aspose file tools*
The moose likes Struts and the fly likes Blank page returned from ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Blank page returned from ActionForm" Watch "Blank page returned from ActionForm" New topic
Author

Blank page returned from ActionForm

Andy Lucian
Greenhorn

Joined: May 25, 2005
Posts: 1
Hello All,

I'm an experienced Java programmer new to Struts. I have to say so far I'm finding it very frustrating.

My problem is that I get a blank page returned from an ActionForm derived class when I click the associated form's submit button, and secondly that no errors are displayed by the <html:errors/> tag. I have hardcoded an error message in validate, but it isn't displayed.

I *know* validate is called because when I click the form's cancel button, Tomcat correctly finds and performs the forward to an error page - this behaviour is just for testing. Ohh and as if that wasn't enough can't seem to get Log4j to log, but that's secondary for now.

I'm sure this is probably just a case of not having read enough documentation...


From struts-config.xml (relevant tags only) :

<!-- Logon form -->
<form-bean name="LogonForm" type="template.form.LogonForm"/>

<!-- Process a user logon -->
<action path="/SubmitLogonForm"
type="template.action.LogonAction"
name="LogonForm"
scope="request"
input="/logon.jsp">
<forward name="failure" path="/error.jsp" />
<forward name="success" path="/welcome.jsp" />
</action>

Class template.form.LogonForm :


public class LogonForm extends ActionForm {


private String username;
private String password;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
// initial values of form fields
username = null;
password = null;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {

ActionErrors errors = new ActionErrors();
errors.add("password",new ActionMessage("logon.form.password.invalid")); // TESTING ONLY
// validate on submit
if (FormUtils.isNullOrEmpty(httpServletRequest.getParameter("username"))) {
errors.add("ERRORS",new ActionMessage("logon.form.username.invalid"));
}
if (FormUtils.isNullOrEmpty(httpServletRequest.getParameter("password"))) {
errors.add("ERRORS",new ActionMessage("logon.form.password.invalid"));
}

return errors;
}
}

JSP logon.jsp :


<html:errors/>
<html:form action="/SubmitLogonForm">
<table>
<tr>
<td>Username</td>
<td><html:text property="username"/></td>
</tr>
<tr>
<td>Password</td>
<td><html:text property="password"/></td>
</tr>
<tr>
<td>
<html:submit/> <html:cancel/>
</td>
<td></td>
</tr>
</table>
</html:form>

From Action derived class :

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
log.trace("Enter");
if (isCancelled(request)) {
log.debug("Cancel pressed");
return mapping.findForward(Constants.FAILURE);
}

LogonForm logonForm = (LogonForm)form;
log.debug("username "+logonForm.getUsername());
log.debug("password "+logonForm.getPassword());

return mapping.findForward(Constants.SUCCESS);
}


Thanks for any ideas ...

Andy.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
when you get a blank page, it means the target is not found (Constants.SUCCESS) in the action-mapping forward. double check your Constants.SUCCESS value. do a println.out of the Constants.SUCCESS in your .execute() before return findForward. you need to resolve the target issue first before addressing the errors not being printed out.

you need to add validate="true" to your action mapping. this tells the struts to validate the form. also, if you are adding error messages inside your action, you need to call saveMessages(request,messages); before returning the forward.

also, what version of struts are you using? ActionErrors are deprecated in 1.2.x. you may want to look at the declarative validation (based on XML file) instead of using the old struts 1.0 validate(). also, instead of creating beans, try configure the bean using form-bean definitions. i suggested these because you are just starting out. it's best to stay away from deprecated features and 'way of programming'.
[ May 25, 2005: Message edited by: alan do ]

-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blank page returned from ActionForm