I'm trying to understand somebody's else Struts 2 code and I'm stuck with a data passing problem.
I know that on a JSP page, if you use a <s:textfield name="something" ... />
tag, thrn Struts 2 will try to call setSomething(...)
automatically in the action class.
I'm now seeing this type of code:
<s:textfield name="item.name" ... />
and I'm wondering, how does this .
(dot) work? I have a method called setItem()
in my action class, and the object that is being set in that method has a setName()
method, but apparently this doesn't work. What does the dot means between item
and name
, and how do I use it correctly to instantiate the item and set its name?
PS: The item object that is being set in setItem()
in my action class has an empty args
constructor.
The problem is solved. The getItem() actually contained the following code:
public Item getItem()
{
System.out.println("Trying to get item: " + item.toString());
return item;
}
And this gave a nullpointer exception because item was null. Only, this nullpointerexception was NOT THROWN by the struts framework! The code just continued (and failed of course...). When I removed the sysout statement, the code worked.