留言板

Struts portlet

thumbnail
mohammad azaruddin,修改在10 年前。

Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi


In normal MVC portlet we can hit perticular method using this snipplet
myActionURL.setParameter(ActionRequest.ACTION_NAME, "myMethod");


How can achiev same in struts portlet.
<portlet:actionURL var="myActionURL">
<portlet:param name="struts_action" value="/sample_struts_liferay_portlet/subscribe" />
</portlet:actionURL>

this actionURL hit the processAction method of class defined in struts-config.xml.But i wanted to hit perticular method (myMethod in this case)

How can i achieve this

Azhar
Thanks in advance
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi all
Is it possible .....?
thumbnail
Vilmos Papp,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 529 加入日期: 10-10-21 最近的帖子
<portlet:actionurl name="myFunction" var="myFuncionURL" />
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi
Vilmos Papp

Thank youemoticon
This is what i was looking foremoticonemoticonemoticon And in sample-struts-portlet all methods are overridden method.so i dont think they used this approachemoticon
thumbnail
Apoorva Prakash,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
mohammad azaruddin:
Hi


In normal MVC portlet we can hit perticular method using this snipplet
myActionURL.setParameter(ActionRequest.ACTION_NAME, "myMethod");


How can achiev same in struts portlet.
<portlet:actionURL var="myActionURL">
<portlet:param name="struts_action" value="/sample_struts_liferay_portlet/subscribe" />
</portlet:actionURL>

this actionURL hit the processAction method of class defined in struts-config.xml.But i wanted to hit perticular method (myMethod in this case)

How can i achieve this

Azhar
Thanks in advance


Hello Azhar,

The way you are trying to achieve this, I am afraid this is not possible.

Instead of MVCPortlet, you shout try extending Apache Strut's Action class. See the following class blueprint:
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 SampleAction extends Action {

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

			return mapping.findForward("/html/sample/view.jsp");
		}
	}
}


HTH.

Thanks and Regards,
Apoorva Prakash
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
HI Apoorva Prakash

Thank you for your answeremoticon
How if i'm extending Action class and want to jump to perticular custom method....?
thumbnail
Vilmos Papp,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 529 加入日期: 10-10-21 最近的帖子
Probably you could check out our demo struts portlet as well: https://github.com/liferay/liferay-plugins/tree/master/portlets/sample-struts-liferay-portlet
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi
In sample sturts portlet example renderURL is created using this sniplet

<a href="<portlet:renderURL><portlet:param name="struts_action" value="/sample_struts_liferay_portlet/x" /></portlet:renderURL>">Render</a>


And as mentioned in struts-config.xml it is going to action class

<action path="/sample_struts_liferay_portlet/x" type="com.liferay.samplestrutsliferay.struts.action.XAction">
<exception key="error.sample.exception" type="com.liferay.samplestrutsliferay.SampleException" path="portlet.sample_struts_liferay_portlet.sample_exception" />
<forward name="portlet.sample_struts_liferay_portlet.x" path="portlet.sample_struts_liferay_portlet.x" />
</action>



So my doubt is can we render,Without going to action class....?And without overidding render method of action class,
return mapping.findForward(
getForward(
renderRequest, "portlet.sample_struts_liferay_portlet.x"));

thumbnail
Apoorva Prakash,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
mohammad azaruddin:
Hi
In sample sturts portlet example renderURL is created using this sniplet

<a href="<portlet:renderURL><portlet:param name="struts_action" value="/sample_struts_liferay_portlet/x" /></portlet:renderURL>">Render</a>


And as mentioned in struts-config.xml it is going to action class

<action path="/sample_struts_liferay_portlet/x" type="com.liferay.samplestrutsliferay.struts.action.XAction">
<exception key="error.sample.exception" type="com.liferay.samplestrutsliferay.SampleException" path="portlet.sample_struts_liferay_portlet.sample_exception" />
<forward name="portlet.sample_struts_liferay_portlet.x" path="portlet.sample_struts_liferay_portlet.x" />
</action>



So my doubt is can we render,Without going to action class....?And without overidding render method of action class,
return mapping.findForward(
getForward(
renderRequest, "portlet.sample_struts_liferay_portlet.x"));



Yes, we can do.

You are probably using renderURL and ActionURL wrong.
ActionURL - forwards your request to processAction()
RenderURL - forwards your request to doView()

You should not add the the struts action in renderURL, but in action URL.

HTH
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi apoorva
In example portlet they were using same param name&value for creating renderURL as well as actionURL.
sample-struts-liferay-portlet example portlet they use
<a href="<portlet:renderURL><portlet:param name="struts_action" value="/sample_struts_liferay_portlet/x" /></portlet:renderURL>">Render</a>
sniplet to create renderURL..You can find sample portlet here


<a href="<portlet:actionURL><portlet:param name="struts_action" value="/sample_struts_liferay_portlet/x" /><portlet:param name="x_param" value="bad_x_value" /></portlet:actionURL>">Action</a>
thumbnail
Apoorva Prakash,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
mohammad azaruddin:
HI Apoorva Prakash

Thank you for your answeremoticon
How if i'm extending Action class and want to jump to perticular custom method....?


Hey Azhar,

All the rules of Struts Portlet applies here. But if you are looking for jumping on particular function then you can create portlet with multiple actions as suggested by Vilmos Papp.
You can seek some help from here and here.

HTH.

Thanks and Regards,
Apoorva Prakash
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Struts portlet

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon
thumbnail
Apoorva Prakash,修改在10 年前。

RE: Struts portlet

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
mohammad azaruddin:
Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon


Welcome Azhar...