This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run a very simple struts application I get the following error message:
[ServletException in:/pages/Name.jsp] No getter method for property firstName of bean org.apache.struts.taglib.html.BEAN'

The property fields in the beans have the correct case.
Bean:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import java.util.*;

public class NameActionForm extends ActionForm {

private String firstName = "";
private String lastName = "";
private String initial = "";


public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getInitial() {
return initial;
}

public void setFirstName(String name) {
firstName = name;
}

public void setLastName(String name) {
lastName = name;
}

public void setInitial(String init) {
initial = init;
}
}

struts-config (parts of it)

<form-beans>
<form-bean
name="addresses"
type="AddressActionForm"/>

<form-bean
name="names"
type="NameActionForm"/>
</form-beans>

<global-forwards>
<forward
name="name"
path="/Name.do" />
</global-forwards>

jsp page (Name.jsp)
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>



<html:form action="/Addresses">
<table>
<tr>
<th>
First Name:
</th>
<th>
Last Name:
</th>
<th>
Initial
</th>
</tr>
<tr>
<td>
<html:text property="firstName" size="20"/>
</td>
<td>
<html:text property="lastName" size="30"/>
</td>
<td>
<html:text property="initial" size="1"/>
</td>
</tr>
</table>
<html:submit
property="submit">Submit</html:submit>
</html:submit>

If I change the line
<html:form action="/Addresses"> to
<html:form name="names" type="NameActionForm" action="/Addresses">

It works fine. Any help would be appreciated.

</html:form>
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the ActionMapping look like in your struts-config.xml?
It should have a name attribute that references a defined form-bean.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Marc was alluding to, you need an action mapping for your app. Something like:

<!-- Names -->
<action path="/Name"
type="com.x.y.NameActionForm" <!-- defines action class -->
name="names" <!-- identifies form class (in form-bean) -->
scope="request" <!-- formbean in request scope -->
validate="true" <!-- If you're using validator -->
input="name.jsp"> <!-- return errors to this jsp -->
<!-- optional entries below -->
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
 
Jason Goodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant to put that in. The Action mapping looks like

<action-mappings>
<action
path="/Name"
type="org.apache.struts.actions.ForwardAction"
name="names"
scope="session"
parameter="namepage"/>
</action-mappings>

namepage goes to tiles_def.xml

Thanks again
 
Jason Goodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me as though the problem is in the struts-config, because putting the name="names" type="NameActionForm" into the html:form tag on the jsp gets rid of the problems. But I can't see any issues in the struts-config file.
Any thoughts?

Thanks again
 
Jason Goodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone see the problem with the code above?
Thanks
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
your html form code obiously calls the /addresses mapping and this uses the bean of adresses, which is probably another bean than the one that is attached to the /name mapping, the names bean that you want to use.
take a look at your adresses mapping in struts config.
regards,
 
Jason Goodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with the Name.jsp. There is no Bean method relating to fname. This jsp is linked in the Struts config.xml to the NameActionForm. This Bean has a get/setFname method.
The Struts-config looks like:
The acton mapping in strut-congif is:
<action
path="/Name"
type="org.apache.struts.actions.ForwardAction"
name="names"
scope="session"
parameter="namepage"/>


<action
path="/Addresses"
type="org.apache.struts.actions.ForwardAction"
name="addresses"
scope="session"
parameter="addresspage"/>

The /Name is attached to name=names. Since the Name.jsp needs the NameActionForm bean (since this holds the vars and methods for fname, lname and initial.
The Beans are defined in the struts-config as
<form-bean
name="addresses"
type="AddressActionForm"/>

<form-bean
name="names"
type="NameActionForm"/>

Any help would be appreciated.
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
The problem is indeed in Name.jsp. This jsp has a form action which invokes the /Addresses, which uses the action as below

<action
path="/Addresses"
type="org.apache.struts.actions.ForwardAction"
name="addresses"
scope="session"
parameter="addresspage"/>

Than that action uses 'addresses' - formbean which is
<form-bean
name="addresses"
type="AddressActionForm"/>

which does not have the right getters and setters

That's really all, you gave all the answers
 
Jason Goodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. The version I originally wrote had what you talked about. I made a copy to test some new features in struts and somewhere along the lines must have changed the action. I will make that fix. Sometimes a fresh pair of eyes a the best thing.

Thanks again.
 
    Bookmark Topic Watch Topic
  • New Topic