开发者

JSF templating beginner's question

I belong to Asp.Net but just starting to lea开发者_JS百科rn 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?


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.


Here is a good tutorial on JSF templating:

JSF 2 Tutorials - Templating

In order to customize what different user roles will see just use rendered attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