You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nils-Helge Garli Hegvik <ni...@gmail.com> on 2009/08/06 19:14:32 UTC

Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

The portlet execution life cycle is separated in two: The action/event
phase, in which state transitions (typically a form submit) occurs,
and then the render phase, where the actual output is rendered. The
request object that is available in these two phases are not the same.
In the action phase, there is no RenderRequest, only an ActionRequest,
and opposite in the render phase. So what's happening is that the
action is probably invoked in the action phase in the second case. I
suggest that you use a redirectAction result from the action that is
processing the submit to avoid this from happening.

Nils-H

2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
> Greetings to all ,
>
> i have setup latest struts 2.1.6 and created a simple portlet for liferay
> 5.2.3
>
> Everything went smoothly until i tried to run the below code :
>
> RenderRequest req = PortletActionContext.getRenderRequest();
>       ThemeDisplay themeDisplay = (ThemeDisplay)
> req.getAttribute(WebKeys.THEME_DISPLAY);
>       PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
>
> in a new action that i called from the index view action. This code runs
> smoothly on the index view action but in my second action i get the below
> exception
>
> java.lang.IllegalStateException: RenderRequest cannot be obtained in event
> phase
> at
> org.apache.struts2.portlet.context.PortletActionContext.getRenderRequest(PortletActionContext.java:66)
>
> in the first line ( RenderRequest req =
> PortletActionContext.getRenderRequest(); )
>
> I would really appreciate any replies since i am on a tight schedule.
>
> Regards,
>
> Leon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Not with the Struts tags, no. But it's quite possible to use Ajax with portlets.

Nils-H

On Fri, Aug 7, 2009 at 5:47 PM, Scott Nesbitt<sc...@yahoo.com> wrote:
>
> So Ajax actions do not work in Struts portlets?  If not, do you know if there are plans for them to work in the future?
>
> Thanks,
>
> Scott
>
>
>
> ----- Original Message ----
> From: Nils-Helge Garli Hegvik <ni...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Friday, August 7, 2009 4:41:53 AM
> Subject: Re: struts2 portlet bug RenderRequest cannot be obtained in event  phase
>
>>
>> I have also noticed that struts form tag breaks the layout of the page. I am
>> not sure if you have seen this. I will try to find out why (i.e. not
>> standard html or css issue), otherwise i will use html form.
>
> Try using the "simple" theme.
>
> Nils-H
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Scott Nesbitt <sc...@yahoo.com>.
So Ajax actions do not work in Struts portlets?  If not, do you know if there are plans for them to work in the future?

Thanks,

Scott



----- Original Message ----
From: Nils-Helge Garli Hegvik <ni...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Friday, August 7, 2009 4:41:53 AM
Subject: Re: struts2 portlet bug RenderRequest cannot be obtained in event  phase

>
> I have also noticed that struts form tag breaks the layout of the page. I am
> not sure if you have seen this. I will try to find out why (i.e. not
> standard html or css issue), otherwise i will use html form.

Try using the "simple" theme.

Nils-H

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


      

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
>
> I have also noticed that struts form tag breaks the layout of the page. I am
> not sure if you have seen this. I will try to find out why (i.e. not
> standard html or css issue), otherwise i will use html form.

Try using the "simple" theme.

Nils-H

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Leonidas Papadakis <lp...@bluecore.gr>.
I understand your solution but the issue occurs when i call editcontent 
from the jsp file. At that point i can not get RenderReuqest in 
editcontent action that i need further down in the code. RenderRequest 
will provide me portletDisplay and from portletDisplay i get the 
instanceId that i use to store my data to the db. This way regardless of 
where the user places a portlet i will have unique content. To make it 
more clear the table in the db has these fields: id, content, 
portletinstanceid.

In order to overcome this problem i send the instanceid as post 
parameter (hidden input when calling the action) so i do not need to get 
RenderRequest in action editcontent. This way with the redirection that 
you proposed as result type seems to provide a solution.

I have also noticed that struts form tag breaks the layout of the page. 
I am not sure if you have seen this. I will try to find out why (i.e. 
not standard html or css issue), otherwise i will use html form.

Thanks again for your reply.

Regards,
Leon

