wood burning stoves 2.0*
The moose likes Struts and the fly likes html:select tag - problem in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:select tag - problem in struts" Watch "html:select tag - problem in struts" New topic
Author

html:select tag - problem in struts

Kevin McLeod
Greenhorn

Joined: Jan 12, 2007
Posts: 2
Hello everyone-

Struts appears to be appending _# to the property name on my <html:select> tags which is causing "No getter method..." errors. The property name is defined in my Form, and the only Form items that cause an arror are the ones used in html:select tags.

Have any of you ever run into this? Any solutions you used? Thanks! My SELECT code and the error messages are below.

<c:forEach var="liabilities" items="${scenarioForm.liabilities}" varStatus="status">
<html:select property="originalLender" name="liabilities" indexed="true" >
</c:choose>
<c:when test="${scenarioForm.leadChannel == '2'}">
<html ptions collection="ORIGINALLENDERADDCORR" property="value" labelProperty="label" >
</c:when>
<c therwise>
<html ptions collection="ORIGINALLENDER" property="value" labelProperty="label" >
</c therwise>
</c:choose>
</html:select>



ERROR 12:26:06 [http-8080-Processor23] [com.dfc.struts.framework.JSHelper] - No getter method for property originalLender_0 of bean liabilities
javax.servlet.jsp.JspException: No getter method for property originalLender_0 of bean liabilities
ERROR 12:26:06 [http-8080-Processor23] [com.dfc.struts.framework.JSHelper] - No getter method for property originalLender_1 of bean liabilities
javax.servlet.jsp.JspException: No getter method for property originalLender_1 of bean liabilities
ERROR 12:26:06 [http-8080-Processor23] [com.dfc.struts.framework.JSHelper] - No getter method for property originalLender_2 of bean liabilities
javax.servlet.jsp.JspException: No getter method for property originalLender_2 of bean liabilities
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
First off I notice that the code that you posted has "</c:choose>" where it should be "<c:choose>".

It is hard to say what the cause of the error is without knowing more about your action form. Does your form have a method like getLiabilities(int i)?

- Brent
Kevin McLeod
Greenhorn

Joined: Jan 12, 2007
Posts: 2
Thanks for the reply! Yes, the following methods exist within the actionForm. All of the form's variables are being accessed and rendered properly by the jsp - even the field responsible for the error message. It is only the property of the <html:select> tag that is getting that _number appended, and I haven't been able to figure out why...


private List liabilities;
public List getLiabilities() {
return liabilities;
}
the class is initialized as follows:
liabilities = new FormList(ScenarioLiabilityDetailForm.class);

and here is part of the class containing the individual data items:
public class ScenarioLiabilityDetailForm extends BaseActionForm {
private String originalLender;
private String UPB;
private String UPBPD;
private String rentalWash;
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you specify indexed="true" on a Struts tag, you must provide an indexed getter to go with it. In addition to this, a requirement that is not well documented is that the name given to the "var" attribute of your <c:forEach> tag must match the name of this indexed getter. Due to the fact that ActionForms don't handle overloaded methods very well, that name also needs to be different from the name given to the getter for the collection.

Given the above, I'd suggest creating the following getter in your ActionForm.



Then change your jsp to:



Note: The ability to embed an indexed property in a <c:forEach> stanza was added with version 1.2 of struts, so this will only work if you are using version 1.2 or above. Otherwise, you must use a <logic:iterate> tag.
[ January 16, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:select tag - problem in struts
 
Similar Threads
Validation of Html options
&lt;html:options&gt; and ActionForms
struts - logic:iterator used with html:select
Having trouble with options Collection
Help on Drop Down