0

I have a couple of panel groups, one with "register" and "log in" links, and the other with "log out". When I log in only the "log in" link disappears, the "register" stays rendered, and the "log out" never gets rendered. The #{user.loggedIn}" returns true when the user is logged in. And when refreshing the screen in debug mode I can see that method is being run. Any suggestions for how to get this to work correctly. The code should be explanatory, please let me know if it isn't.

<h:panelGroup rendered="#{!user.loggedIn}">
  <li>
    <h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login" styleClass="loginpanelclass">Log In</h:outputLink>
  </li>
  <li>
    <h:link value="Register" outcome="/registration/register.xhtml" />
  </li>
</h:panelGroup>

<h:panelGroup rendered="#{user.loggedIn}">
  <li>
    <h:commandLink action="#{user.logout()}">Logout</h:commandLink>
  </li>
</h:panelGroup>
Bill Rosmus
  • 2,941
  • 7
  • 40
  • 61
  • In general in order to update an element which is not being rendered you must update its wrapper that is always rendered , this might help you a bit http://stackoverflow.com/a/10370268/617373 – Daniel Jul 09 '12 at 06:28
  • I was thinking this might be the issue. I'll study the solution in the link and see what I can do. Also, the panel groups are not in a form, is that an issue? – Bill Rosmus Jul 09 '12 at 12:39
  • @Daniel just curious, since this isn't in a form, do I include the ajax tag inside the panel group or outside... or where? Or does it have to be in a form? – Bill Rosmus Jul 09 '12 at 13:05
  • the ajax should be wrapped by element that can fire some events like `commandButton/commnadLink/inputText/and many more (menus/checkboxes etc...)` and that component must be wrapped by h:form , while the `render="someId anotherID..."` can point to elements that resides outside the form too (in that case a ":" prefix should be used before the id `render=":someIdOutSideTheForm anotherIDInsideTheForm..."`) – Daniel Jul 10 '12 at 06:15
  • It seems that the element being referenced must be in a namingcontainer. Form is a naming container, subview is, datatable, repeat... maybe more. I suppose you can create your own by by implementing the interface. I put mine in a form, since I ended up putting in a couple of command links, like to log out. I'll put a brief note about naming containers on this page as an answer and then mark you answer on the other page up by one. – Bill Rosmus Jul 11 '12 at 16:28

1 Answers1

0

The elements you want to reference have to be in a naming container if they are not in the same naming container you are referencing them from. For me I launch a login dialog using primefaces when the first link in my question is clicked. Inside the dialog is a form. When that form completes it tells the panels in my question above to render or not by using the p:dialog update attribute. I had to put the panels in my question inside a naming container and then was able to successfully reference them using the ':' notation through the hierarchy.

If anyone is having trouble look for articles on component hierarchies and naming containers in JSF. With the hints given by Daniel in his comments above and the stuff I found looking at hierarchies and naming containers I figured this one out good enough for now. Still a few uncertainties but my code does what I want it to do for now. :) I'm marking the answer Daniel gave in his linked question up by one.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Bill Rosmus
  • 2,941
  • 7
  • 40
  • 61