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:
----------
==&gt; 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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to