You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sharath karnati <ka...@yahoo.com> on 2009/08/06 17:23:17 UTC

Using Ajax tag with struts2.0.11

Hi All,
 
    Say I have COMPLAINT table as below
 
----------------------------------------------------------------------------
 
<div id="div1">
<table class="datatab" cellpadding="0" cellspacing="5" width="95%">
<thead> 
<tr align="left"> 
<th> 
<c:choose>
<c:when test="${sort_by == 'complaint_id'}"> 
<s:url id="complaintLink1" action="complaints!listWithAjax" includeParams="none">
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{other_order}"/> 
</s:url>

<s:a id="complaintId1" href="%{complaintLink1}" cssClass="sort_header" theme="ajax" targets="div1" errorText="An error ocurred" loadingText="Loading...">
Complaint ID<img border="0" src="images/sort_${sort_order}.gif" />
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{other_order}"/>
</s:a> 
</c:when>
<c:otherwise>
<s:url id="complaintLink2" action="complaints!listWithAjax" includeParams="none">
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{'asc'}"/> 
</s:url>
<s:a id="complaintId2" href="%{complaintLink2}" cssClass="sort_header" theme="ajax" targets="div1" errorText="An error ocurred" loadingText="Loading...">
Complaint ID
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{'asc'}"/>
</s:a> 
</c:otherwise>
</c:choose> 
</th> 
<th>
<c:choose>
<c:when test="${sort_by == 'first_name'}">
<a class="sort_header" href="javascript:sortResults('openForm', 'first_name', '${other_order}')">
Consumer Name<img border="0" src="images/sort_${sort_order}.gif" />
</a>
</c:when>
<c:otherwise>
<a class="sort_header" href="javascript:sortResults('openForm', 'first_name', 'asc')">
Consumer Name
</a>
</c:otherwise>
</c:choose>
</th> 
<th>
<c:choose> 
<c:when test="${sort_by == 'submission_date'}">
<a class="sort_header" href="javascript:sortResults('openForm', 'submission_date', '${other_order}')">
Submission Date<img border="0" src="images/sort_${sort_order}.gif" />
</a>
</c:when>
<c:otherwise>
<a class="sort_header" href="javascript:sortResults('openForm', 'submission_date', 'asc')">
Submission Date
</a>
</c:otherwise>
</c:choose>
</th>

 

</tr>
</thead>

<s:iterator value="complaint_list" id="complaint">
<tr>
<td>
<s:url id="complaintLink" action="manageForm" includeParams="none">
<s:param name="complaint_key" value="%{user_complaint_key}"/>
<s:param name="form_type" value="%{form_type}"/> 
</s:url>
<s:a href="%{complaintLink}">
<s:property value="user_complaint_key" />
</s:a>
</td> 
<td>
<s:property value="first_name" />
<s:property value="last_name" />
</td> 
<td>
<s:date name="submission_date" format="MM/dd/yyyy" />
</td>
</tr>
</s:iterator> 
</table>
</div>
-------------------------------------
 
  Added ajax call in the below way
 
   
<s:url id="complaintLink2" action="complaints!listWithAjax" includeParams="none">
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{'asc'}"/> 
</s:url>
<s:a id="complaintId2" href="%{complaintLink2}" cssClass="sort_header" theme="ajax" targets="div1" errorText="An error ocurred" loadingText="Loading...">
Complaint ID
<s:param name="sort_by" value="%{'complaint_id'}"/>
<s:param name="sort_order" value="%{'asc'}"/>
</s:a> 

 
 When user selects 'Complaint ID' column header,  it is calling 'listWithAjax' method in 'complaints' action but it is not refreshing 'div1' values. It is not even showing table header columns.  In page header added <s:head theme="ajax" debug="true"/>
 
 The 'listWithAjax' method is populating list 'complaint_list' of values in action but these are not avilable in response, can anyone let me know how to retrieve values in ajax request? what I'm doing wrong?
 
  Thanks in advance.
 
Regards,
Sharath.


      

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
>
>
>   


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

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
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


struts2 portlet bug RenderRequest cannot be obtained in event phase

Posted by 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