tags:

views:

25

answers:

1

Hello, I belong to Asp.Net but just starting to learn JSF. I wanted to know whether all features of MasterPage are available in JSF templating? I mean say suppose i have a menu in template, and based on roles menu changes. If the Admin logs in, he will get to show more options and if general user logs in he will get to see less options. Now i have a managed bean for my "real" page(not template). How do i use this managed bean to toggle my control in template on and Off?

+1  A: 

You can do pretty much all in JSF/Facelets as you could do in ASP MasterPages. You can use the rendered attribute of any JSF component to toggle whether the component needs to be rendered in the view. It accepts a boolean expression which will cause the component (and all its children) to be shown when true, otherwise completely hidden when false. Here are several examples:

<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue > 10}" />
<h:someComponent rendered="#{bean.objectValue == null}" />
<h:someComponent rendered="#{bean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty bean.collectionValue}" />
<h:someComponent rendered="#{!bean.booleanValue && bean.intValue != 0}" />
<h:someComponent rendered="#{bean.stringValue == 'oneValue' || bean.stringValue == 'anotherValue'}" />

To learn more about JSF/Facelets, I recommend to go through Sun's own JSF tutorial in the Java EE 6 tutorial part II chapters 4-9 and Marty Hall's Coreservlets.com tutorials.

BalusC
Great!! thanks BalusC
Ankit Rathod