background image

The NavigationEnumBean Class

<< Request Processing | Protecting the Web Client >>
<< Request Processing | Protecting the Web Client >>

The NavigationEnumBean Class

public Object action() {
return this;
}
}
If you are not familiar with enums, see
http://java.sun.com/javase/6/docs/technotes/guides/language/enums.html
.
A managed bean is needed to expose the enum to the expression language so that a page can
access its logical outcomes. In this case, the Navigation enum class is accessed through the
NavigationEnumBean
:
public class NavigationEnumBean extends EnumManagedBean {
public NavigationEnumBean() {
super(Util.Navigation.class);
}
}
NavigationEnumBean
extends a special bean class that includes a method to return an enum
constant, which represents a logical outcome:
public Enum getEnum(String enumName) {
return Enum.valueOf(e, enumName);
}
The application also includes a custom EL resolver, EnumResolver, which resolves expressions
that reference an instance of this bean class. You create a resolver if you want expressions to
particular kinds of objects resolved in a special way that is not already supported by the EL
mechanism. See
"Resolving Expressions" on page 160
for more information on EL resolvers.
The resolver calls the bean's getEnum method from its getValue method to return the enum
constant:
public Object getValue(ELContext elContext, Object base, Object property) {
if ((base != null && property != null)
&& base instanceof EnumManagedBean) {
elContext.setPropertyResolved(true);
return
((EnumManagedBean)base)
.getEnum(property.toString());
}
return null;
}
A tag's action attribute references a particular constant of the enum to specify a logical
outcome. The following commandLink tag appears on the links.jsp page:
<h:commandLink value=
"#{bundle.Logoff}"
action=
"#{navigation.logout.action}"/>
Web Client
The Java EE 5 Tutorial · September 2007
1072