sorry for the typo, I meant it "DOESN't" go to the Help page when I click the submit button on the Input page.
On Wed, Jun 24, 2009 at 12:10 AM, Sam Wun<swun2...@gmail.com> wrote: > Dear all, > > I have a problem when I click a submit button of a page, it doesn't go > straight to the next desired page. > Here is my little project: > Firstly, I want to show you how it supposed to flow: > Input page -> Help page > > But the problem is it does go to the Help page when I click the submit > button on the Input page. > > Here are the source files: > > --- input.jsp: > ============================================ > # cat input.jsp > <%@ include file="/html/portlet/struts_redirect_portlet/init.jsp" %> > > <p align=centre> > Hello the INPUT page..... > </p> > <bean:define id="comment" name="RedirectForm" property="comment" > type="java.lang.String" /> > > <logic:messagesPresent> > <span class="es-error"> > <bean:message key="error.comment.invalid"/> > </span> > </logic:messagesPresent> > > <p align=centre> > <html:form action="/struts_redirect_portlet/input" method="post" > focus="comment"> > > <table class="stats"> > <tr> > <th><bean:message key="form.title.comment"/></th> > <th><html:text name="RedirectForm" property="comment" size="50" /></th> > </tr> > </table> > </p> > > <p align=left> > <html:submit><bean:message key="button.submit"/></html:submit> > </html:form> > </p> > > --- help.jsp: > ============================================= > > # cat help.jsp > <%@ include file="/html/portlet/struts_redirect_portlet/init.jsp" %> > > <p align=centre> > Hello the HelP FORM ??..... > </p> > <bean:define id="name" name="RedirectHelpForm" property="name" > type="java.lang.String" /> > > <logic:messagesPresent> > <span class="es-error"> > <bean:message key="error.name.invalid"/> > </span> > </logic:messagesPresent> > > <p align=centre> > <html:form action="/struts_redirect_portlet/help" method="post" focus="name"> > > <table class="stats"> > <tr> > <th><bean:message key="form.title.name"/></th> > <th><html:text name="RedirectHelpForm" property="name" size="50" /></th> > </tr> > </table> > </p> > > <p align=left> > <html:submit><bean:message key="button.submit"/></html:submit> > </html:form> > </p> > > -- RedirectAction.java: > ================================= > package com.ip6networks.struts_redirect.portlet; > > import com.ip6networks.struts_redirect.portlet.RedirectForm; > > import com.liferay.portal.struts.PortletAction; > > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > > import javax.portlet.ActionRequest; > import javax.portlet.ActionResponse; > import javax.portlet.PortletConfig; > import javax.portlet.RenderRequest; > import javax.portlet.RenderResponse; > > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > > /** @struts.action name="RedirectForm" path="/struts_redirect_portlet/input" > * scope="session" > * input="/portlet/struts_redirect_portlet/input.jsp" > * > * @struts.action-forward name="input" > path="/portlet/struts_redirect_portlet/input.jsp" redirect="true" > * @struts.action-forward name="help" > path="/portlet/struts_redirect_portlet/help.jsp" redirect="true" > */ > public class RedirectAction extends PortletAction { > > public ActionForward execute( > ActionMapping mapping, ActionForm form, > HttpServletRequest req, > HttpServletResponse res) > throws Exception { > > RedirectForm redirectForm = (RedirectForm) form; > > String comment = redirectForm.getComment().trim(); > if ( comment.length() > 0) { > return mapping.findForward("help"); > } > > return mapping.findForward("input"); > > } > > public ActionForward render( > ActionMapping mapping, ActionForm form, > PortletConfig config, > RenderRequest req, RenderResponse res) > throws Exception { > > return mapping.findForward("input"); > } > } > > --- RedirectForm.java > ================================= > # cat RedirectForm.java > package com.ip6networks.struts_redirect.portlet; > > import org.apache.struts.validator.ValidatorForm; > > import javax.servlet.http.HttpServletRequest; > > import org.apache.struts.action.ActionErrors; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.ActionMessage; > > /** > * @struts.form name="RedirectForm" > */ > public class RedirectForm extends ValidatorForm { > private String comment=""; > > public String getComment() {return this.comment;} > > /** > * @struts.validator type="required" msgkey="error.comment.required" > */ > public void setComment(String c) {this.comment = c;} > > public void reset(ActionMapping mapping, HttpServletRequest req) { > this.comment = ""; > } > > public ActionErrors validate(ActionMapping mapping, > HttpServletRequest req) { > > ActionErrors errors = new ActionErrors(); > try{ > if (this.comment == null || this.comment.length() < 1) > { > errors.add("comment", new > ActionMessage("error.comment.required")); > } > } > catch(NullPointerException npe){} > > return errors; > } > > } > > --- ReidrectHelpAction.java > ===================================== > # cat RedirectHelpAction.java > package com.ip6networks.struts_redirect.portlet; > > import com.liferay.portal.struts.PortletAction; > > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > > import javax.portlet.ActionRequest; > import javax.portlet.ActionResponse; > import javax.portlet.PortletConfig; > import javax.portlet.RenderRequest; > import javax.portlet.RenderResponse; > > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > > /** @struts.action name="RedirectHelpForm" > path="/struts_redirect_portlet/help" > * scope="session" > * input="/portlet/struts_redirect_portlet/help.jsp" > * > * @struts.action-forward name="help" > path="/portlet/struts_redirect_portlet/help.jsp" redirect="true" > */ > > public class RedirectHelpAction extends PortletAction { > > public ActionForward execute( > ActionMapping mapping, ActionForm form, > HttpServletRequest req, > HttpServletResponse res) > throws Exception { > > return mapping.findForward("help"); > } > > public ActionForward render( > ActionMapping mapping, ActionForm form, > PortletConfig config, > RenderRequest req, RenderResponse res) > throws Exception { > > return mapping.findForward("help"); > } > } > > --- RedirectHelpForm.java > ======================================= > # cat RedirectHelpForm.java > package com.ip6networks.struts_redirect.portlet; > > import org.apache.struts.validator.ValidatorForm; > > import javax.servlet.http.HttpServletRequest; > > import org.apache.struts.action.ActionErrors; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.ActionMessage; > > /** > * @struts.form name="RedirectHelpForm" > */ > public class RedirectHelpForm extends ValidatorForm { > private String name=""; > > public String getName() {return this.name;} > > /** > * @struts.validator type="required" msgkey="error.name.required" > */ > public void setName(String c) {this.name = c;} > > public void reset(ActionMapping mapping, HttpServletRequest req) { > this.name = ""; > } > > public ActionErrors validate(ActionMapping mapping, > HttpServletRequest req) { > > ActionErrors errors = new ActionErrors(); > try{ > if (this.name == null || this.name.length() < 1) > { > errors.add("name", new ActionMessage("error.name.required")); > } > } > catch(NullPointerException npe){} > > return errors; > } > > } > > --- struts-config.xml: > ==================================== > <action-mappings> > <action > path="/struts_redirect_portlet/input" > type="com.ip6networks.struts_redirect.portlet.RedirectAction" > name="RedirectForm" > scope="session" > input="/portlet/struts_redirect_portlet/input.jsp" > unknown="false" > validate="true" > > > <forward > name="input" > path="/portlet/struts_redirect_portlet/input.jsp" > redirect="true" > /> > <forward > name="help" > path="/portlet/struts_redirect_portlet/help.jsp" > redirect="true" > /> > </action> > <action > path="/struts_redirect_portlet/help" > type="com.ip6networks.struts_redirect.portlet.RedirectHelpAction" > name="RedirectHelpForm" > scope="session" > input="/portlet/struts_redirect_portlet/help.jsp" > unknown="false" > validate="true" > > > <forward > name="help" > path="/portlet/struts_redirect_portlet/help.jsp" > redirect="true" > /> > </action> > > --- validation.xml: > =============================== > <form name="RedirectHelpForm"> > <field property="name" > depends="required"> > <msg > name="required" > key="error.name.required"/> > > <arg0 key="RedirectHelpForm.name"/> > </field> > </form> > <form name="RedirectForm"> > <field property="comment" > depends="required"> > <msg > name="required" > key="error.comment.required"/> > > <arg0 key="RedirectForm.comment"/> > </field> > </form> > > That s all. > I don;t know else I have to show here. > > Please let me. I am stlll newbie with struts. > Your help is certainly very much appreciated. > > Thanks > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org