How do I access a non-managed-bean class in JSF page?
I am using facelets开发者_StackOverflow社区. I have one class:
public class foo{
public static String foofookoo() {
return "tookoofoopoo";
}
}
How do I access this on my JSF page because this is a simple POJO not a managed bean?
Assuming that it is really a POJO and that your code example is simply bad; the only way to access it nicely is to make it a property of an existing managed bean:
@ManagedBean
public class Bean {
private Pojo pojo;
public Bean() {
pojo = new Pojo(); // Create/load it somehow.
}
public Pojo getPojo() {
return pojo;
}
}
Then in the JSF page associated with the managed bean just do:
<h:outputText value="#{bean.pojo.property}" />
which roughly translates to pageContext.findAttribute("bean").getPojo().getProperty()
.
But, if it is on the other hand actually an utility class with static non-getter methods, then your best bet is to wrap it in an EL function. You can find a Facelets-targeted example in this answer.
精彩评论