3

I am creating a JSF application with primefaces. Basically I have this view. There is a tab view which for each tab contains a command button and a accordion panel (another kind of tab view). The tabs of the accordion panel among other elements, contain each one command button. My problem is that the first command button (under 1 level of tabs) calls correctly the action method when it is clicked, while the second button (under 2 level of tabs) does not. I should say that both the tabView and accordionPanel are working correctly, since they are displaying the information they should display.

I am posting a simplified version of my view so that you can see what is happening.

<h:form>
<p:tabView id="unitTabs"  orientation="left" dynamic="true" cache="false" var="unit" value="#{unitController.getUnitsOfLoggedInUser(loginController.checkedUser)}">
    <p:tab id="unitTab" title="#{unit.unitName}">

    <p:commandButton value="Add Lecture" action="#{unitController.setTemporary(unit)}" onclick="createLectureDialog.show()">

    <p:accordionPanel id="lectureTabs" value ="#{lectureController.getLecturesForUnit(unit)}" var="lecture" dynamic="true" cache="false">

         <p:tab title="#{lecture.lectureName}">
              <p:commandButton value="Add Criterion" action ="#{lectureController.setTemporary(lecture)}" onclick="createCriterionDialog.show()" >
         </p:tab>
     </p:accordionPanel>
     </p:tab>
</p:tabView>
</h:form>

What am i doing wrong? Thanks

Dani
  • 3,744
  • 4
  • 27
  • 35
interboy
  • 856
  • 1
  • 11
  • 25
  • Please check points 3 and 4 of http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Jun 20 '12 at 18:46
  • @BalusC I get this message whenever a page is rendered. I have been having it from the beginning but it was not creating problems `The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within` – interboy Jun 20 '12 at 19:04
  • This particular issue is specific to older Mojarra versions (before 2.0.5 or something IIRC), upgrading should fix it. But this is indeed likely not the cause of your problem as you already have a form. In other words, you don't see any validation errors as mentioned in point 3? Also not ones which are not been displayed and thus logged to server log as "unhandled messages"? – BalusC Jun 20 '12 at 19:11
  • @BalusC No, I checked and there is nothing like this. Can you tell me if there is any way to do what I am doing in the action attribute in the onclick attribute, therefore through JavaScript? Thanks – interboy Jun 20 '12 at 19:31
  • I tried this `onclick="#{lectureController.setTemporary(lecture)}; createCriterionDialog.show()` and the method is not being called when the button is clicked, but when the tab that the button belongs is activated. However, it is not a problem for me, although I am not understanding why.. Anyways thanks for your help @BalusC – interboy Jun 20 '12 at 20:15
  • That confirms point 4 being the cause of the problem. – BalusC Jun 20 '12 at 20:22
  • Your "workaround" will however fail if there are more tabs in the accordionpanel. It'll always end up being the last `lecture` value. – BalusC Jun 20 '12 at 20:34
  • Actually I can add as many tabs as I want, but it is working perfectly. It evaluates the bean attribute when the any tab is pressed, but considering that the button pressed will be for that tab, the value is the same. @BalusC – interboy Jun 20 '12 at 21:07

1 Answers1

5

This construct requires that the EL expression in the value attribute of the <p:tabView> and <p:accordionPanel> returns exactly the same value during processing the form submit as it was during the initial display.

If the bean is request scoped and/or the value depends behind the scenes on a request based parameter or variable and it thus returns a different value on every request, then it will fail because JSF cannot locate the button which was been invoked. To fix it, the bean needs to be placed in the view scope and the getter method should not contain any business logic, or any request based parameters or variables should be retained in the subsequent requests.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555