Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JSF 1.2 (http://www.velocityreviews.com/forums/t751374-jsf-1-2-a.html)

Pif - 34 07-13-2011 08:03 AM

JSF 1.2
 
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.

Chris Riesbeck 07-13-2011 06:17 PM

Re: JSF 1.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....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)



lewbloch 07-13-2011 06:32 PM

Re: JSF 1.2
 
On Jul 13, 11:17*am, Chris Riesbeck <Chris.Riesb...@gmail.com> 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....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

Travers Naran 07-18-2011 04:54 AM

Re: JSF 1.2
 
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/5...rameter-in-jsf


All times are GMT. The time now is 11:04 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.