You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by JS Portal Support <su...@jsportal.com> on 2006/09/25 13:20:13 UTC
How to reference a static value in JSF
Hi,
Just started to implement Shale and JSF. As I've always worked more with
scriptlets and Servlets I can't seem to figure out how to reference a public
static value from one of my classes in my JSP's. I've always used:
<input type="hidden" name="a"
value="<%=com.jsportal.projectportal.web.webActions.login%>"/>
Now I try to achieve this with the following:
<h:inputHidden id="a"
value="${com.jsportal.projectportal.web.webActions.login}"/>
I understand this doesn't work as it will try to call
com.getJsportal()....etc. But how do I do it, as the <%=%> is not allowed in
these taglib tags?
Thanks,
Joost
RE: How to reference a static value in JSF
Posted by "Kito D. Mann" <km...@virtua.com>.
There's also a library that implements this feature (and accessing methods,
among other things) in JSF 1.2: http://el-functors.sourceforge.net/.
In the EG, we were never really keen on the idea of calling methods via the
EL, but I think constants makes a lot of sense. And, given the fact that
people are always adding support for method calls, perhaps that should be
there as well.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann (kmann@virtua.com)
Author, JavaServer Faces in Action
http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info
> -----Original Message-----
> From: David Delbecq [mailto:delbd@oma.be]
> Sent: Thursday, September 28, 2006 12:58 PM
> To: user@shale.apache.org
> Subject: Re: How to reference a static value in JSF
>
> You can simply create a bean implementing the Map interface.
> Then, in the get(Object key) use introspection to locate the
> class referenced and extract the given public field.
> eg, get("some.package.Class.THE_FIELD") will do a return
> Class.forName("some.package.Class").someMethodAmTooLazyTooLook
> ForInApi("THE_FIELD");
>
> This should take no more than a few lines of code to create
> such bean and you can even make it read/write :)
>
> Reference this bean as an application bean, with a name like
> 'StaticAccessor' and use this in your JSF:
> <h:inputHidden id="a"
> value="#{StaticAccessor['com.jsportal.projectportal.web.webAct
> ions.login']}"/>
>
> Note: use #{} and not ${} in JSF!!
> JS Portal Support a écrit :
> > Hi,
> >
> > Just started to implement Shale and JSF. As I've always worked more
> > with scriptlets and Servlets I can't seem to figure out how to
> > reference a public static value from one of my classes in
> my JSP's. I've always used:
> >
> > <input type="hidden" name="a"
> > value="<%=com.jsportal.projectportal.web.webActions.login%>"/>
> >
> > Now I try to achieve this with the following:
> >
> > <h:inputHidden id="a"
> > value="${com.jsportal.projectportal.web.webActions.login}"/>
> >
> > I understand this doesn't work as it will try to call
> > com.getJsportal()....etc. But how do I do it, as the <%=%> is not
> > allowed in these taglib tags?
> >
> > Thanks,
> > Joost
> >
> >
>
Re: How to reference a static value in JSF
Posted by David Delbecq <de...@oma.be>.
You can simply create a bean implementing the Map interface. Then, in
the get(Object key) use introspection to locate the class referenced and
extract the given public field.
eg, get("some.package.Class.THE_FIELD") will do a
return
Class.forName("some.package.Class").someMethodAmTooLazyTooLookForInApi("THE_FIELD");
This should take no more than a few lines of code to create such bean
and you can even make it read/write :)
Reference this bean as an application bean, with a name like
'StaticAccessor' and use this in your JSF:
<h:inputHidden id="a"
value="#{StaticAccessor['com.jsportal.projectportal.web.webActions.login']}"/>
Note: use #{} and not ${} in JSF!!
JS Portal Support a écrit :
> Hi,
>
> Just started to implement Shale and JSF. As I've always worked more with
> scriptlets and Servlets I can't seem to figure out how to reference a public
> static value from one of my classes in my JSP's. I've always used:
>
> <input type="hidden" name="a"
> value="<%=com.jsportal.projectportal.web.webActions.login%>"/>
>
> Now I try to achieve this with the following:
>
> <h:inputHidden id="a"
> value="${com.jsportal.projectportal.web.webActions.login}"/>
>
> I understand this doesn't work as it will try to call
> com.getJsportal()....etc. But how do I do it, as the <%=%> is not allowed in
> these taglib tags?
>
> Thanks,
> Joost
>
>