I have a form with a doAction method all set up and a bind method in the bean yet for some reason the call back handler doesn’t fire.
Code:
doAction method:
@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {
log.debug("doAction()");
final FormMap formMap = new FormMap(request, new String[] { "comment" });
log.debug("-----01-----");
// validate form input
boolean valid = true;
for (String fieldName : formMap.getFieldNames()) {
final FormField field = formMap.getField(fieldName);
log.debug(fieldName + ": " + field.getValue());
if (StringUtils.isEmpty(field.getValue())) {
field.addMessage("Field is required");
valid = false;
}
}
log.debug("" + valid);
log.debug("-----02-----");
// if form is invalid, persist form data and do not continue processing
if (!valid) {
log.debug("Form is not valid.");
FormUtils.persistFormMap(request, response, formMap, null);
return;
}
log.debug("-----03-----");
final HippoDocument beanToLinkTo = request.getRequestContext().getContentBean(HippoDocument.class);
if (beanToLinkTo == null) {
throw new HstComponentException("No document to review");
}
final String name = beanToLinkTo.getName();
final String siteContentBasePath = request.getRequestContext().getSiteContentBasePath();
final String commentPath = "/" + siteContentBasePath + "/messageboard/comments";
final String postPath = "/" + siteContentBasePath + "/messageboard/posts/" + name;
final String commentNameAndID = getID();
log.debug("-----04-----");
WorkflowPersistenceManager wpm = null;
try {
log.debug("-----05-----");
final Session session = request.getRequestContext().getSession();
wpm = getWorkflowPersistenceManager(session);
wpm.setWorkflowCallbackHandler(new BaseWorkflowCallbackHandler<DocumentWorkflow>() {
public void processWorkflow(DocumentWorkflow wf) throws Exception {
log.debug("=======setWorkflowCallbackHandler=======");
wf.publish();
}
});
log.debug("-----06-----");
wpm.refresh();
log.debug("-----07-----");
log.debug(commentPath + "/" + commentNameAndID);
final String reviewDocumentPath = wpm.createAndReturn(commentPath, "myhippoproject:Comment", commentNameAndID, true);
log.debug("-----08-----");
final Comment comment = (Comment) wpm.getObject(reviewDocumentPath);
log.debug("-----09-----");
if (comment == null) {
throw new HstComponentException("Failed to add Review");
}
log.debug("-----10-----");
comment.setId(commentNameAndID);
comment.addHtml(formMap.getField("comment").getValue());
log.debug("-----11-----");
wpm.update(comment);
wpm.save();
log.debug("-----12-----");
/*
log.debug("-----12-----");
Post post = (Post)wpm.getObject(postPath);
List<Comment> postComments = post.getComments();
postComments.add(comment);
wpm.update(post);
log.debug(wpm.getObject(postPath).toString());
wpm.save();
*/
} catch (Exception e) {
log.error("Failed to persist review: {}", e.getMessage(), e);
if (wpm != null) {
try {
wpm.refresh();
} catch (ObjectBeanPersistenceException e1) {
log.warn("Failed to refresh: ", e1);
}
}
}
bind method:
@Override
public boolean bind(Object content, javax.jcr.Node node) throws ContentNodeBindingException {
if (content instanceof Post) {
try {
log.debug("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
Comment comment = (Comment)node;
this.getNode().getNode(HTML_NODEPATH).remove();
log.debug("============"+comment.getId() + "============");
node.setProperty("myhippoproject:id", comment.getId());
if(this.html != null) {
if(node.hasNode(HTML_NODEPATH)) {
javax.jcr.Node html = node.addNode(HTML_NODEPATH, "hippostd:html");
html.setProperty("hippostd:content", html);
}
}
} catch (Exception e) {
log.error("Unable to bind the content to the JCR Node" + e.getMessage(), e);
throw new ContentNodeBindingException(e);
}
return true;
}
return false;
}
Console output:
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:53] doAction()
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:56] -----01-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:61] comment:
[INFO] [talledLocalContainer] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien risus, tincidunt vitae ornare vehicula, efficitur quis risus. Maecenas nec vulputate justo, imperdiet pulvinar est. Fusce tempus maximus ipsum, tempor interdum mi luctus faucibus. In vehicula, diam et finibus volutpat, ipsum urna tempor enim, vel suscipit eros nunc eget justo. Donec vehicula finibus nibh ac efficitur. Donec eu orci vehicula, cursus urna non, porta nisi. Vivamus varius nunc eu dignissim tempus. Quisque interdum auctor mauris, ut egestas metus placerat nec. Aenean in sem vitae magna imperdiet pharetra aliquet id sem. Suspendisse interdum nisi in cursus fermentum. Curabitur mattis, magna ac hendrerit dictum, ipsum sem facilisis nisl, a interdum turpis libero eget ex. Nam in nisi tempor ante lobortis maximus id blandit felis. Pellentesque tempus turpis sit amet pharetra mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:68] true
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:69] -----02-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:77] -----03-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:89] -----04-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:92] -----05-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:102] -----06-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:106] -----07-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:107] /content/documents/myhippoproject/messageboard/comments/WevtkU3l
[INFO] [talledLocalContainer] 09:19:01 INFO autoexport is processing changes...
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:110] -----08-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:113] -----09-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:118] -----10-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:01 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:123] -----11-----
[INFO] [talledLocalContainer] 09:19:02 INFO autoexporting source: myhippoproject/myhippoproject/myhippoproject-repository-data-application [content: content/documents/myhippoproject/messageboard.yaml]
[INFO] [talledLocalContainer] 09:19:03 INFO autoexport update complete
[INFO] [talledLocalContainer] 09:19:05 INFO autoexport is processing changes...
[INFO] [talledLocalContainer] 01.08.2018 09:19:05 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:129] -----12-----
[INFO] [talledLocalContainer] 01.08.2018 09:19:05 DEBUG http-nio-8080-exec-3 [PostComponent.doAction:154] -----13-----
[INFO] [talledLocalContainer] 09:19:05 INFO autoexporting source: myhippoproject/myhippoproject/myhippoproject-repository-data-application [content: content/documents/myhippoproject/messageboard.yaml]
[INFO] [talledLocalContainer] 09:19:05 INFO autoexport update complete