2

Inside a p:dataScroller I got a form with an inputTextarea and a commandButton:

<h:form>
    <p:inputTextarea rows="4" cols="15" autoResize="false" value="#{feedBean.comment}" />
    <br />
    <p:commandButton value="Kommentar posten" action="#{feedBean.commentStatus(entry.id)}" />                                               
</h:form>

When I click the first button everything works fine. When I try to click the second or the third button the method is not called. I also tried to use f:param but it doesn't work too.

This is the method commentStatus:

public String commentStatus(String id) {
    /* Irrelevant code */

    System.out.println("###entryId: "+id);

    /* Irrelevant code */

    return NavigationBean.securedFeedLink;
}

EDIT: Just found the solution by myself. I had to add process="@form" to my button. Now it works fine!

EDIT 2: My form was nested into another form that's why I needed process="@form" I updated my code and removed the other form. Now it works without adding process="@form"!

acidowl
  • 103
  • 1
  • 10
  • have you tried `actionListener` instead of `action` on the commandButton ? – Jorge Campos Aug 11 '15 at 12:03
  • Problem suggests bean is not view scoped and/or JSF view state got lost. Can you verify and confirm both? – BalusC Aug 11 '15 at 12:03
  • @JorgeCampos: Huh? Food for read: http://stackoverflow.com/q/3909267 Or, if you actually never used JSF, but just tried to repost the first Google result in a comment in all fairness, please don't do that, it only pollutes the Internet with misinformation. – BalusC Aug 11 '15 at 12:04
  • What if the first click is on the second button? Does that one work then and after that clicking on button 1 fails? Or in other words, is it related to the number of buttons or the number of clicks on the **same** button? – Kukeltje Aug 11 '15 at 12:07
  • @BalusC: Yes it's not viewscoped, it's sessionscoped. – acidowl Aug 11 '15 at 12:08
  • @Kukeltje: First click on the second button doesn't work either. Only the first button works. – acidowl Aug 11 '15 at 12:09
  • @BalusC Thanks for the reading (great by the way, as always). I'm use to use JSF with spring and a custom view scoped anotation and have faced such problems as the OP mentioned and just changing the action by actionListener worked for me. But you are totally right. Probably my case was entirelly different. – Jorge Campos Aug 11 '15 at 12:14

1 Answers1

0

Just found the solution by myself. I had to add process="@form" to my button. Now it works fine!

acidowl
  • 103
  • 1
  • 10
  • This is strange as that's the default value already. Or did you actually had a different one and omitted it from the question for brevity without actually testing the resulting code? – BalusC Aug 11 '15 at 12:44
  • @BalusC: Didn't omit it. Never had it in my code. Just read something on the internet and added it to my button. I know it's the default value that's why I'm wondering why it works. – acidowl Aug 11 '15 at 12:53
  • Okay. And if you remove it, does it fail again? Just to exclude a dirty build from being the cause. – BalusC Aug 11 '15 at 12:54
  • If I remove it, it fails again. Just tried it without and with again. – acidowl Aug 11 '15 at 12:58
  • Are you nesting forms? – BalusC Aug 11 '15 at 12:59
  • @BalusC: Just checked it and indeed there was another form around it that I didn't saw because there was so much other code around it. I updated my code and now it works without `process="@form"` – acidowl Aug 11 '15 at 13:05
  • Technically, this is dupe of http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked :) – BalusC Aug 11 '15 at 13:06
  • @BalusC: Thanks for your help! – acidowl Aug 11 '15 at 13:08