tags:

views:

153

answers:

1

I am using facelets. 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?

+3  A: 

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.

BalusC
Hi BalusC, i did exactly what it said on the link you pointed, But it's not working. I get tag not found error. What should i do? Here is my taglib.xml<?xml version="1.0" encoding="UTF-8"?><facelet-taglib> <namespace>http://laala.com/el/AppDeployment</namespace> <function> <function-name>getCommonImagePath</function-name> <function-class>Common.AppDeployment</function-class> <funciton-signature>String getCommonImagePath(java.lang.String)</funciton-signature> </function></facelet-taglib>
Ankit Rathod
In my web.xml i added :- <context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/META-INF/AppDeployment.taglib.xml</param-value> </context-param>I keep getting configuration null error and tag not found in glassfish admin console. Please help me.
Ankit Rathod
I get this error to be spccific :SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
Ankit Rathod
Hi balusC, i figured it out on my own. It was my silly mistake. Thanks again
Ankit Rathod
OK, you're welcome.
BalusC