Nils-Helge Garli Hegvik wrote:
> Try something like this:
>
> <action name="editcontent" class="struts.actions.EditContentAction">
>   <result type="redirectAction">
>     <param name="actionName">index</param>
>   </result>
> </action>
>
> This of course assumes that you have actually separated the processing
> and view logic in these two actions.
>
> You should also take a look at the portlet tutorial:
> http://struts.apache.org/2.1.6/docs/struts-2-portlet-tutorial.html
>
> Nils-H
>
>
> 2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
>   
>> Hi Nils-H and thanks for your reply. Much appreciated.
>>
>> At the moment this is in my struts.xml
>>
>> <package name="view" extends="struts-portlet-default" namespace="/view">
>>          <action name="index" class="struts.actions.ContentAction">
>>           <result>/WEB-INF/jsp/view/index.jsp</result>
>>      </action>
>>
>>      <action name="editcontent" class="struts.actions.EditContentAction">
>>           <result name="INPUT">/WEB-INF/jsp/view/edit.jsp</result>
>>           <result name="SUCCESS">/WEB-INF/jsp/view/index.jsp</result>
>>      </action>
>>
>>   </package>
>>
>> initially the portlet executes the index action and the code runs fine.
>> Afterwards even if i call action index from a form or action editcontent i
>> get the exception.
>>
>> How would i change the above configuration ?
>>
>> Thanks again
>>
>> Leon
>>
>> Nils-Helge Garli Hegvik wrote:
>>     
>>> The portlet execution life cycle is separated in two: The action/event
>>> phase, in which state transitions (typically a form submit) occurs,
>>> and then the render phase, where the actual output is rendered. The
>>> request object that is available in these two phases are not the same.
>>> In the action phase, there is no RenderRequest, only an ActionRequest,
>>> and opposite in the render phase. So what's happening is that the
>>> action is probably invoked in the action phase in the second case. I
>>> suggest that you use a redirectAction result from the action that is
>>> processing the submit to avoid this from happening.
>>>
>>> Nils-H
>>>
>>> 2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
>>>
>>>       
>>>> Greetings to all ,
>>>>
>>>> i have setup latest struts 2.1.6 and created a simple portlet for liferay
>>>> 5.2.3
>>>>
>>>> Everything went smoothly until i tried to run the below code :
>>>>
>>>> RenderRequest req = PortletActionContext.getRenderRequest();
>>>>      ThemeDisplay themeDisplay = (ThemeDisplay)
>>>> req.getAttribute(WebKeys.THEME_DISPLAY);
>>>>      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
>>>>
>>>> in a new action that i called from the index view action. This code runs
>>>> smoothly on the index view action but in my second action i get the below
>>>> exception
>>>>
>>>> java.lang.IllegalStateException: RenderRequest cannot be obtained in
>>>> event
>>>> phase
>>>> at
>>>>
>>>> org.apache.struts2.portlet.context.PortletActionContext.getRenderRequest(PortletActionContext.java:66)
>>>>
>>>> in the first line ( RenderRequest req =
>>>> PortletActionContext.getRenderRequest(); )
>>>>
>>>> I would really appreciate any replies since i am on a tight schedule.
>>>>
>>>> Regards,
>>>>
>>>> Leon
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>       
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>   


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Try something like this:

<action name="editcontent" class="struts.actions.EditContentAction">
  <result type="redirectAction">
    <param name="actionName">index</param>
  </result>
</action>

This of course assumes that you have actually separated the processing
and view logic in these two actions.

You should also take a look at the portlet tutorial:
http://struts.apache.org/2.1.6/docs/struts-2-portlet-tutorial.html

Nils-H


