留言板

How to create ActionRequest in Struts portlet

thumbnail
devi nimmagadda,修改在12 年前。

How to create ActionRequest in Struts portlet

Regular Member 帖子: 109 加入日期: 10-12-9 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Liferay Master 帖子: 690 加入日期: 04-8-18 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 109 加入日期: 10-12-9 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 152 加入日期: 10-9-28 最近的帖子
Hi Devi,

Me to have same problem?
Please help me.

Thank you in advance.


Thanks & Regards
Manasa.chandri
simon tuffle,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 150 加入日期: 09-5-18 最近的帖子
Hi Manasa,

I think its better to follow this LINK
thumbnail
manasa chandri,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 152 加入日期: 10-9-28 最近的帖子
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
thumbnail
Raju OO7,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 239 加入日期: 10-4-27 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 109 加入日期: 10-12-9 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 150 加入日期: 09-5-18 最近的帖子
Hi devi,

Could you please let me know the difference between struts portlet and struts -plugin portlet.
thumbnail
Mani kandan,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Expert 帖子: 492 加入日期: 10-9-15 最近的帖子
Hi simon,
wt you are talking about Struts portlet or MVCPortlet?
Give the question clearly
thumbnail
Manali Lalaji,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Expert 帖子: 362 加入日期: 10-3-9 最近的帖子
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,修改在12 年前。

RE: How to create ActionRequest in Struts portlet

Regular Member 帖子: 127 加入日期: 09-7-14 最近的帖子
I got it with the following code:

ActionRequest actionRequest = PortletActionContext.getActionRequest();