You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mrakomor <mr...@gmail.com> on 2009/09/02 14:00:20 UTC
Problem with collection in select
Hello folks,
I wanted to use a Struts 2 select in the form. I wanted to populate the list
using filtered collection. If I use it without the filter, like this:
<s:select
name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
listKey="contractNr" listValue="contractNr"
list="depzad.dzZadostMat.contractList" />
it works just fine. In depzad.dzZadostMat.contractList is a list of the
contracts and contract numbers are in the select.
If I use a filter, that compares a number, it works too:
<s:select
name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
listKey="contractNr" listValue="contractNr"
list="depzad.dzZadostMat.contractList.{? #this.integerProperty>20}" />
"integerProperty" - there is a valid getter for the integerProperty in the
Contract class and the list I obtain is properly filtered.
However if the property for the filtering is a String:
<s:select
name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
listKey="contractNr" listValue="contractNr"
list="depzad.dzZadostMat.contractList.{? #this.stringProperty=='B'}" />
I receive an error message:
org.apache.struts2.StrutsException #8636967tag 'select', field 'list', name
'depzad.dzRequest.contractList[1].selectedContract': The requested list key
'depzad.dzRequest.contractList.{?#this.stringProperty=='B'}' could not be
resolved as a collection/array/map/enumeration/iterator type. Example:
people or people.{name} - [unknown location]
The public String getStringProperty() function exists in the Class, but it
is not called. What may be wrong?
--
View this message in context: http://www.nabble.com/Problem-with-collection-in-select-tp25256112p25256112.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problem with collection in select
Posted by Mrakomor <mr...@gmail.com>.
Your advice works! I used a javascript workaround in the meantime, however
your answer will spare me a lot of time next time.
--
View this message in context: http://www.nabble.com/Problem-with-collection-in-select-tp25256112p25259300.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problem with collection in select
Posted by Wes Wannemacher <we...@wantii.com>.
My guess is that your single-char string is evaluated as a single char...
http://struts.apache.org/2.x/docs/why-wont-the-if-tag-evaluate-a-one-char-string.html
Try flipping the quotes or escaping double-quotes in the expression,
then OGNL will probably figure it out.
-Wes
On Wed, Sep 2, 2009 at 8:00 AM, Mrakomor<mr...@gmail.com> wrote:
>
> Hello folks,
>
> I wanted to use a Struts 2 select in the form. I wanted to populate the list
> using filtered collection. If I use it without the filter, like this:
>
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList" />
>
>
> it works just fine. In depzad.dzZadostMat.contractList is a list of the
> contracts and contract numbers are in the select.
>
> If I use a filter, that compares a number, it works too:
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList.{? #this.integerProperty>20}" />
>
> "integerProperty" - there is a valid getter for the integerProperty in the
> Contract class and the list I obtain is properly filtered.
>
> However if the property for the filtering is a String:
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList.{? #this.stringProperty=='B'}" />
>
> I receive an error message:
> org.apache.struts2.StrutsException #8636967tag 'select', field 'list', name
> 'depzad.dzRequest.contractList[1].selectedContract': The requested list key
> 'depzad.dzRequest.contractList.{?#this.stringProperty=='B'}' could not be
> resolved as a collection/array/map/enumeration/iterator type. Example:
> people or people.{name} - [unknown location]
>
> The public String getStringProperty() function exists in the Class, but it
> is not called. What may be wrong?
>
> --
> View this message in context: http://www.nabble.com/Problem-with-collection-in-select-tp25256112p25256112.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Wes Wannemacher
Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problem with collection in select
Posted by Dave Newton <ne...@yahoo.com>.
Mrakomor wrote:
> Hello folks,
>
> I wanted to use a Struts 2 select in the form. I wanted to populate the list
> using filtered collection. If I use it without the filter, like this:
>
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList" />
>
>
> it works just fine. In depzad.dzZadostMat.contractList is a list of the
> contracts and contract numbers are in the select.
>
> If I use a filter, that compares a number, it works too:
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList.{? #this.integerProperty>20}" />
>
> "integerProperty" - there is a valid getter for the integerProperty in the
> Contract class and the list I obtain is properly filtered.
>
> However if the property for the filtering is a String:
> <s:select
> name="depzad.dzRequest.contractList[%{#status.index}].selectedContract"
> listKey="contractNr" listValue="contractNr"
> list="depzad.dzZadostMat.contractList.{? #this.stringProperty=='B'}" />
OGNL treats single chars in single quotes as chars, not strings.
http://struts.apache.org/2.x/docs/why-wont-the-if-tag-evaluate-a-one-char-string.html
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org