I have declared a boolean variable as isABooleanValue
in the Struts 2 modelbean and I am able to see the value by using this modelbean.aBooleanValue
in jsp.
getter looks like this
public boolean isABooleanValue(){
return isABooleanValue;
}
setter looks like this
public void setABooleanValue(boolean isABooleanValue){
this.isABooleanValue=isABooleanValue;
}
Jsp code
<s:property value="modelbean.aBooleanValue" />
can anyone explain how an incorrect variable name be accessed like this from value stack.
Edit
Solution
Using property in JSP is based on the Getter method specified. modelbean.aBooleanValue
calls the isABooleanValue()
method defined in your Model Bean, hence, not dependent on private field name.
Update:- Though this may seem to work in older version of OGNL but OGNL version 3.0.11 (OgnlRuntime) which is bundled with Struts2 may cause blank values be displayed when getter and setter of fields names are not same.