JSF 1.2

P

Pif - 34

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.
 
C

Chris Riesbeck

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)
 
L

lewbloch

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top