added component specific feedback panels for subject and message body fields. also added default radio choice value to avoid null pointers
This commit is contained in:
parent
9cd2fdc9dd
commit
3e979cf478
src/main/java/se/su/dsv/scipro/admin/panels
@ -9,13 +9,18 @@
|
||||
<input type="radio"/>
|
||||
</div>
|
||||
<form wicket:id="mailForm">
|
||||
<div class="span-10">
|
||||
Subject:<br />
|
||||
<input type="text" wicket:id="mailSubject"><br />
|
||||
<div wicket:id="subjectErrors"></div>
|
||||
<input type="text" wicket:id="mailSubjectField"><br />
|
||||
Message:<br />
|
||||
<textarea wicket:id="mailBody"></textarea><br />
|
||||
<div wicket:id="messageErrors"></div>
|
||||
<textarea wicket:id="mailBodyField"></textarea><br />
|
||||
<div>
|
||||
<input type="submit" value="Send e-mail" wicket:id="submitButton" />
|
||||
</div>
|
||||
<input type="submit" value="Send e-mail" wicket:id="submitButton" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
|
@ -9,15 +9,18 @@ import org.apache.log4j.Logger;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
|
||||
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
||||
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
|
||||
import org.apache.wicket.markup.html.form.Button;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.RadioChoice;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.apache.wicket.validation.validator.StringValidator;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
|
||||
@ -53,7 +56,6 @@ public class AdminMailPanel extends Panel {
|
||||
|
||||
public AdminMailPanel(String id) {
|
||||
super(id);
|
||||
add(new FeedbackPanel("feedbackPanel"));
|
||||
setUpRadioButtons();
|
||||
setUpMailForm();
|
||||
}
|
||||
@ -63,11 +65,13 @@ public class AdminMailPanel extends Panel {
|
||||
private void setUpMailForm() {
|
||||
MailForm mailForm = new MailForm("mailForm");
|
||||
add(mailForm);
|
||||
add(new FeedbackPanel("feedbackPanel", new ComponentFeedbackMessageFilter(mailForm)));
|
||||
|
||||
}
|
||||
|
||||
public class MailForm extends Form<Void> {
|
||||
private TextField<String> mailSubject;
|
||||
private TextArea<String> mailBody;
|
||||
private TextField<String> mailSubjectField;
|
||||
private TextArea<String> mailBodyField;
|
||||
private String fromName;
|
||||
private String fromEmail;
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -84,35 +88,40 @@ public class AdminMailPanel extends Panel {
|
||||
"onclick",
|
||||
"if (!confirm('Are you sure you want to send this e-mail to the selected recipients?')){ return false; }"));
|
||||
add(submitButton);
|
||||
mailSubject = new TextField<String>("mailSubject", new Model<String>());
|
||||
mailBody = new TextArea<String>("mailBody", new Model<String>());
|
||||
mailSubjectField = new TextField<String>("mailSubjectField", new Model<String>());
|
||||
mailSubjectField.setRequired(true);
|
||||
mailBodyField = new TextArea<String>("mailBodyField", new Model<String>());
|
||||
mailBodyField.setRequired(true);
|
||||
mailBodyField.add(StringValidator.minimumLength(5));
|
||||
|
||||
add(mailSubject);
|
||||
add(mailBody);
|
||||
add(new ComponentFeedbackPanel("subjectErrors", mailSubjectField));
|
||||
add(new ComponentFeedbackPanel("messageErrors", mailBodyField));
|
||||
add(mailSubjectField);
|
||||
add(mailBodyField);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSubmit() {
|
||||
|
||||
try {
|
||||
MailEvent me = new MailEvent(mailSubject.getInput(), mailBody.getInput(), userSet, fromName, fromEmail);
|
||||
MailEvent me = new MailEvent(mailSubjectField.getInput(), mailBodyField.getInput(), userSet, fromName, fromEmail);
|
||||
me = mailEventDao.save(me);
|
||||
System.out.println("Mail to: " + me.getRecipients() );
|
||||
System.out.println("Mail subject: " + me.getSubject());
|
||||
System.out.println("Mail body: " + me.getMessageBody());
|
||||
info("E-mail sent successfully to the following users: " + me.getRecipients());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to send e-mail");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setUpRadioButtons() {
|
||||
List<String> myChoices = Arrays.asList(new String[]{AUTHORS_ALL,AUTHORS_REFUSED,THESISSUPPORT,SUPERVISOR_ALL, SUPERVISOR_UNCONFIRMED});
|
||||
final RadioChoice<String> rc = new RadioChoice<String>("radioChoices",new Model<String>(), myChoices);
|
||||
List<String> options = Arrays.asList(new String[]{AUTHORS_ALL,AUTHORS_REFUSED,THESISSUPPORT,SUPERVISOR_ALL, SUPERVISOR_UNCONFIRMED});
|
||||
final RadioChoice<String> rc = new RadioChoice<String>("radioChoices",Model.of(AUTHORS_ALL), options);
|
||||
|
||||
//Default values, taken from RadioChoice constructor above (Model.of(your choice)).
|
||||
userSet = new HashSet<User>();
|
||||
userSet = getRecipients(rc.getModelObject());
|
||||
|
||||
AjaxFormChoiceComponentUpdatingBehavior behavior = new AjaxFormChoiceComponentUpdatingBehavior() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
Required=Field '${label}' is required
|
||||
|
||||
mailSubjectField.Required=You need a subject for your e-mail
|
||||
mailBodyField.Required=You can't send an empty message
|
||||
mailForm.mailBodyField.StringValidator.minimum=You need to write a minimum of 5 characters
|
Loading…
x
Reference in New Issue
Block a user