All you need to have is getter and setter methods for the fields in your Action
class. Struts2 will put that object on the top of ValueStack
and With the help of OGNL
you can access the properties from JSP.
Here is the code snippet
public class Test Extends ActionSupport{
public String execute() throws Exception{
// Action Logic fetching/Init code object
return SUCCESS;
}
private Code code=null;
public void setCode(Code code){
this.code=code
}
public Code getCode(){
return code;
}
}
Now Struts2 framework will put the code
instance on the top of ValueStack
which is the place where all request processing data is being placed by the framework and being referred by the jsp/Actions using OGNL which is a navigation language to fetch the data.
in your JSP you can access the code
instance with the following code
<s:property value="%{code.codeId}"/>
or
<s:textfield name="abc" value="%{code.codeId}"/>
what exactly happening here is that framework has placed your code
instance with the filled value on the ValueStack
and with the help of OGNL we are fetching that value.
OGNL will check if there is an instance namd code
on the top of value stack which will be placed by framework, after it found code
instance it will check if it has codeId property. On finding the property, OGNL
will do the data type conversion and will show the value in JSP.
hope this will help you.