3

I am looking for how to enable and disable the icefaces components based on the user login ? For example:

if login as admin i need to enable the come more components and login as user, disable some components as well as add some other components in one page ? How to do this function in jsf/icefaces ?

These two enable and disable in one page .

I appericate your suggestions.

rose
  • 31
  • 1
  • 1
  • 2

2 Answers2

12

Use the rendered attribute. It accepts a boolean expression. Add a method to the User entity like isAdmin() or getRole() and let the rendered attribute intercept on that.

<h:someComponent rendered="#{user.admin}">
    Will be displayed when user.isAdmin() returns true.
</h:someComponent>
<h:someComponent rendered="#{user.role != 'ADMIN'}">
    Will be displayed when user.getRole() (String or enum) does not equal ADMIN.
</h:someComponent>

For the case you're interested, here are some more examples how you could use boolean expressions in EL.

JSP-compatible syntax:

<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.enumValue == 'ONE' || bean.enumValue == 'TWO'}" />

Facelets-compatible syntax with some XML-sensitive EL operators like > and & changed:

<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue gt 10}" />
<h:someComponent rendered="#{bean.objectValue eq null}" />
<h:someComponent rendered="#{bean.stringValue ne 'someValue'}" />
<h:someComponent rendered="#{not empty bean.collectionValue}" />
<h:someComponent rendered="#{not bean.booleanValue and bean.intValue ne 0}" />
<h:someComponent rendered="#{bean.enumValue eq 'ONE' or bean.enumValue eq 'TWO'}" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    did JSF2 no longer allow the use of `&&`, because it give me this `The entity name must immediately follow the '&' in the entity reference`. However, if I use the keyword `and`, then it works – Thang Pham Aug 18 '10 at 14:01
  • 1
    @Harry: Oh sorry, that was the JSP style. In XML (XHTML, Facelets) you need to escape XML entities. The `&` is one of them. Yes, `and` is the right keyword. For the remnant, [here's an overview](http://download.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaik). – BalusC Aug 18 '10 at 14:55
  • @ThankPharm Sorry, what do you mean by your first comment? Is using && not allowed? – Koray Tugay May 16 '13 at 19:34
1

In ICEfaces for controls that has disabled property use:

<ice:inputText disabled="[true/false]"/>

Example

I used this in my code:

<ice:inputText disabled="#{ABMUsuario.accion!='3'}"/>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
demian
  • 632
  • 7
  • 14