Reputation: 489
I know this question got ask over and over. I did like suggested in all the issues regarding this and I did what BalusC in this question that I put
told me and I haven`t succeeded yet. So the flow of the web app is:
I login, when successful the boolean loggedIn becomes true and the page gets redirected to home.xhtml. (The beans TestBean and EnterView are instantiated and SessionScoped). In this page I got 4 links if the loggedIn boolean is true.
To not use the JSTL c:choose tags (because of the JSTL and JSF "one runs during view build time, the other runs during view render time." - BalusC) I used the rendered attribute.
The list with the links appear but I have to click them twice to do the action it should.
The snippet:
<h:form rendered="#{enterView.userBean.loggedIn}">
<ul id="grileList">
<li><h:commandLink action="#{menuView.showTestsPage(1)}"
value="label1" rendered="#{enterView.userBean.loggedIn}"/></li>
<li><h:commandLink action="#{menuView.showTestsPage(2)}"
value="label2" rendered="#{enterView.userBean.loggedIn}"/></li>
<li><h:commandLink action="#{menuView.showTestsPage(3)}"
value="label3" rendered="#{enterView.userBean.loggedIn}"/></li>
<li><h:commandLink action="#{menView.showTestsPage(4)}"
value="label4" rendered="#{enterView.userBean.loggedIn}"/></li>
</ul>
</h:form>
The h:form it is rendered correctly so it has gone through the view rendered phase, but it doesn't do the actions when I click the links (just when I click them twice) so it is the view build time??? I read about both of them , I thought I understood...
I have put the rendered attribute in the commandLinks to try to render them, but I haven't succeeed.
Upvotes: 2
Views: 4106
Reputation: 1108642
The symptom of "need to click twice in order to invoke action" is recognizable as consequence of JSF spec issue 790 which is fixed in the upcoming JSF 2.2.
To the point, if you have 2 forms and the one updates only a parent component of the other form by ajax, then the other form would lose its JSF view state (the <input type="hidden" name="javax.faces.ViewState">
). Invoking an ajax action in the other form for the first time would not invoke any action, but add the JSF view state back and any subsequent actions will then succeed.
To fix this, you need to explicitly specify the client ID of the other form in the ajax render. E.g.
<f:ajax ... render=":someComponent :otherForm" />
...
<h:someComponent id="someComponent">
<h:form id="otherForm" rendered="#{enterView.userBean.loggedIn}">
...
Upvotes: 3