David Pizon

Greenhorn
+ Follow
since Oct 03, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Pizon

Hooookay...

First of all I would like to give a great deal of thanks to Merrill Higginson for your support.

Since I did not override the Form class reset() method I do not know how the page integer was getting reset. I added the following code to my Form class to make sure the parent reset() method wasn't doing anything sneaky:

<snip>
public void reset() {
}
</snip>

No joy.

Lastly I created a private integer "stage" with appropriate gets and sets. If I use getStage() instead of getPage() everything works the way it should.

It's a pity that I'm not understanding the proper use of the "page" integer since upon first glance it seems to be exactly what I am after.



If anyone has any pointers on how exactly the "page" integer should properly be used, I'd be happy to hear from you.

Until then... don't squat with your spurs on.
15 years ago
Moving to the next page *should* be handled by the following code:

<snip>
// Perform our custom validation method on our form
ActionMessages actionMessages = registrationForm.validateRegisterForm(mapping, request);
this.saveErrors(request, actionMessages);

// If there were no errors -- move to the next page
if (actionMessages.isEmpty()) page++;
registrationForm.setPage(page);
</snip>

Validation is done from within the Action class (by calling the custom validateRegisterForm() method in the Form object). If the returned actionMessages object is empty, the page number gets increased and set before feeding into the switch statement which sends the user on thier way.

The problem appears to be that the registrationForm.setPage() calls do not actually store the page value to the Form object in the session.

Upon entering the Action class execute() method, registrationForm.getPage() always returns 0.
15 years ago
2

I will never regret leaving standard JSP. There was too much room for sloppy habits.
15 years ago
Are you using struts tags or generic <input> tags?
15 years ago
<%@ page language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"; prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"; prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"; prefix="logic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">;
<html:html xhtml="true" locale="true">
<head>
<html:base />
<title>Sample form</title>
</head>
<body>
<html:form action="/Sample">
<%-- input field for properties --%>
<p>Sample field: <html:text property="field1" /></p>
<p>Sample field: <html:text property="field2" /></p>
<html:submit property="submit" value="submit" />
</html:form>
</body>
</html:html>
15 years ago
/*
* Created on Jul 11, 2005
*
* TODO Figure out why setPage() does not change the page number past this instance of the execute() method
* registrationForm.getPage() always returns 0
*/
package com.campushousingguide.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.campushousingguide.form.RegistrationForm;

/**
* @author David Pizon
*/
public class RegistrationAction extends Action {

// Local Forwards
public static final String FORWARD_page1 = "page1";
public static final String FORWARD_page2 = "page2";
public static final String FORWARD_page3 = "finish";

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String forward = FORWARD_page1;
int page = 0;

// Retrieve the registration form
RegistrationForm registrationForm = (RegistrationForm)form;
page = registrationForm.getPage();

System.out.println("Why is this value always 0?");
System.out.println(new Integer(registrationForm.getPage()).toString());

// Check to see if the user clicked on the "back" button
if (request.getParameter("back") != null) {
switch(page) {
case 0: break;
case 1:
page = 0;
forward = FORWARD_page1;
break;
case 2:
page = 1;
forward = FORWARD_page2;
break;
default: break;
}
registrationForm.setPage(page);
return mapping.findForward(forward);
}

// Perform our custom validation method on our form
ActionMessages actionMessages = registrationForm.validateRegisterForm(mapping, request);
this.saveErrors(request, actionMessages);

// If there were no errors -- move to the next page
if (actionMessages.isEmpty()) page++;
registrationForm.setPage(page);

System.out.println(new Integer(registrationForm.getPage()).toString());
System.out.println("The page value has been set but will default to back to zero when we next run this method");

// Send the user to whichever page they should go to
switch(page) {
// Move to the next page
case 0:
forward = FORWARD_page1;
break;
case 1:
forward = FORWARD_page2;
break;
case 2:
// The form is completed
// Perform whatever database stuff we need to here
forward = FORWARD_page3;
break;
default: break;
}
return mapping.findForward(forward);
}
}
[ July 29, 2005: Message edited by: David Pizon ]
15 years ago
That would seem perfectly logical and I would love to do it that way. However, for some unknown reason page-to-page flow does not work properly.

Clicking on the "next" button on the first page will validate and send the user to the second page. Clicking on the "next" button on the second page validates the first page (known to be valid) and re-sends the user to the second page.

The Form "page" int is apparently not getting changed. Am I not setting it correctly?
15 years ago
Howdy, Ranchers!

I'm working on the mulit-page user registration portion of a small web application.

What I have so far (hope to improve):

I do not override the Form class reset() method. As the controller moves from page to page, all of the old form information still exists within the form object. At the final page, I remove the form object from the session.

Also, I do not override the Form class validate() method. The controller flows to the Action class. Within the execute() method of the Action class I call a custom validation method in the form object, check to see if errors were returned (actionMessages.isEmpty()), and return the appropriate ActionForward.

Right now each page contains a page value as a hidden field to determine which fields to validate for the given stage.
<html:hidden property="page" value="1"/>
<html:hidden property="page" value="2"/>
<html:hidden property="page" value="3"/> ... and so on ...

The controller takes this hidden field and performs the setPage() method (inherited from the ValidatorForm class).

I would like to avoid passing hidden fields because I worry about users faking requests to the web application (savvy users forming a request with a different page value) and tricking the web application into skipping right to the confirmation stage.

I've tried coding the JSP pages to pull the form object from the session, perform the setPage() method, and re-stuffing the object into the session. For some reason the Form's "page" integer remains 0 when I do this.

Does anyone else have any suggestions?

[ July 28, 2005: Message edited by: David Pizon ]

[ July 28, 2005: Message edited by: David Pizon ]
[ July 28, 2005: Message edited by: David Pizon ]
15 years ago
"add an ActionError/ActionMessage from the Action"

Right... how do I do that?

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;

I want to keep authentication in the LoginAction separate from validation in the LoginForm. Can I stuff an ActionErrors() object in an ActionForward() object?
15 years ago
I am a Struts newbie attempting to write a login app.

Most (if not all) of the examples I have found online use three JSP pages:

login.jsp (prompts user for username/password, re-displays if invalid)
fail.jsp (username/password valid but incorrect)
success.jsp (username/password was correct)



I would like to change my app to have use only two JSP pages:

login.jsp (prompts user for username/password, re-displays if invalid, re-displays if incorrect)
success.jsp (username/password was correct)

I have an Action which validates user input and, if valid, invokes a bean to authenticate the user.

I presume I need three findForwards in my Action:
return (mapping.findForward(this.FORWARD_invalid));
return (mapping.findForward(this.FORWARD_incorrect));
return (mapping.findForward(this.FORWARD_success));

How do I let the login.jsp page know which error condition to display ("invalid field", "could not authenticate", or no error)?

Am I on the right track?
15 years ago