| Author |
HOW: 'if'-like JSF conditions?
|
J. Begham
Greenhorn
Joined: Jun 04, 2007
Posts: 3
|
|
Hi group, I'd like to show / hide some parts / sections of my JSF page depending on whether the user is logged in or the user has propper rights. E.g. if a user is already logged in, the login section should no longer be shown. in a normal JSP page, I would do this by something like but I have absolutly no idea how to do this in a JSF way. I know that most of the jsf-tags have an render-attribute, but in my opinion it is not the right approach, as you would have to set it for each element which should be shown/ should be hidden. So what I am looking for is something what gives me the possibility to just hide/show everything between one tag like the if-brackets in the "old" way. How can it be done in JSF? Thanks in advance John
|
 |
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
As of JSF 1.2 and Servlets 2.5, JSTL 1.2 is supposed to work well with JSF. So give a try to <c:if> and <c:choose> tags and let us know about the results. Example : <c:if test="${empty param.userName}"> do things here ... </c:if> <c:if test="${initParam.showAdvice == 'yes'}"> do things here ... </c:if> <c:choose> <c:when test="${sessionScope.shoppingCart.itemsCount > 0}"> do things here ... </c:when> <c:when test="${applicationScope.databaseName == 'MySQL'}"> do things here ... </c:when> <c therwise> do other things here ... </c therwise> </c:choose> and so on .... [ June 04, 2007: Message edited by: Edisandro Bessa ]
|
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
|
 |
J. Begham
Greenhorn
Joined: Jun 04, 2007
Posts: 3
|
|
Hi, thanks for the help. I think the JSF 1.2 Servlet 2.5 JSTL 1.2 solution is what I am looking for. Unfortunatly the environment basis isn't ready yet for this state-of-the art technology, so it will take some time to get the "good solution" running. I have found a "workaround" solution with using a myFaces Tomahawk Div extension which I can use as a surrounding element which can hold the rendered-Attribute. e.g. In the example above the enclosed content won't be rendered. Greets John
|
 |
Majid Al-Fifi
Ranch Hand
Joined: Aug 22, 2006
Posts: 45
|
|
rendered attribute with something like PanelGrid will do the job. You don't need to set "rendered" for every other element. only the element you wanna control its hide/show behaviour. I don't understand why you see it will complicate your design. I don't think you need JSF1.2 or Tomahawk to acheive your goal. Just group the things you wanna hide/show under one element maybe PanelGrid. regards, Majid
|
SCJP1.4, SCWCD1.4
|
 |
J. Begham
Greenhorn
Joined: Jun 04, 2007
Posts: 3
|
|
Hi Majid, you are right. PanelGroup would do the job as well. I didn't thought of this element. Greets John [ June 04, 2007: Message edited by: J. Begham ]
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14456
|
|
|
The JSF tags aren't intended to be a programming language. The idea is that all logic "should" be in the backing beans or services referenced by the backing beans, unlike JSTL or Struts. For conditional display of elements, the rendered= attribute works well. That puts the logic in the backing bean, but ensures that propertis of the backing bean will be displayed - or not - in an appropriate manned.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Emilio Lb
Greenhorn
Joined: Aug 05, 2010
Posts: 2
|
|
You can use html:panelGroup tag to conditionally output an html block
|
 |
 |
|
|
subject: HOW: 'if'-like JSF conditions?
|
|
|