You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by DavidCAIT <dz...@cait.org> on 2009/02/03 17:10:50 UTC
Null element in List
Hi,
I have a list of Integers and I want one of the options to be null (since it
is a search field). However, I get the following freemarker exception when
rendering my JSP:
>> FreeMarker template error!
>> Error on line 73, column 13 in template/simple/select.ftl
>> stack.findValue('top') is undefined.
>> It cannot be assigned to itemKey
>> The problematic instruction:
>> ----------
>>==> assignment: itemKey=stack.findValue('top') [on line 73, column 13
in template/simple/select.ftl]
>> in user-directive s.iterator [on line 63, column 1 in
>> template/simple/select.ftl]
>> ----------
I am using Struts 2.0.11 with the following action:
public class simpleAction implements Preparable {
// both myList and value have a public getter and setter
private List<Integer> myList = new ArrayList<Integer>();
private Integer value;
public String prepare() {
myList.add(null); // commenting out this line removes the runtime JSP
exception
for (int i = 0; i < 60; i++) {
myList.add(i);
} } }
My JSP page:
<html>
<body>
<s:form action="anotherAction">
<s:select list="myList" />
<s:submit />
</s:form>
</body></html>
Does anyone have any ideas or workarounds about how I can include a null
entry in a list of integers without getting this freemarker exception?
Thanks,
David
--
View this message in context: http://www.nabble.com/Null-element-in-List%3CInteger%3E-tp21812998p21812998.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: Null element in List
Posted by Dave Newton <ne...@yahoo.com>.
Use <s:select...>'s "emptyOption" attribute?
I mean, you can't just put a "null" into a list and expect to get a
value from it--you could put an empty string, maybe; that might work
with an Integer object to avoid getting a 0.
Dave
DavidCAIT wrote:
> Actually that didn't work out when I tested it.
>
> A TreeMap sorts elements by calling Object.equals. When it encounters my
> null element, it tries to de-reference it and throws an exception.
>
> HashMap does not produce any exceptions, but leaves my numbers in a very
> strange order like:
>
> 3, 2, 4, 1, 5, 0
>
> even though I inserted them in order.
>
> In summary, I am still trying to have a list of numbers which also allows
> null to be available through my user interface's select dropdown box.
> Ideally I would like to use an ArrayList if I could resolve the freemarker
> exception.
>
> Thanks again,
>
> David
>
>
> DavidCAIT wrote:
>> I did find a workaround which is a bit undesirable.
>>
>> If I change my ArrayList to a TreeMap and store the same value for the key
>> and the value then the problem disappears. However, it is a bit wasteful
>> to store each value in the list twice.
>>
>> Any other ideas? If not, my workaround is good enough for me.............
>>
>>
>> DavidCAIT wrote:
>>> Hi,
>>>
>>> I have a list of Integers and I want one of the options to be null (since
>>> it is a search field). However, I get the following freemarker exception
>>> when rendering my JSP:
>>>
>>>>> FreeMarker template error!
>>>>> Error on line 73, column 13 in template/simple/select.ftl
>>>>> stack.findValue('top') is undefined.
>>>>> It cannot be assigned to itemKey
>>>>> The problematic instruction:
>>>>> ----------
>>>>> ==> assignment: itemKey=stack.findValue('top') [on line 73, column 13
> in template/simple/select.ftl]
>>>>> in user-directive s.iterator [on line 63, column 1 in
>>>>> template/simple/select.ftl]
>>>>> ----------
>>> I am using Struts 2.0.11 with the following action:
>>>
>>> public class simpleAction implements Preparable {
>>>
>>> // both myList and value have a public getter and setter
>>> private List<Integer> myList = new ArrayList<Integer>();
>>> private Integer value;
>>>
>>> public String prepare() {
>>>
>>> myList.add(null); // commenting out this line removes the runtime JSP
>>> exception
>>> for (int i = 0; i < 60; i++) {
>>> myList.add(i);
>>> } } }
>>>
>>> My JSP page:
>>>
>>> <html>
>>> <body>
>>> <s:form action="anotherAction">
>>> <s:select list="myList" />
>>> <s:submit />
>>> </s:form>
>>> </body></html>
>>>
>>> Does anyone have any ideas or workarounds about how I can include a null
>>> entry in a list of integers without getting this freemarker exception?
>>> Thanks,
>>>
>>> David
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Null element in List
Posted by DavidCAIT <dz...@cait.org>.
Actually that didn't work out when I tested it.
A TreeMap sorts elements by calling Object.equals. When it encounters my
null element, it tries to de-reference it and throws an exception.
HashMap does not produce any exceptions, but leaves my numbers in a very
strange order like:
3, 2, 4, 1, 5, 0
even though I inserted them in order.
In summary, I am still trying to have a list of numbers which also allows
null to be available through my user interface's select dropdown box.
Ideally I would like to use an ArrayList if I could resolve the freemarker
exception.
Thanks again,
David
DavidCAIT wrote:
>
> I did find a workaround which is a bit undesirable.
>
> If I change my ArrayList to a TreeMap and store the same value for the key
> and the value then the problem disappears. However, it is a bit wasteful
> to store each value in the list twice.
>
> Any other ideas? If not, my workaround is good enough for me.............
>
>
> DavidCAIT wrote:
>>
>> Hi,
>>
>> I have a list of Integers and I want one of the options to be null (since
>> it is a search field). However, I get the following freemarker exception
>> when rendering my JSP:
>>
>>>> FreeMarker template error!
>>
>>>> Error on line 73, column 13 in template/simple/select.ftl
>>>> stack.findValue('top') is undefined.
>>>> It cannot be assigned to itemKey
>>>> The problematic instruction:
>>>> ----------
>>>>==> assignment: itemKey=stack.findValue('top') [on line 73, column 13
in template/simple/select.ftl]
>>>> in user-directive s.iterator [on line 63, column 1 in
>>>> template/simple/select.ftl]
>>>> ----------
>>
>> I am using Struts 2.0.11 with the following action:
>>
>> public class simpleAction implements Preparable {
>>
>> // both myList and value have a public getter and setter
>> private List<Integer> myList = new ArrayList<Integer>();
>> private Integer value;
>>
>> public String prepare() {
>>
>> myList.add(null); // commenting out this line removes the runtime JSP
>> exception
>> for (int i = 0; i < 60; i++) {
>> myList.add(i);
>> } } }
>>
>> My JSP page:
>>
>> <html>
>> <body>
>> <s:form action="anotherAction">
>> <s:select list="myList" />
>> <s:submit />
>> </s:form>
>> </body></html>
>>
>> Does anyone have any ideas or workarounds about how I can include a null
>> entry in a list of integers without getting this freemarker exception?
>> Thanks,
>>
>> David
>>
>
>
--
View this message in context: http://www.nabble.com/Null-element-in-List%3CInteger%3E-tp21812998p21813746.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: Null element in List
Posted by DavidCAIT <dz...@cait.org>.
I did find a workaround which is a bit undesirable.
If I change my ArrayList to a TreeMap and store the same value for the key
and the value then the problem disappears. However, it is a bit wasteful to
store each value in the list twice.
Any other ideas? If not, my workaround is good enough for me.............
DavidCAIT wrote:
>
> Hi,
>
> I have a list of Integers and I want one of the options to be null (since
> it is a search field). However, I get the following freemarker exception
> when rendering my JSP:
>
>>> FreeMarker template error!
>
>>> Error on line 73, column 13 in template/simple/select.ftl
>>> stack.findValue('top') is undefined.
>>> It cannot be assigned to itemKey
>>> The problematic instruction:
>>> ----------
>>>==> assignment: itemKey=stack.findValue('top') [on line 73, column 13
in template/simple/select.ftl]
>>> in user-directive s.iterator [on line 63, column 1 in
>>> template/simple/select.ftl]
>>> ----------
>
> I am using Struts 2.0.11 with the following action:
>
> public class simpleAction implements Preparable {
>
> // both myList and value have a public getter and setter
> private List<Integer> myList = new ArrayList<Integer>();
> private Integer value;
>
> public String prepare() {
>
> myList.add(null); // commenting out this line removes the runtime JSP
> exception
> for (int i = 0; i < 60; i++) {
> myList.add(i);
> } } }
>
> My JSP page:
>
> <html>
> <body>
> <s:form action="anotherAction">
> <s:select list="myList" />
> <s:submit />
> </s:form>
> </body></html>
>
> Does anyone have any ideas or workarounds about how I can include a null
> entry in a list of integers without getting this freemarker exception?
> Thanks,
>
> David
>
--
View this message in context: http://www.nabble.com/Null-element-in-List%3CInteger%3E-tp21812998p21813376.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