开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