JSF 1.2

Discussion in 'Java' started by Pif - 34, Jul 13, 2011.

  1. Pif - 34

    Pif - 34 Guest

    Hello,

    I'm working on a project based on JSF1.2. In a XHTML document, I must
    call a method using a parameter.

    So, since this is not possible directly using standard syntax, I would
    like to know if one of following solutions is possible that cut be
    usefull in my code:

    - use an include of a JSP template that do the code I need to place ? In
    a <html ... > doc, you can only include <html subdocs ?

    - include a JSP tag in the <html> that allow to place javacode ?

    Do you have Id of workarounds ?

    Thanks a lot.
    Pif - 34, Jul 13, 2011
    #1
    1. Advertising

  2. On 7/13/2011 3:03 AM, Pif - 34 wrote:
    > Hello,
    >
    > I'm working on a project based on JSF1.2. In a XHTML document, I must
    > call a method using a parameter.
    >
    > So, since this is not possible directly using standard syntax, I would
    > like to know if one of following solutions is possible that cut be
    > usefull in my code:
    >
    > - use an include of a JSP template that do the code I need to place ? In
    > a <html ... > doc, you can only include <html subdocs ?
    >
    > - include a JSP tag in the <html> that allow to place javacode ?
    >
    > Do you have Id of workarounds ?


    For just one such method, you can create a function you can call in the
    JSP expression language. Just two steps:

    - in an appropriate class, define a static method
    - in a TLD file, declare the function

    Details at

    http://download.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html


    If I have many such methods, I define one "call" method in some utility
    class (error checking code removed) and the associated TLD

    public static Object call(final Object obj, final String methodName,
    final Object arg)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
    return obj.getClass()
    .getMethod(methodName, arg.getClass())
    .invoke(obj, arg);
    }

    then I can write expressions like the following, where au is the prefix
    for my tag library:

    "${au:call(user, 'getDomainRoles', domain)}"

    to call user.getDomainRoles(domain)
    Chris Riesbeck, Jul 13, 2011
    #2
    1. Advertising

  3. Pif - 34

    lewbloch Guest

    On Jul 13, 11:17 am, Chris Riesbeck <> wrote:
    > On 7/13/2011 3:03 AM, Pif - 34 wrote:
    >
    > > Hello,

    >
    > > I'm working on a project based on JSF1.2. In a XHTML document, I must
    > > call a method using a parameter.

    >
    > > So, since this is not possible directly using standard syntax, I would
    > > like to know if one of following solutions is possible that cut be
    > > usefull in my code:

    >
    > > - use an include of a JSP template that do the code I need to place ? In
    > > a <html ... > doc, you can only include <html subdocs ?

    >
    > > - include a JSP tag in the <html> that allow to place javacode ?

    >
    > > Do you have Id of workarounds ?

    >
    > For just one such method, you can create a function you can call in the
    > JSP expression language. Just two steps:
    >
    >    - in an appropriate class, define a static method
    >    - in a TLD file, declare the function
    >
    > Details at
    >
    >    http://download.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html
    >
    > If I have many such methods, I define one "call" method in some utility
    > class (error checking code removed) and the associated TLD
    >
    >    public static Object call(final Object obj, final String methodName,
    > final Object arg)
    >    throws IllegalAccessException, InvocationTargetException,
    > NoSuchMethodException {
    >     return obj.getClass()
    >               .getMethod(methodName, arg.getClass())
    >               .invoke(obj, arg);
    >    }
    >
    > then I can write expressions like the following, where au is the prefix
    > for my tag library:
    >
    >     "${au:call(user, 'getDomainRoles', domain)}"
    >
    > to call user.getDomainRoles(domain)


    Why are people discussing JSP when the OP states that the problem is
    in XHTML?

    There are other ways, too - for example, set a member variable in a
    page-level bean instead of passing a method argument.

    I thought EL allowed passing arguments to methods. I will have to
    research this. It's a problem I've faced before but I don't remember
    the solution off the top of my head. I'll be back on that.

    --
    Lew
    lewbloch, Jul 13, 2011
    #3
  4. On 13/07/2011 11:32 AM, lewbloch wrote:
    > I thought EL allowed passing arguments to methods. I will have to
    > research this. It's a problem I've faced before but I don't remember
    > the solution off the top of my head. I'll be back on that.


    Not in JSF 1.2. It's in JSF 2.0.

    Although this post suggests it can be done by just changing other base
    technology versions:
    http://stackoverflow.com/questions/5273729/how-to-call-a-method-with-a-parameter-in-jsf
    Travers Naran, Jul 18, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Javaholic
    Replies:
    1
    Views:
    1,219
    Jonathan Revusky
    Jul 14, 2003
  2. orientphoebus

    file upload with Struts or JSF

    orientphoebus, Dec 17, 2003, in forum: Java
    Replies:
    2
    Views:
    1,718
    Mladen Adamovic
    Dec 19, 2003
  3. dudu
    Replies:
    0
    Views:
    353
  4. Sebastian Fey

    JSF debugging / JSF newsgroup

    Sebastian Fey, Apr 7, 2006, in forum: Java
    Replies:
    1
    Views:
    7,602
    Danno
    Apr 7, 2006
  5. BlackIce
    Replies:
    1
    Views:
    17,143
Loading...

Share This Page