Java – Struts 2 passing data from JSP to action class


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, than struts2 will try to call setSomething(...) automatically in the action class.

I'm now seeing this type of code:

<s:textfield 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 mean between item and name and how do I use it correctly to instantiate the item and set it's name?

PS: The item object that is being set in setItem() in my action class has an empty args constructor.

Best Solution

In OGNL . is the dot notation. means getItem().setName(); means getItem().getSubitem.setName();

One problem could be the missing empty args constructor, as described here, but you are saying it's not your case; then I bet on the "missing getter for Item". If it's not, please post more relevant code.

Related Question