2

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
TCM
  • 16,780
  • 43
  • 156
  • 254
  • That's not a POJO. It's normally a *pure* Javabean with only public non-static getters/setters/c'tors. Aren't you talking about an utility class with only static methods (functions)? – BalusC Mar 30 '10 at 17:07
  • Hi BalusC, Why is it not a POJO? I thought POJO and java beans are same? Please clarify, i have a doubt. And ya, i was talking about utility class with static methods. I wanted these static methods to be accessed on page. – TCM Mar 31 '10 at 02:16
  • You showed a static non-getter method. This cannot be part of a POJO. – BalusC Mar 31 '10 at 11:18
  • 1
    POJO's don't have to have getters and setters. http://en.wikipedia.org/wiki/Plain_Old_Java_Object. From wikipedia: "Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification." – Bill Rosmus Nov 17 '12 at 18:16

1 Answers1

4

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 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 http://laala.com/el/AppDeployment getCommonImagePath Common.AppDeployment String getCommonImagePath(java.lang.String) – TCM Mar 31 '10 at 09:07
  • In my web.xml i added :- javax.faces.FACELETS_LIBRARIES /META-INF/AppDeployment.taglib.xml I keep getting configuration null error and tag not found in glassfish admin console. Please help me. – TCM Mar 31 '10 at 09:10
  • I get this error to be spccific : SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null – TCM Mar 31 '10 at 09:15
  • Hi balusC, i figured it out on my own. It was my silly mistake. Thanks again – TCM Mar 31 '10 at 09:39