Struts: No getter method for property name problem
Karthik Guru
Ranch Hand
Joined: Mar 06, 2001
Posts: 1209
posted
0
Hi All, Am using Struts. jsp trace looks like this.. Struts: No getter method for property name of bean org.apache.struts.taglib.html.BEAN This is the error am getting while rendering the page. I find it amusing. I have the form class with a getter and setter for properties name, country. In the action class, I fill up the Form class and set it against the mapping.getAttribute() String in the request. Am not sure why its not able to find the getters by reflection. Any help w'd be of great help to me thanks.
Adam Hardy
Ranch Hand
Joined: Oct 09, 2001
Posts: 563
posted
0
Hi Karthik, it's not necessarily anything to do with your formbean. It could be that you have not specified the name attribute on some <bean: tag. Try reducing the HTML page to the bare minimum that causes this error and then post it here (please don't post loads of html). Adam
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Ta Ri Ki Sun
Ranch Hand
Joined: Mar 26, 2002
Posts: 442
posted
0
are you sure your getter is spelt getName() , getCountry() ? thats what my problem was last time i saw that error
Prasad P Nair
Greenhorn
Joined: Nov 22, 2002
Posts: 10
posted
0
Hi All, I'm also new to Struts.So was experimenting with the stuffs. I also coem across the same problem. I'm attaching the html code and my Actionbean. CAn anybody help? HTML =========================== <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <% System.out.println("inside Form"); %> dshjfasdkhfasdkljfhasdkjfhasdfkjhasdk <html:html> <body> <html:form action="/save.do?Page=1"> <table> <tr> <td>username</td> <td><html:text property="UserName" size="16" /></td> </tr> <tr> <td>password</td> <td><html:text property="PassWord" size="16" value="" /></td> </tr> <tr> <td colspan=2> <html:submit/>
Try changing the properties to start with a lower case instead of upper case. "username" instead of "UserName". <td><html:text property="userName" size="16" /></td> </tr> <tr> <td>password</td> <td><html:text property="passWord" size="16" value="" /></td>
Hey... It's working fine by changing to userName and passWord. Any idea why it is so?? Anyway thanks a lot...3 days i was behind this problem Cheers Prasad
Adam Hardy
Ranch Hand
Joined: Oct 09, 2001
Posts: 563
posted
0
The reason is that application servers are totally case-sensitive and also have to conform to Sun�s JavaBean specification. So when the application server reads a JSP and sees a reference to a property on a bean, it will capitalize the first letter of the property name and append �get� or �set� to the front: <html:text property="passWord" size="16" value="" /> myBean.getPassWord() myBean.setPassWord() Now you capitalized the first letter of the property in your HTML tag. That's not meant to be. The effect is probably undefined by the Javabean specification. Adam
Dolly Patel
Greenhorn
Joined: Nov 25, 2002
Posts: 4
posted
0
Hi, I keep getting this error. No getter method for property username of bean org.apache.struts.taglib.html.Bean I did read all the comments on Case sensitive name and have made sure that i follow the rules. But i still get the same error. Here is my clip of code. Please help. I have spend enuf time on this and cant think of anything else. //************ Java Bean public final class WizSearchForm extends ActionForm { private String action = "WizardSearch"; private String username = null; public String getAction() { return (this.action); } public void setAction(String action) { this.action = action; } public String getUsername() { return (this.username); } public void setUsername(String username) { this.username = username; } // ************ JSP Form <td align="right"> <bean:message key="prompt.username"/> </td> <td><html:text property="username" size="16" /></td>
ravi janap
Ranch Hand
Joined: Nov 04, 2000
Posts: 389
posted
0
Hi Dolly Your code looks absolutely fine to me. Just change this part of code from
to
and check your declaration of the corresponding phrase i.e 'prompt.name' in resource.properties file . Thanks Ravindra
SCJP, SCJD, SCWCD, SCBCD, SCEA
Ganga Prasad
Greenhorn
Joined: Apr 09, 2003
Posts: 1
posted
0
Hi all, I have simmilar problem but it is when I am using Vector. my jsp & form bean is like this: //jsp <logic:iterate id="itemDesc" name="farmPermitForm" property="itemDetails"> <table> <TD> <html:text name="itemDesc" property="qty" styleClass="inputtxt" size="10" maxlength="5" > <bean:write name="itemDesc" property="qty" /> </html:text> </TD> <TD> <html:text name="itemDesc" property="fa_type" styleClass="inputtxt" size="30" maxlength="30" > <bean:write name="itemDesc" property="fa_type" /> </html:text> </TD> <TD> <html:text name="itemDesc" property="calibre" styleClass="inputtxt" size="30" maxlength="30"> <bean:write name="itemDesc" property="calibre" /> </html:text> </TD> <TD> <html:text name="itemDesc" property="barrel" styleClass="inputtxt" size="10" maxlength="10" > <bean:write name="itemDesc" property="barrel" /> </html:text> </TD> <TD> <html:text name="itemDesc" property="overall" styleClass="inputtxt" size="10" maxlength="10" > <bean:write name="itemDesc" property="overall" /> </html:text> </TD> <TD> <html:text name="itemDesc" property="serial_no" styleClass="inputtxt" size="30" maxlength="30" > <bean:write name="itemDesc" property="serial_no" /> </html:text> </TD>
</logic:iterate> </TABLE> // // form bean is : import java.util.Vector; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; private Vector itemDetails = null; public class farmPermitForm extends ActionForm { /** * Returns the itemDetails. * @return Vector */ public Vector getItemDetails() { return itemDetails; } /** * Sets the itemDetails. * @param itemDetails The itemDetails to set */ public void setItemDetails(Vector itemDetails) { this.itemDetails = itemDetails; } /** * Constructor */ public FarmPermitForm() { itemDetails = new Vector();
} public void reset(ActionMapping mapping, HttpServletRequest request) { // Reset values are provided as samples only. Change as appropriate. /*String submitValue = request.getParameter("actionvalue"); System.out.println("ACTION VALUE "+submitValue); if(submitValue.endsWith("A")) {
}*/ itemDetails.add(new FAitemDetails()); } public ActionErrors validate( ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); // Validate the fields in your form, adding // adding each error to this.errors as found, e.g. // if ((field == null) || (field.length() == 0)) { // errors.add("field", new ActionError("error.field.required")); // } return errors; }
} /// and the error is like this: WebGroup E SRVE0026E: [Servlet Error]-[No getter method for property itemDetails of bean farmPermitForm]: javax.servlet.jsp.JspException: No getter method for property itemDetails of bean farmPermitForm CAN ANY ONE HELP ME WITH THIS PROBLEM..... THANKS...
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Dolly, check your struts.config to make sure you are running the right form.
Mike Aron
Greenhorn
Joined: May 29, 2003
Posts: 3
posted
0
This seems to be a common problem... form bean: public class HVACListFormBean extends ActionForm implements Serializable private Vector hvaclist = null; public Vector getHvaclist() { return hvaclist; } JSP: <logic:iterate id="appliance" indexId="theIndex" name="hvacListForm" property="hvaclist"> <bean:write name="appliance" property='<%="cdBus["+ theIndex + "]"%>'/> </logic:iterate> Error Message: No getter method for property hvaclist of bean hvacListForm Thanks
Mete Kural
Greenhorn
Joined: Aug 28, 2003
Posts: 5
posted
0
Hello, I have the same exact problem now and I was wondering if any of you ever got around to fixing that problem. Do you have any suggestions on what is the source of the problem? Thanks much, Mete
Junilu Lacar
Ranch Hand
Joined: Feb 26, 2001
Posts: 3008
posted
0
Here's what you should post to help find the problem: From struts-config.xml: - the relevant form definition - the relevant action mapping Java code: - relevant snippets from your ActionForm JSP: - relevant snippets, including the <html:form> tag Cut and paste the stacktrace too.
Thank God I could fix the problem by changing the name of the form bean. For some reason the older version of the form bean was getting cached somewhere in the application (I don't know how that could possibly happen, I have no explanations). When I changed the form bean's name, I could add new properties and the jsp page found the getters for those properties. So now it works. I hope this may be helpful for any other who may be having the same problem. All praise be to God! Mete
Mete Kural
Greenhorn
Joined: Aug 28, 2003
Posts: 5
posted
0
Hello again, Figured out why my problem occurs. It's because somewhere down the line in the request handling, I overwrite the default form bean that is specified in struts-config.xml by another bean that I save in the request scope under the same attribute name, therefore any changes that I made to struts-config.xml did not affect the bean that was in the request scope during the JSP processing. Changing the name of the form bean fixed the problem because the bean that I was saving to the request scope was no more overwriting the default form bean that is specified in struts-config.xml. I had been pondering over this problem over several weeks. Thank God now it is completely resolved. -Mete
Bruce Zhang
Greenhorn
Joined: Sep 29, 2003
Posts: 3
posted
0
Hi Mete, this problem bugs me a long time. Thank you for your infomation. But I didn't quite follow you. What form bean is the default form bean? How did you solve this problem? Could you give us specific instructions on this? I believe a lot people are having this problem. Thanks! Bruce
Mete Kural
Greenhorn
Joined: Aug 28, 2003
Posts: 5
posted
0
Hi Bruce, By default form bean, I mean the form bean that I specified for that action-mapping in struts-config.xml by setting the name property of the action mapping element to point to the form-bean that I specified under form-beans in struts-config.xml. What I realized was that in my action class I was manually setting another bean in the request scope with the same name as the name I gave to my form-bean in struts-config.xml. So my form bean specified in struts-config was being overwritten by the other bean that I set in the request scope in my action class. For that reason, any changes that I made to my bean specified in struts-config was not being reflected to my JSP page. That is why when I was trying to access new bean properties that I have added in my JSP page I was getting no getter errors, since those new properties are not reflected to the JSP page. I suggest that you check your action classes to make sure you are not overwriting your bean with another bean before it gets to the JSP page. Please don't hesitate to ask more questions. May God help you, Mete
Bruce Zhang
Greenhorn
Joined: Sep 29, 2003
Posts: 3
posted
0
Thank you Mete for your fast response. After I posted my question, I solved my NO GETTER problem too. But ridiculously, I forgot how I solved it. I remember I only changed the form name in the struts-config.xml, cleared brower cache, and the problem is gone now. I didn't change the code in the action class. How did you manually set another bean in the request scope with the same name as the name you gave to your form-bean in struts-config.xml? Could you please paste the code for that portion here? Thanks Mete. -Bruce [ September 29, 2003: Message edited by: Bruce Zhang ]
Mete Kural
Greenhorn
Joined: Aug 28, 2003
Posts: 5
posted
0
I'm happy for you that you were able to fix it. That problem took some of my time too. >How did you manually set another bean in the request scope with the same name as the name you gave to your form-bean in struts-config.xml? Could you please paste the code for that portion here? request.setAttribute("registrationForm" registerationBean); where "registrationForm" is the same as the name property of the form-bean element. -Mete
Bruce Zhang
Greenhorn
Joined: Sep 29, 2003
Posts: 3
posted
0
Hi Mete, It seems that this problem can show up because many causes. I never used "request.setAttribute("registrationForm" registerationBean);", but still I got the same problem. The good news for me is that the problem is gone for now. But I think it will come back for a visit someday. Who knows. Thanks. -Bruce
Boniface Kabaso
Greenhorn
Joined: Jun 30, 2003
Posts: 5
posted
0
Just another addition to the many already excellent solutions to go round this problem. I just found out that leaving white space at the end of your attributes in the JSP page will cause this error as well.
Hope that helps somebody.
Boniface
Archanaa Panchal
Greenhorn
Joined: Sep 22, 2004
Posts: 7
posted
0
hey guys,
thanks for all the help - it did a great job helping me figure out why i was getting the same error msg.
here's also what helped - i realized that i had a missing <br> tag in my JSP file between another set of radio buttons right above the new ones i'd added.
once i put in this simple tag, it worked like a dream.
Murtuza Akhtari
Ranch Hand
Joined: Aug 07, 2004
Posts: 108
posted
0
I thought the case sensitivity worked only for the first letter. I guess I was wrong. I had a attribute called "qAError" with its appropriate getter/setter viz getQAError() and setQAError()
However i kept getting the same error: No getter blah blah blah Then I just changed my attribute name to "qaError" Now my getter/setter looked like getQaError() and setQaError() Everything seems to be working fine now !!!
forget the first letter....it also wants proper case for the second letter
Rule of thumb: define attributes with 1st 2(atleast) letters lower-case.
---<br />SCJP 1.4
Phred Phrank
Greenhorn
Joined: Jun 28, 2005
Posts: 1
posted
0
I was having this problem with an attribute on the bean called "inProcess", with getter getInProcess(). I changed the name of the attribute to "interrupted", with getter getInterrupted(), and it works.
So, try using a one-word attribute name if you get this error.
vijaya bharath
Ranch Hand
Joined: Jun 10, 2005
Posts: 66
posted
0
Hi,
According to java naming conventions all the variable names and property names shud start with lower letter and the firstletter of the words following shud start with capital letter. So if we follow this we wont get such problem. Coming to beans it creates getter and setter methods by changing the first letter of the property name as capital letter. ex for firstName it creates getFirstName and setFirstName. Here all the letters are lower letters except the first letter from the second word. Here the second word is name so property name as firstName.
Form code has Object getMeasures(int index) Object[] getMeasures() void setMeasures(Object[] array) void setMessuares(int index, Object value)
The code works fine in WSAD or Websphere 5.0.1.2
The server m/c 's JDK version is 1.3, and using Websphere server 5.0.2
Their is no error in console log. the jsp page is processed and forwarded perfectly But Error on JSP page. ServletException in selctcall.do }No getter method for property measures of bean timeseriesForm
Here measure is an arraylist containing Formbean value objects.
Can any one give any suggestions
Juergen Schmitt
Greenhorn
Joined: Aug 10, 2005
Posts: 1
posted
0
Hi, i had the same problem and found out, that its not enough, when the property name start only with one lower letter.
A property name like "bVarName" failed in my application. After correcting it to two lower letters "baVarName" it worked.
Thats strange to me but who cares. Now it runs.
Pramodh Rachakatla
Greenhorn
Joined: Nov 23, 2005
Posts: 1
posted
0
I changed property name to lowercase ex: phonenumber and added get/set method as getPhonenumber and setPhonenumber in my Bean and it works.
I hope this information is helpful.
Cendy Nguvy
Ranch Hand
Joined: May 25, 2005
Posts: 37
posted
0
Originally posted by Juergen Schmitt: Hi, i had the same problem and found out, that its not enough, when the property name start only with one lower letter.
A property name like "bVarName" failed in my application. After correcting it to two lower letters "baVarName" it worked.
Thats strange to me but who cares. Now it runs.
It doesn't work when the property name start only with one lower letter, like your property "bVarName", because one letter can't be consider as a word.
For Dolly Patel, its property is username. In order to follow the rules, she has to change username in userName, because there is two words.
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
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,
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.
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
R Diaz
Greenhorn
Joined: Jun 24, 2008
Posts: 15
posted
0
Hi Everyone,
I'm new working with Struts and also got this "No getter method for property error." Sorry to post the code, but I'm hoping that someone could tell me what I'm doing wrong. I haven't been able to figure this out and it's not like what was previously mentioned.
<html> <head> <title>Show book list</title> </head> <body> <table border="1"> <tbody> <%-- set the header --%> <tr> <td>Author</td> <td>Book name</td> <td>Available</td> <td> </td> <td> </td> </tr> <%-- check if book exists and display message or iterate over books --%> <logic:empty name="bookListForm" property="books"> <tr> <td colspan="5">No books available</td> </tr> </logic:empty> <logic:notEmpty name="bookListForm" property="books"> <logic:iterate name="bookListForm" property="books" id="book"> <tr> <%-- print out the book information --%> <td><bean:write name="book" property="author" /></td> <td><bean:write name="book" property="title" /></td> <td><html:checkbox disabled="true" name="book" property="available" /> </td>
<%-- print out the edit and delete link for each book --%> <td><html:link action="bookEdit.do?do=editBook" paramName="book" paramProperty="id" paramId="id">Edit</html:link></td> <td><html:link action="bookEdit.do?do=deleteBook" paramName="book" paramProperty="id" paramId="id">Delete</html:link></td> </tr> </logic:iterate> </logic:notEmpty>
<%-- print out the add link --%> <tr> <td colspan="5"><html:link action="bookEdit.do?do=addBook">Add a new book</html:link> </td> </tr>
Sorry for posting the code. Thanks in advance for any help.
Best regards,
Rudi
subhas sing
Greenhorn
Joined: Sep 11, 2008
Posts: 1
posted
0
Hi Everyone, I also got this same error, "No getter method for property error." when I deploy my Struts 1 application in WebSphere 6.1 but same code works fine with WebSphere 5.1 server. I don't know how to resolve this issuejavascript:%20x(). Any help will be appreciated.
Form Bean ======= public class TestForm extends ActionForm implements Serializable {
String actionFlag = null; public String getActionFlag() { return actionFlag; } public void setActionFlag(String actionFlag) { this.actionFlag = actionFlag; }
//The following methods for dynamically populate public List getMileageDetails() { return mileageDetails; } // non-bean version so as not to confuse struts. public void populateMileageDetails(List skills) { mileageDetails.clear(); this.mileageDetails.addAll(skills); } public void setMileageDetails(UpdateRowBean skill) { this.mileageDetails.add(skill); } public UpdateRowBean getMileageDetails(int index) { // automatically grow List size while (index >= mileageDetails.size()) { mileageDetails.add(new UpdateRowBean()); } return (UpdateRowBean)mileageDetails.get(index);
} }
Action ========= public class TestAction extends Action{
if (actionFlag != null && actionFlag.equalsIgnoreCase("send")){ System.out.println(".....hello...."+testForm.getMileageDetails()); testForm.setActionFlag(null); }else{ List temp = new ArrayList(); for(int i=0;i<10;i++){
UpdateRowBean te = new UpdateRowBean(); te.setJuris("AL"+i); te.setSupNbr((short)i++); te.setMileage(i*345); te.setMileageType("N"); te.setMonth(i); te.setYear(4); te.setPerc(0); temp.add(te); } testForm.populateMileageDetails(temp); }
return aMapping.getInputForward();
} }
UpdateRowBean ============================ public class UpdateRowBean { String delFg; String juris; long mileage; String mileageType; int month; int year; double perc;
short supNbr=-1; String payCheckNbr; String payCheckM;
public void setEid(String eid) {
this.eid = eid;
}
}
this is my code, i have added a getter and setter, but still the problem.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Without more information it'll be difficult to help. How are you putting the bean into scope? How are you trying to access the bean?
Please UseCodeTags, and in the future, start a new thread rather than appending on to an old one.
Saravanan Mrajan
Greenhorn
Joined: Jun 28, 2009
Posts: 18
posted
0
David Newton wrote:Without more information it'll be difficult to help. How are you putting the bean into scope? How are you trying to access the bean?
Please UseCodeTags, and in the future, start a new thread rather than appending on to an old one.
struts-config
ProcesssimpleAction.java
i have given all my codes here. please help.
Thanks!!
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Not the JSP.
subject: Struts: No getter method for property name problem