cant post message vith zero length

Change-Id: Ia92804670207972dd5ea5ac5f0b14fae01547cb0
This commit is contained in:
joha-asc 2011-07-22 16:06:37 +02:00
parent 0b7e46434d
commit a380c0f1cd
2 changed files with 33 additions and 46 deletions
src/main/java/se/su/dsv/scipro/commentthread/panels

@ -33,6 +33,7 @@
<div wicket:id="navigator" class="comment-pager last"></div> <div wicket:id="navigator" class="comment-pager last"></div>
</div> </div>
<div class="last comment-form"> <div class="last comment-form">
<div wicket:id="feedbackPanel"></div>
<form wicket:id="commentForm"> <form wicket:id="commentForm">
<div class="last"> <div class="last">
<strong>Comment:</strong> <strong>Comment:</strong>

@ -19,6 +19,7 @@ import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView; import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel; import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model; import org.apache.wicket.model.Model;
@ -70,6 +71,7 @@ public class CommentThreadPanel extends Panel {
private final Set<SubscriberModel> subscriberModels; private final Set<SubscriberModel> subscriberModels;
private final String title; private final String title;
private final Long classId; private final Long classId;
private final FeedbackPanel feedbackPanel;
public CommentThreadPanel(final String id, final Commentable keyObject, public CommentThreadPanel(final String id, final Commentable keyObject,
final int numberOfComments, final Set<SubscriberModel> subscriberModels, final int numberOfComments, final Set<SubscriberModel> subscriberModels,
@ -111,6 +113,10 @@ public class CommentThreadPanel extends Panel {
dialog.setWidth(470); dialog.setWidth(470);
dialog.add(dialogContainer); dialog.add(dialogContainer);
add(dialog); add(dialog);
feedbackPanel = new FeedbackPanel("feedbackPanel");
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
dialogContainer.setOutputMarkupId(true); dialogContainer.setOutputMarkupId(true);
editCommentForm = new EditCommentForm("editCommentForm", editCommentForm = new EditCommentForm("editCommentForm",
@ -176,30 +182,35 @@ public class CommentThreadPanel extends Panel {
@Override @Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) { protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Comment comment = (Comment) form.getDefaultModelObject(); Comment comment = (Comment) form.getDefaultModelObject();
comment = commentDao.save(comment); if (comment.getComment() == null || comment.getComment().length() < 1) {
System.out.println(subscriberModels); error("Comment can't be empty");
if (subscriberModels != null) {
for (SubscriberModel sm : subscriberModels) { } else {
createNotification(sm.getUser(), comment.getComment(), comment = commentDao.save(comment);
sm.getNotificationPriority(), sm.getAbsolutePath()); if (subscriberModels != null) {
for (SubscriberModel sm : subscriberModels) {
notificationController.createNotificationForComment(sm.getUser(), comment.getComment(),
sm.getNotificationPriority(), title, classId.toString(), sm.getAbsolutePath());
}
} }
} /*
/* * Do not, on purpose set the forms defaultModelObject
* Do not, on purpose set the forms defaultModelObject to * to the now persisted object, we leave the original
* the now persisted object, we leave the original object so * object so it can be re reused for any number of
* it can be re reused for any number of submits * * submits *
*/ */
webMarkupContainer.remove(commentListView); webMarkupContainer.remove(commentListView);
webMarkupContainer.remove(customPagingNavigator); webMarkupContainer.remove(customPagingNavigator);
textArea.setDefaultModelObject(""); textArea.setDefaultModelObject("");
generateCommentListView(); generateCommentListView();
webMarkupContainer.add(commentListView); webMarkupContainer.add(commentListView);
webMarkupContainer.add(customPagingNavigator); webMarkupContainer.add(customPagingNavigator);
target.addComponent(textArea); target.addComponent(textArea);
target.addComponent(webMarkupContainer); target.addComponent(webMarkupContainer);
}
target.addComponent(feedbackPanel);
} }
}; };
@ -338,29 +349,4 @@ public class CommentThreadPanel extends Panel {
} }
} }
private void createNotification(final User user, final String message,
final NotificationPriority notificationPriority, final String absolutePath) {
Properties props = null;
try {
props = PropsUtils.load("notification.properties");
} catch (Exception e) {
e.printStackTrace();
}
String mailSubject = props.getProperty("mailSubject");
String conferenceNotification = props.getProperty("conferenceNotificationComment");
String twoNewLines = props.getProperty("twoNewLines");
String webNotificationMessage = SciProSession.get().getUser() + conferenceNotification
+ title;
String mailMessage = webNotificationMessage + twoNewLines + message;
NotificationMessage notificationMessage = new NotificationMessage(webNotificationMessage,
mailSubject, mailMessage);
notificationController.processNotification(user, notificationMessage, absolutePath+"&"+classId
,
notificationPriority);
}
} }