Foros de discusión

How to create ActionRequest in Struts portlet

thumbnail
devi nimmagadda, modificado hace 12 años.

How to create ActionRequest in Struts portlet

Regular Member Mensajes: 109 Fecha de incorporación: 9/12/10 Mensajes recientes
Hi all,

can anybody know how to create ActionRequest in Struts plugin portlet.

Means in Struts portlet == our class should extend Action class. Action class contains execute() like below.



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Sample extends Action{


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

// coding of our integration logic here...

return super.execute(mapping, form, request, response);
}
}


Here the request and response objects are HttpServletRequest and HttpServletResponse .

From this how can I get ActionRequest and ActionResponse objects. can anybody please help me for this.


Thanks in advance.....
thumbnail
Suresh Nimmakayala, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Liferay Master Mensajes: 690 Fecha de incorporación: 18/08/04 Mensajes recientes
Hi devi
just a idea

public class SampleAction extends PortletAction {
public void processAction(
ActionMapping mapping, ActionForm form, PortletConfig config,
ActionRequest req, ActionResponse res)
throws Exception {
...................
............
if (Validator.isNull(description)) {
setForward(req, "portlet.ext.sample.failure");
} else {
//your action
res.sendRedirect(redirectURL);
}
}

followed by
public ActionForward render(ActionMapping mapping, ActionForm form,
PortletConfig config, RenderRequest req, RenderResponse res)
throws Exception {
if (getForward(req) != null && !getForward(req).equals("")) {
return mapping.findForward(getForward(req));
} else {
return mapping.findForward("portlet.ext.sample.view");
}
}

}


Regards
Suresh Nimmakayala
thumbnail
devi nimmagadda, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 109 Fecha de incorporación: 9/12/10 Mensajes recientes
Hi,

Thanks for your reply. I am doing Struts plugin portlet. So My class should extends Action class. So My Action Servlet should extends org.apache.portals.bridges.struts.StrutsPortlet.


In portlet.xml i am writing like this..

<portlet>
<portlet-name>employee</portlet-name>
<display-name>employee</display-name>
<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet[</portlet-class>
<init-param>
<name>ServletContextProvider</name>
<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
</init-param>
<init-param>
<name>ViewPage</name>
<value>/portlet_action/employee/view</value>
</init-param>



With this I created one Sample class like before I said.

Sample class should extend Action class of org.apache.struts.action.Action.

Here no ActionRequest and ActionResponse... only HttpServletRequest and HttpServletResponse are present.

please suggest me....

Thanks in advance..
thumbnail
manasa chandri, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 152 Fecha de incorporación: 28/09/10 Mensajes recientes
Hi Devi,

Me to have same problem?
Please help me.

Thank you in advance.


Thanks & Regards
Manasa.chandri
simon tuffle, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 150 Fecha de incorporación: 18/05/09 Mensajes recientes
Hi Manasa,

I think its better to follow this LINK
thumbnail
manasa chandri, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 152 Fecha de incorporación: 28/09/10 Mensajes recientes
Hi simon tuffle,

Thank yo for giving reply
I worked on that, i got exception..
I am attached to this post
Please help me.
Thank you in advance.

Thanks & Regards
Manasa.chandri

Archivos adjuntos:

thumbnail
Raju OO7, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 239 Fecha de incorporación: 27/04/10 Mensajes recientes
in the jsp file..


&lt;%@page import="javax.portlet.PortletURL"%&gt;
&lt;%@page import="javax.portlet.RenderResponse"%&gt;
&lt;%@page import="javax.portlet.WindowState"%&gt;
&lt;%@page import="javax.portlet.ActionResponse"%&gt;<br>
&lt;%
    PortletURL actionURL = renderResponse.createActionURL();
    actionURL.setWindowState(WindowState.MAXIMIZED);
    actionURL.setParameter("struts_action", "/ext/libraryAction/add_book");
%&gt;

Add a book entry to the Library:


<form action="<%= actionURL.toString() %>" method="POST" name="<portlet:namespace />fm">   
   
    Book Title:
   
    <input type="text" name="<portlet:namespace />book_title"><br><br>
   
    <input type="submit" value="Add Book">
</form>






in struts-cofig-ext.xml



<!--?xml version="1.0"?-->

<struts-config>
	<action-mappings>
		<action path="/ext/libraryActionDB/add_book" type="com.ext.portlet.libraryActionDB.action.AddBookActionDB">
		<forward name="portlet.ext.libraryActionDB.view" path="portlet.ext.libraryActionDB.view" />
			<forward name="portlet.ext.libraryActionDB.success" path="portlet.ext.libraryActionDB.success" />
			<forward name="portlet.ext.libraryActionDB.failure" path="portlet.ext.libraryActionDB.failure" />
		</action>
	</action-mappings>
</struts-config>




in tiles-defs-ext.xml..

<!--?xml version="1.0" encoding="ISO-8859-1"?-->

<tiles-definitions>
	<definition name="portlet.ext.libraryAction.view" extends="portlet.ext.libraryAction">
		<put name="portlet_content" value="/portlet/ext/libraryAction/view.jsp" />
	</definition>
	<definition name="portlet.ext.libraryAction.failure" extends="portlet.ext.libraryAction">
		<put name="portlet_content" value="/portlet/ext/libraryAction/failure.jsp" />
	</definition>
	<definition name="portlet.ext.libraryAction.success" extends="portlet.ext.libraryAction">
		<put name="portlet_content" value="/portlet/ext/libraryAction/success.jsp" />
	</definition>
</tiles-definitions>
thumbnail
devi nimmagadda, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 109 Fecha de incorporación: 9/12/10 Mensajes recientes
Hi raju,

Thanks for your reply.

I am developing struts plugin portlet. Unlike struts portlet , i cannot get easily actionRequest.

I am using execute () of org.apache.struts.action class. Not liferay struts action.

could you please suggest me , how can i get action request in struts plugin portlet.

I am using org.apache.struts.ActionServlet

org.apache.struts.action




Thanks in advance....
simon tuffle, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 150 Fecha de incorporación: 18/05/09 Mensajes recientes
Hi devi,

Could you please let me know the difference between struts portlet and struts -plugin portlet.
thumbnail
Mani kandan, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Expert Mensajes: 492 Fecha de incorporación: 15/09/10 Mensajes recientes
Hi simon,
wt you are talking about Struts portlet or MVCPortlet?
Give the question clearly
thumbnail
Manali Lalaji, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Expert Mensajes: 362 Fecha de incorporación: 9/03/10 Mensajes recientes
Hi Devi,

Below is the sample code:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class AddSkillsAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
throws Exception {
ActionRequest aReq = (ActionRequest) req.getAttribute("javax.portlet.request");
ActionResponse aRes = (ActionResponse) req.getAttribute("javax.portlet.response");
PortletPreferences prefs = aReq.getPreferences();
String view = (String) aReq.getParameter("view");
category_id =((AddSkillsForm)form).getCategory_Id();
aRes.setPortletMode( PortletMode.VIEW);
Employee_SkillsLocalServiceUtil.addSkills(emp_id, skillName, categoryName, rating, experience, comments);
return mapping.findForward("/Employee_Skills_App/addSkills/success");
}

Hope this helps..

Regards,
Manali
thumbnail
David García González, modificado hace 12 años.

RE: How to create ActionRequest in Struts portlet

Regular Member Mensajes: 127 Fecha de incorporación: 14/07/09 Mensajes recientes
I got it with the following code:

ActionRequest actionRequest = PortletActionContext.getActionRequest();