0

I'm trying to create a comment page with a variable set of comments (layed out via o:tree, thanks BalusC) that anyone can reply to. I'm displaying the h:inputTextArea via p:inplace, so there are multiple textinputareas per page with multiple commandbutton replies. I'm trying to map the command button to a single back-end variable from a specific textinputarea so that every textinputarea isn't processed each time the command button is pressed.

Edit: Code example

<o:tree value="#{xPost.post.comments.treeModel}" var="comment" varNode="node">

    <o:treeNode>
        <o:treeNodeItem>
            <p:panel>
                <h:outputText value="#{comment.commentText}" />
                <p:inplace label="Reply">
                    <br/>
                    <p:editor value="#{post.newComment}" />
                    <p:commandButton action="#{post.saveComment('#{comment.ID'})}" value="Comment" ajax="false" />
                </p:inplace>
                <o:treeInsertChildren />
            </p:panel>
        </o:treeNodeItem>
    </o:treeNode>
</o:tree>

To add to this, I'm using hibernate validation, which to my knowledge can only validate via annotations:

@NotBlank(message="Please enter a comment.") @Length(min=1, max=10000, message="A comment must be between 1 and 10,000 characters.") @SafeHtml(message="Invalid Rich Text.") private String newComment = "";

So from the code above, when I have 2+ p:editor, each editor is being processed and populating the same back-bean variable. How do I force a commentButton to only validate a specific inputBox/p:editor and set the backing-bean variable.

Thank you for your help.

David D
  • 83
  • 1
  • 1
  • 5

2 Answers2

1

Just give each editor its own form. In other words, move the <h:form> from outside the <o:tree> to inside the <o:treeNodeItem>. This will ultimately render multiple forms with each its own editor and button.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I just found the primefaces has a component called [Fragment](http://www.primefaces.org/showcase/ui/fragment.jsf) that will do essentially what I was looking for, but your solution works without the component. – David D Nov 05 '13 at 00:24
0
  1. You need to provide your source details for people to give you more help
  2. In your case, I'm guessing the following should do the trick:

    <ui:repeat var="comment" ...> // or equivalent like o:tree
      <h:inputText value="#{comment.message} .../>
      <h:commandButton actionListener="#{bean.updateMessage}">
        <f:setPropertyActionListener from="#{comment}" to="#{bean.commentBeingProcessed}"/>
        <!-- Or alternatively, you can set the comment object on to the command button
             and receive it on the server side as event.getComponent().getAttribute("comment")
          <f:attribute name="comment" value="#{comment}"/>
        -->
      </h:commandButton>
    </ui:repeat>
    

Hope that helps.

Harsha R
  • 707
  • 6
  • 12
  • Thank you for your answer, but I don't think I properly explained the problem. I have edited my post to better reflect my question. – David D Oct 26 '13 at 16:33