2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
> Hi Nils-H and thanks for your reply. Much appreciated.
>
> At the moment this is in my struts.xml
>
> <package name="view" extends="struts-portlet-default" namespace="/view">
>          <action name="index" class="struts.actions.ContentAction">
>           <result>/WEB-INF/jsp/view/index.jsp</result>
>      </action>
>
>      <action name="editcontent" class="struts.actions.EditContentAction">
>           <result name="INPUT">/WEB-INF/jsp/view/edit.jsp</result>
>           <result name="SUCCESS">/WEB-INF/jsp/view/index.jsp</result>
>      </action>
>
>   </package>
>
> initially the portlet executes the index action and the code runs fine.
> Afterwards even if i call action index from a form or action editcontent i
> get the exception.
>
> How would i change the above configuration ?
>
> Thanks again
>
> Leon
>
> Nils-Helge Garli Hegvik wrote:
>>
>> The portlet execution life cycle is separated in two: The action/event
>> phase, in which state transitions (typically a form submit) occurs,
>> and then the render phase, where the actual output is rendered. The
>> request object that is available in these two phases are not the same.
>> In the action phase, there is no RenderRequest, only an ActionRequest,
>> and opposite in the render phase. So what's happening is that the
>> action is probably invoked in the action phase in the second case. I
>> suggest that you use a redirectAction result from the action that is
>> processing the submit to avoid this from happening.
>>
>> Nils-H
>>
>> 2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
>>
>>>
>>> Greetings to all ,
>>>
>>> i have setup latest struts 2.1.6 and created a simple portlet for liferay
>>> 5.2.3
>>>
>>> Everything went smoothly until i tried to run the below code :
>>>
>>> RenderRequest req = PortletActionContext.getRenderRequest();
>>>      ThemeDisplay themeDisplay = (ThemeDisplay)
>>> req.getAttribute(WebKeys.THEME_DISPLAY);
>>>      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
>>>
>>> in a new action that i called from the index view action. This code runs
>>> smoothly on the index view action but in my second action i get the below
>>> exception
>>>
>>> java.lang.IllegalStateException: RenderRequest cannot be obtained in
>>> event
>>> phase
>>> at
>>>
>>> org.apache.struts2.portlet.context.PortletActionContext.getRenderRequest(PortletActionContext.java:66)
>>>
>>> in the first line ( RenderRequest req =
>>> PortletActionContext.getRenderRequest(); )
>>>
>>> I would really appreciate any replies since i am on a tight schedule.
>>>
>>> Regards,
>>>
>>> Leon
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by Leonidas Papadakis <lp...@bluecore.gr>.
Hi Nils-H and thanks for your reply. Much appreciated.

At the moment this is in my struts.xml

<package name="view" extends="struts-portlet-default" namespace="/view">
      
       <action name="index" class="struts.actions.ContentAction">
            <result>/WEB-INF/jsp/view/index.jsp</result>
       </action>

       <action name="editcontent" class="struts.actions.EditContentAction">
            <result name="INPUT">/WEB-INF/jsp/view/edit.jsp</result>
            <result name="SUCCESS">/WEB-INF/jsp/view/index.jsp</result>
       </action>

    </package>

initially the portlet executes the index action and the code runs fine.
Afterwards even if i call action index from a form or action editcontent 
i get the exception.

How would i change the above configuration ?

Thanks again

Leon

Nils-Helge Garli Hegvik wrote:
> The portlet execution life cycle is separated in two: The action/event
> phase, in which state transitions (typically a form submit) occurs,
> and then the render phase, where the actual output is rendered. The
> request object that is available in these two phases are not the same.
> In the action phase, there is no RenderRequest, only an ActionRequest,
> and opposite in the render phase. So what's happening is that the
> action is probably invoked in the action phase in the second case. I
> suggest that you use a redirectAction result from the action that is
> processing the submit to avoid this from happening.
>
> Nils-H
>
> 2009/8/6 Leonidas Papadakis <lp...@bluecore.gr>:
>   
>> Greetings to all ,
>>
>> i have setup latest struts 2.1.6 and created a simple portlet for liferay
>> 5.2.3
>>
>> Everything went smoothly until i tried to run the below code :
>>
>> RenderRequest req = PortletActionContext.getRenderRequest();
>>       ThemeDisplay themeDisplay = (ThemeDisplay)
>> req.getAttribute(WebKeys.THEME_DISPLAY);
>>       PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
>>
>> in a new action that i called from the index view action. This code runs
>> smoothly on the index view action but in my second action i get the below
>> exception
>>
>> java.lang.IllegalStateException: RenderRequest cannot be obtained in event
>> phase
>> at
>> org.apache.struts2.portlet.context.PortletActionContext.getRenderRequest(PortletActionContext.java:66)
>>
>> in the first line ( RenderRequest req =
>> PortletActionContext.getRenderRequest(); )
>>
>> I would really appreciate any replies since i am on a tight schedule.
>>
>> Regards,
>>
>> Leon
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>