Search code examples
javapropertiesstrutsstruts-1

html:options calls get before set -> null pointer


I have the following:

    <html:select property="myObject.value">
        <html:options property='myMap(someKey)'/>
    </html:select>

Where map(someKey) is set in the action. I've also created these methods in the form:

public void setMyMap( final Map<String, Collection<String>> map )
{
    myMap = map;
}

public Map<String, Collection<String>> getMyMap()
{
    return myMap;
}

This almost seems to work, but occasionally myMap(someKey) is accessed before the appropriate Action is even hit, leading to null pointers. What am I doing wrong, here?

Edit:
If I use a LazyMap to work around this issue, I avoid null pointers until the action sets the form up. I'd still like to know why this is happening, however.


Solution

  • Use a LazyMap or upgrade to Struts 2/3, so someone might actually be able to help you.