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>
<div class="last comment-form">
<div wicket:id="feedbackPanel"></div>
<form wicket:id="commentForm">
<div class="last">
<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.list.ListItem;
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.model.IModel;
import org.apache.wicket.model.Model;
@ -70,6 +71,7 @@ public class CommentThreadPanel extends Panel {
private final Set<SubscriberModel> subscriberModels;
private final String title;
private final Long classId;
private final FeedbackPanel feedbackPanel;
public CommentThreadPanel(final String id, final Commentable keyObject,
final int numberOfComments, final Set<SubscriberModel> subscriberModels,
@ -111,6 +113,10 @@ public class CommentThreadPanel extends Panel {
dialog.setWidth(470);
dialog.add(dialogContainer);
add(dialog);
feedbackPanel = new FeedbackPanel("feedbackPanel");
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
dialogContainer.setOutputMarkupId(true);
editCommentForm = new EditCommentForm("editCommentForm",
@ -176,30 +182,35 @@ public class CommentThreadPanel extends Panel {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Comment comment = (Comment) form.getDefaultModelObject();
comment = commentDao.save(comment);
System.out.println(subscriberModels);
if (subscriberModels != null) {
for (SubscriberModel sm : subscriberModels) {
createNotification(sm.getUser(), comment.getComment(),
sm.getNotificationPriority(), sm.getAbsolutePath());
if (comment.getComment() == null || comment.getComment().length() < 1) {
error("Comment can't be empty");
} else {
comment = commentDao.save(comment);
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 to
* the now persisted object, we leave the original object so
* it can be re reused for any number of submits *
*/
/*
* Do not, on purpose set the forms defaultModelObject
* to the now persisted object, we leave the original
* object so it can be re reused for any number of
* submits *
*/
webMarkupContainer.remove(commentListView);
webMarkupContainer.remove(customPagingNavigator);
textArea.setDefaultModelObject("");
generateCommentListView();
webMarkupContainer.add(commentListView);
webMarkupContainer.add(customPagingNavigator);
target.addComponent(textArea);
target.addComponent(webMarkupContainer);
webMarkupContainer.remove(commentListView);
webMarkupContainer.remove(customPagingNavigator);
textArea.setDefaultModelObject("");
generateCommentListView();
webMarkupContainer.add(commentListView);
webMarkupContainer.add(customPagingNavigator);
target.addComponent(textArea);
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);
}
}