You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Christian Nolte <ch...@noltec.org> on 2007/08/01 22:07:02 UTC
How to evaluate values set with JSTL-Core-tag 'set' with JSF
Hi!
I have the following problem: I have to evaluate values which have been
set using JSTL-Core-tags like set or forEach using JSF-Tags like
outputText to output them. The situation is like this:
-- test.jsp:
<!-- ... -->
<jsp:useBean id="bean" class="de.fhbswf.emaex.web.TestBean" />
<c:set var="test" value="${bean.test}" />
Set: ${test}
Output: <h:outputText value="#{test}"/>
<!-- ... -->
--
I understand that JSF has no rtexpression evaluation and I know that
this is for security reasons but I would like to know how I can use
these two taglibs together.
Best regards
Christian
--
For more than 4 generations the IT Professionals were the
guardians of quality and stability in software. Before the
dark times. Before Microsoft...
Re: How to evaluate values set with JSTL-Core-tag 'set' with JSF
Posted by Bryan Basham <bb...@stillsecure.com>.
Hello Christian,
> Thank you very much! This indeed works. Is there a 'better' or another
> approach which I could take? A concrete use-case would be that I want to
> iterate over a collection from a bean (not a managed bean) like that:
>
> - ---
> <jsp:useBean id="bean" class="de.fhbswf.emaex.web.TestBean"
> scope="request"/>
>
> <c:forEach var="testValue" items="${bean.test}" >
> <h:outputText value="${testValue.value}" />
> </c:forEach>
> - ---
>
> In this case it is not possible without saving the value in a variable
> created by c:set.
>
Unfortunately, the <c:forEach> tag does not allow you to specify the
scope; it is always page-scoped. So, by using <c:forEach> you are
forced to use <c:set> to get the value into the request scope. There
are, of course, always alternatives, but the ones that I can think of
are non-trivial. First, you would create a new JSF variable resolver
which accesses the page-scope (not really sure that is possible).
Second, you could write your own forEach tag which puts the 'var' into
the request scope.
> Another use-case I have is to manipulate the id's of h:inputText-tags so
> that the id in the message which a validator produces can be localized
> or simply replaced:
>
> - ---
>
> <f:loadBundle
> basename="properties.localization.ui.suppliercreateproduct"
> var="createproductBundle"/>
>
> <h:inputText id="${createproductBundle.articlenrID}"
> required="true"
> value="#{ProductCreator.articlenumber}">
>
> <h:message for="${createproductBundle.articlenrID}"
> styleClass="error" />
> - ---
>
> So again: could these cases be handled in a better way?
>
Hmm??? Not exactly sure what you are trying to achieve here. I never
use the standard JSF <h:message> tag because my company has created it's
own UIFieldMessage component which performs internationalization of
screen messages, but we don't modify the field IDs directly, but rather
use these IDs to look up a field name (and message) from a properties file.
Good luck,
Bryan
Re: How to evaluate values set with JSTL-Core-tag 'set' with JSF
Posted by Christian Nolte <ch...@noltec.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bryan Basham schrieb:
> By default the JSTL <c:set> tag stores the attribute in the PAGE scope.
> However, JSF does not know about the PAGE scope. If you really need
> to use <c:set> then specify: scope='REQUEST'.
>
> -Bryan
Thank you very much! This indeed works. Is there a 'better' or another
approach which I could take? A concrete use-case would be that I want to
iterate over a collection from a bean (not a managed bean) like that:
- ---
<jsp:useBean id="bean" class="de.fhbswf.emaex.web.TestBean"
scope="request"/>
<c:forEach var="testValue" items="${bean.test}" >
<h:outputText value="${testValue.value}" />
</c:forEach>
- ---
In this case it is not possible without saving the value in a variable
created by c:set.
Another use-case I have is to manipulate the id's of h:inputText-tags so
that the id in the message which a validator produces can be localized
or simply replaced:
- ---
<f:loadBundle
basename="properties.localization.ui.suppliercreateproduct"
var="createproductBundle"/>
<h:inputText id="${createproductBundle.articlenrID}"
required="true"
value="#{ProductCreator.articlenumber}">
<h:message for="${createproductBundle.articlenrID}"
styleClass="error" />
- ---
So again: could these cases be handled in a better way?
Christian
> Christian Nolte wrote:
>> Hi!
>>
>> I have the following problem: I have to evaluate values which have been
>> set using JSTL-Core-tags like set or forEach using JSF-Tags like
>> outputText to output them. The situation is like this:
>>
>> -- test.jsp:
>> <!-- ... -->
>>
>> <jsp:useBean id="bean" class="de.fhbswf.emaex.web.TestBean" />
>>
>> <c:set var="test" value="${bean.test}" />
>> Set: ${test}
>>
>> Output: <h:outputText value="#{test}"/>
>>
>> <!-- ... -->
>> --
>>
>> I understand that JSF has no rtexpression evaluation and I know that
>> this is for security reasons but I would like to know how I can use
>> these two taglibs together.
>>
>> Best regards
>> Christian
>>
>>
>>
>
- --
For more than 4 generations the IT Professionals were the
guardians of quality and stability in software. Before the
dark times. Before Microsoft...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFGshL8CNjA0nfhW7wRAtT9AKDDRBdMm1gamN6tqgMycmfwLeFEPQCfXao+
vKTumz51p2FkVpedwkL+i+s=
=qqKr
-----END PGP SIGNATURE-----
Re: How to evaluate values set with JSTL-Core-tag 'set' with JSF
Posted by Bryan Basham <bb...@stillsecure.com>.
By default the JSTL <c:set> tag stores the attribute in the PAGE scope.
However, JSF does not know about the PAGE scope. If you really need
to use <c:set> then specify: scope='REQUEST'.
-Bryan
Christian Nolte wrote:
> Hi!
>
> I have the following problem: I have to evaluate values which have been
> set using JSTL-Core-tags like set or forEach using JSF-Tags like
> outputText to output them. The situation is like this:
>
> -- test.jsp:
> <!-- ... -->
>
> <jsp:useBean id="bean" class="de.fhbswf.emaex.web.TestBean" />
>
> <c:set var="test" value="${bean.test}" />
> Set: ${test}
>
> Output: <h:outputText value="#{test}"/>
>
> <!-- ... -->
> --
>
> I understand that JSF has no rtexpression evaluation and I know that
> this is for security reasons but I would like to know how I can use
> these two taglibs together.
>
> Best regards
> Christian
>
>
>