Don't have any more ideas, but generally, the message "cannot find bean in any scope" means exactly what it says: The bean is not in a scope where it can be found. Which means that either it is set in request scope, and attempted to be used in a different request (typically what happens when you do a redirect), or that it has not been set at all. Also, keep in mind that the request/response cycle is a little bit different in a portlet than in a regular web application, so you might have to re-think what you're trying to do.
Nils-H On Thu, Jun 25, 2009 at 10:05 AM, Sam Wun<swun2...@gmail.com> wrote: > Like I have said before, if I "manually" navigated to the > RedirectHellpForm page , then reload the first page (RedirectForm), > and press the Submit button from the RedirectForm, it can find the > "name" of RedirectHelpForm. > My questions is how can I setAttribute("RedirectHelpForm" ...) before > navigated to the RedirectHelpForm page?? > > thanks > Sam > > On Thu, Jun 25, 2009 at 5:17 PM, Sam Wun<swun2...@gmail.com> wrote: >> I just tried your suggestion, >> it doesn't work. >> The page flow is: >> RedirectAction -> RedirectHelpAction -> RedirectStep3Action >> >> Here is the RedirectAction.java file: >> >> 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" >> * 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; >> >> 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"); >> } >> } >> >> Here is the RedirectHelpAction.java file: >> >> 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" >> * 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.getSession().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 { >> >> return mapping.findForward("help"); >> } >> } >> >> >> On Thu, Jun 25, 2009 at 3:47 PM, Nils-Helge Garli >> Hegvik<nil...@gmail.com> wrote: >>> Did you try request.getSession().setAttribute("RedirectHelpForm", >>> redirectHelpForm)? >>> >>> Nils-H >>> >>> On Thu, Jun 25, 2009 at 7:14 AM, Sam Wun<swun2...@gmail.com> wrote: >>>> 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 >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> 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