1

I am trying to call method using custom EL function with perameter of jsfbean.

<c:set var="test1" value="${cx:methodName('para')}" scope="session"/>
        <h:outputText value="#{test1}"/>

i made following id TLD and putted it into WEB-INF

  <?xml version="1.0" encoding="UTF-8" ?>
    <taglib 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
        version="2.1">

        <tlib-version>1.0</tlib-version>
        <short-name>Custom_Functions</short-name>
        <uri>http://example.com/functions</uri>

        <function>
            <name>methodName</name>
            <function-class>funcionclass(Jsfbean)</function-class>
            <function-signature>java.lang.String methodName(java.lang.String)</function-signature>
        </function>
    </taglib>

i also configure in web.xml

<jsp-config> 
        <taglib> 
               <taglib-uri>http://example.com/functions</taglib-uri> 
               <taglib-location>/WEB-INF/functions.tld</taglib-location> 
        </taglib> 
</jsp-config>

and still it is getting Function not found error.

following is method code

public static String methodName(String s1) throws Exception
    {
        return "Kshitij";
    }

can any body help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
MRX
  • 1,611
  • 8
  • 33
  • 55
  • 1
    Are you using JSP or Facelets? You've created a JSP EL function, but your JSF 2.0 tag indicates that you're possibly actually using Facelets. Further, which servletcontainer are you targeting? Is it Servlet 3.0 compatible? Is the `web.xml` declared conform Servlet 3.0? – BalusC Apr 19 '12 at 11:44
  • yes. i am using facelets. and this is my web.xml – MRX Apr 19 '12 at 12:12
  • Huh? Are you running JSF 2.0 on a Servlet 2.4 container? This ain't ever going to work without hacks. What exactly is your server make/version? – BalusC Apr 19 '12 at 12:13
  • That's a Servlet 2.5 compatible container. You should set web.xml to Servlet 2.5. – BalusC Apr 19 '12 at 12:15
  • i am getting error. like Multiple annotations found at this line: - cvc-enumeration-valid: Value '2.5' is not facet-valid with respect to enumeration '[2.4]'. It must be a value from the enumeration. – MRX Apr 19 '12 at 12:18
  • That's a different problem. For example, you've set your IDE project facet version to 2.4 instead of 2.5. – BalusC Apr 19 '12 at 12:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10275/discussion-between-kshitij-and-balusc) – MRX Apr 19 '12 at 12:20

2 Answers2

3

You've created a JSP EL function while you're using Facelets. This is not going to work. Also, your <function-class> declaration is incorrect. It should specify the full qualified class name (FQN). E.g. com.example.FunctionClass.

Rename the taglib file to /WEB-INF/functions.taglib.xml with the following updated content:

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0">
    <namespace>http://example.com/functions</namespace>

    <function>
        <function-name>methodName</function-name>
        <function-class>com.example.FunctionClass</function-class>
        <function-signature>java.lang.String methodName(java.lang.String)</function-signature>
    </function>
</facelet-taglib>

Then you need to register it in web.xml as follows (don't forget to remove the old JSP taglib registration!):

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>

Finally declare it in your view by the following XML namespace

xmlns:cx="http://example.com/functions"

Unrelated to the concrete problem, there's an alternative approach, probably much easier: install JBoss EL. This way you will be able to invoke methods on beans like as possible in the new EL 2.2.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

You still need to include the reference in your jsp:

<%@taglib prefix="cx" uri="http://example.com/functions"%>
slipset
  • 2,960
  • 2
  • 21
  • 17
  • i am using facelets and and following ns i am using. xmlns:cx="http://example.com/functions" – MRX Apr 19 '12 at 12:14