Question

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.

Était-ce utile?

La solution

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.

Autres conseils

  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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top