I am unable to find out what I am doing wrong.
I get this error:
javax.servlet.jsp.JspException: No getter method for property: "firstname" of bean: "org.apache.struts.validator.DynaValidatorForm"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:915)
at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:126)
at org.apache.struts.taglib.html.BaseFieldTag.renderInputElement(BaseFieldTag.java:102)
at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:80)
at org.apache.jsp.login_jsp._jspx_meth_html_005ftext_005f1(login_jsp.java:1095)
at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f1(login_jsp.java:1040)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:759)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
in the struts-config.xml file the tage is used:
<form-bean name="sendContactForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="firstname" type="java.lang.String" initial="firstname"/>
<form-property name="lastname" type="java.lang.String" initial="lastname"/>
<form-property name="emailaddress" type="java.lang.String" initial="email"/>
<form-property name="subject" type="java.lang.String" initial="subject"/>
<form-property name="comments" type="java.lang.String" initial="comments"/>
</form-bean>
and also:
<action path="/sendContactForm" attribute="sendContactForm" input="/login.jsp"
name="sendContactForm" scope="request" parameter="reqCode"
type="org.springframework.web.struts.DelegatingActionProxy" validate="true">
<forward name="sendcontacts" path="/login.jsp"/>
</action>
in Actionform I have:
public class ContactAction extends DynaValidatorActionForm {
private static Logger log = Logger.getLogger(ContactAction.class);
public ActionForward sendContactForm(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse resp) throws Exception {
log.debug("ContactForm--start");
DynaValidatorActionForm sendContactForm = (DynaValidatorActionForm) form;
ActionMessages messages = new ActionMessages();
String firstName = ((String) sendContactForm.get("firstname"));
String lastName = ((String) sendContactForm.get("lastname"));
String emailAddress = ((String) sendContactForm.get("emailaddress"));
String subject = ((String) sendContactForm.get("subject"));
String comments = ((String) sendContactForm.get("comments"));
return mapping.findForward("sendcontacts");
In the jsp file I have:
<html:form action="/sendContactForm.do?ContactCd=sendContactForm" method="post" styleId="sendContactForm">
<c:set var="sendContactForm" value="${sendContactForm}" />
<html:errors/>
<label for="firstname">First Name <span class="asterisk">*</span>
</label>
<html:text styleId="firstname" property="firstname" styleClass="form-control tip required" name="sendContactForm" />
<label for="lastname">Last Name <span class="asterisk">*</span>
</label>
<html:text styleId="lastname" property="lastname" styleClass="form-control tip pplaceholder" name="sendContactForm"/>
<label for="emailaddress">Email Address <span class="asterisk">*</span>
</label>
<html:text styleId="emailaddress" property="emailaddress" styleClass="form-control tip pplaceholder" name="sendContactForm" />
<label for="subject">Subject <span class="asterisk">*</span>
</label>
<html:text styleId="subject" property="subject" styleClass="form-control tip pplaceholder" name="sendContactForm"/>
<label for="comments">Comments <span class="asterisk">*</span>
</label>
<html:textarea styleId="comments" property="comments" styleClass="form-control tip pplaceholder" name="sendContactForm"></html:textarea>
</html:form>
I have researched a lot but wasn't success yet.
So, what's wrong? Thank you.
I am shooting in the dark here(don't have much idea of struts) but seems like you are calling getter function[((String) sendContactForm.get("firstname"));] from some bean and it is giving error no getter function. So have you created getter function for "firstname"?
Ok. Got your problem.
Try this.
Instead of using "String firstName = ((String) sendContactForm.get("firstname"));"
Use this
String firstName = req.getParameter("firstName"));
This will solve your issue. Try it.
I am not very much used to
DynaActionForms
, always usedActionForm
.Just out of curiosity, does it work if you change
firstname
tofirstName
in form definition and all other places you are referring it?Major UPDATE:
I tried out your code with the changes I mentioned here, and the login page with all those five fields are getting displayed with their default initial values that were given in form-bean definition. There are no errors in displaying the page.
Another thing to note here is that your login.jsp has no submit button and you are not all submitting the form, so the control never comes inside your action class.
This is the login.jsp
The jars used are
struts-taglib-1.3.10.jar,struts-core-1.3.10.jar,jstl-1.2.jar,commons-validator-1.3.1.jar, commons-logging-1.0.4.jar,commons-digester-1.8.jar,commons-chain-1.2.jar,commons-beanutils-1.8.0.jar,antlr-2.7.2.jar
The following tld's are put inside my
WEB-INF
struts-bean.tld, struts-html.tld,struts-logic.tld
If you have any validation,
validation.xml
may also be present in WEB-INFContactAction.java [in your current case, control does not come here]
Previous edits Usage of
sendContactForm.get("firstname")
is correct, as you are usingDynaValidatorForm
.The error is that your action class is extending the wrong class.
This is wrong. You need to extend the
Action
class ie:Also, instead of
use
Update: In your action class,
what is this method name -
sendContactForm
? Is there any reason for this?Why don't you change it to
public ActionForward execute