How to do that with session? I am currently setting it in the execute() and render method with the following code: req.setAttribute("RedirectHelpForm", redirectHelpForm);
but this is for request rather than session? Thanks for the suggesion. sam On Thu, Jun 25, 2009 at 3:09 PM, Nils-Helge Garli Hegvik<nil...@gmail.com> wrote: > Haven't looked very deeply into it, but could it be that you're > setting the attribute in the action phase, and trying to access it in > the render phase? That won't work. In that case, you have to set it as > a session attribute, or set some kind of id as a render parameter and > re-fetch the object in the render phase. > > Nils-H > > On Thu, Jun 25, 2009 at 7:03 AM, Sam Wun<swun2...@gmail.com> wrote: >> Hi, >> >> I noticed the setAttribute() method is called too late in one of my >> Action class: >> >> 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" >> * attribute="redirectHelpForm" >> * scope="session" >> * input="/portlet/struts_redirect_portlet/help.jsp" >> * @struts.action-forward name="help" >> path="/portlet/struts_redirect_portlet/help.jsp" redirect="false" >> * @struts.action-forward name="step3" >> path="/portlet/struts_redirect_portlet/step3.jsp" redirect="false" >> */ >> >> public class RedirectHelpAction extends PortletAction { >> >> public ActionForward execute( >> ActionMapping mapping, ActionForm form, >> HttpServletRequest req, >> HttpServletResponse res) >> throws Exception { >> RedirectHelpForm redirectHelpForm = (RedirectHelpForm) form; >> req.setAttribute("RedirectHelpForm", redirectHelpForm); >> >> String name = redirectHelpForm.getName().trim(); >> if ( name.length() > 0) { >> return mapping.findForward("step3"); >> } >> >> return mapping.findForward("help"); >> } >> >> >> public ActionForward render( >> ActionMapping mapping, ActionForm form, >> PortletConfig config, >> RenderRequest req, RenderResponse res) >> throws Exception { >> RedirectHelpForm redirectHelpForm = (RedirectHelpForm) form; >> req.setAttribute("redirectHelpForm", redirectHelpForm); >> >> return mapping.findForward("help"); >> } >> } >> >> The consequence of that is resulting a "cannot find bean in any scope". >> >> Actully when the page is died on this reason, I press the back button >> of the browser go back to the previous page, and then pressed the >> Submit button again, the error would go disappear, because the >> RedirectHelpForm bean is alerady populated in the class >> RedirectHelpAction, however not in the class RedirectAction. >> The code of RedirectAction is shown as below: >> >> /** @struts.action name="RedirectForm" path="/struts_redirect_portlet/input" >> * attribute="redirectForm" >> * scope="session" >> * input="/portlet/struts_redirect_portlet/input.jsp" >> * >> * @struts.action-forward name="input" >> path="/portlet/struts_redirect_portlet/input.jsp" redirect="false" >> * @struts.action-forward name="help" >> path="/portlet/struts_redirect_portlet/help.jsp" redirect="false" >> */ >> public class RedirectAction extends PortletAction { >> >> public ActionForward execute( >> ActionMapping mapping, ActionForm form, >> HttpServletRequest req, >> HttpServletResponse res) >> throws Exception { >> >> RedirectForm redirectForm = (RedirectForm) form; >> // req.setAttribute("redirectForm", redirectForm); >> >> 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"); >> } >> } >> >> Can anyone tell me how to pre-setAttribute for an upcoming Form in an >> Action class? >> It sounds weried. but I couldn't find a way to get rid of the error. >> >> Thanks >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >> For additional commands, e-mail: user-h...@struts.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org