I am new to
JSP and
Struts development. I have a display only form that
I have mapped to an ActionForm and an ActionClass. The form is displayed
OK, but I don't get any data in it. It is just a standalone form and am
trying to set the values for the form fields using Action class.
I am posting code snippets here:
*******ActionForm*************
public class page14ActionForm extends ActionForm
{
private
String username;
private String name;
private String location;
public void setUsername(String username)
{
this.username = username;
}
public void setName(String name)
{
this.name = name;
}
...........
}
*******Action Class**********
public class page14Action extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
page14ActionForm aForm = (page14ActionForm)form;
String uname="John" ;
request.setAttribute("username",uname);
return(mapping.findForward("success")) ;
}
}
**** JSP PAGE (Posting only for one field) ******
<html:form action="page14" name="page14Form" type="page14ActionForm" >
<table id="pg14table1" align="center" width="343" cellpadding="2" cellspacing="2">
<tr align="center">
<td ><bean:message key="app.username" /></td>
<td>
<html:text property="username" readonly="true" />
<bean
efine id="username" name="page14Form" property="username" />
</td>
</tr>
******* STRUTS CONFIG************
<form-beans>
<form-bean name="page14Form" type="page14ActionForm" />
</form-beans>
<action-mappings>
<action path="/page14" type="page14Action"
name="page14Form" input="/common/page14.jsp" scope="request">
<forward name="success" path="/common/header.jsp" />
<forward name="failure" path="/common/footer.jsp" />
</action>
</action-mappings>
What am I missing here? I get a message cannot set null value. So looks like username is null, but why ?? I am setting it in ActionClass
.
Any help is greatly appreciated.
Thanks in advance for all the responses.