<TD><bean:write name="myBean" property="myBeanProperty" /></TD>
In this case we expect that struts will call,
myBean.getMyBeanProperty();
by constucting getter method for your property like,
"get" + capitalizeFirstChar(myBeanProperty)
and then calling the resultant method "getMyBeanProperty" on the
bean using reflection.
However it is the other way around,
1) If your bean has a method like "getXXXXXXX" then the property name
you are specifing in JSP should match with the 'internal property'.
You can construct 'internal property' in the following manner.
Struts internally prepares a properties list of 'internal properties'
from the methods in your bean.
The internal property construction is as shown below,
1) Strip off the "get" from the bean getter method.
Now it will become 'XXXXXXX'
2) If first 2 chars of 'XXXXXXX' are chapital letters then
XXXXXXX is the 'internal property'.
otherwise
xXXXXXX is the 'internal propery'.
The property name you are specifing in JSP should match with the
internal propery other wise you will get
"No getter method for property name problem"
General way of specifying getter/setters by following java convensions.
properygetterinternal propery construction
==============================================
namegetNamegetName -> Name -> name
countryNamegetCountryNamegetCountryName -> CountryName -> countryName
fNamegetFNamegetFName -> FName -> FName (since first 2 chars are upper)
<TD><bean:write name="myBean" property="myBeanProperty" /></TD>
In JSP assuming property is the real propery of the bean, we may
specify the following tags,
<TD><bean:write name="myBean" property="name" /></TD>
<TD><bean:write name="myBean" property="countryName" /></TD>
<TD><bean:write name="myBean" property="fName" /></TD>
The first two TD work absolutely fine because the property name we have specified
and the internal property constucted above are exactly same.
But for the 3rd TD the property name and internal property constucted are different.
This is where the problem comes and you wil get the "No getter method for property name"
So make sure that you are giving the internal propery name instead of the
actual bean propery.
Below i have given a simple example of a bean and displaying its properties in the JSP.
JSP
====
<table border=0 cellpadding=0 cellspacing=0>
<logic:iterate id="userDet" type="com.sym.entity.User" name="usersList" scope="session">
<TR>
<TD><bean:write name="userDet" property="FName" /></TD>
<TD><bean:write name="userDet" property="FIRSTNAME" /></TD>
<TD><bean:write name="userDet" property="LName" /></TD>
<TD><bean:write name="userDet" property="login" /></TD>
<TD><bean:write name="userDet" property="email" /></TD>
</TR>
</logic:iterate>
</table>
BEAN
=====
package com.sym.entity;
public class User implements java.io.Serializable {
private static final long serialVersionUID = 4148531659281963091L;
String fName=null;
String lName=null;
String login=null;
String pass=null;
String email=null;
int uId;
String role=null;
public String getFName() {
return fName;
}
public String getFIRSTNAME() {
return fName;
}
public void setFName(String name) {
fName = name;
}
public String getLName() {
return lName;
}
public void setLName(String name) {
lName = name;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getUId() {
return uId;
}
public void setUId(int id) {
uId = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
I hope it is clear.
Happy Coding