Foren

Struts portlet

thumbnail
mohammad azaruddin, geändert vor 11 Jahren.

Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
Hi all
Is it possible .....?
thumbnail
Vilmos Papp, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 529 Beitrittsdatum: 21.10.10 Neueste Beiträge
<portlet:actionurl name="myFunction" var="myFuncionURL" />
thumbnail
mohammad azaruddin, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 658 Beitrittsdatum: 15.06.10 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 529 Beitrittsdatum: 21.10.10 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 658 Beitrittsdatum: 15.06.10 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 658 Beitrittsdatum: 15.06.10 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: Struts portlet

Expert Beiträge: 492 Beitrittsdatum: 17.09.12 Neueste Beiträge
Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon
thumbnail
Apoorva Prakash, geändert vor 10 Jahren.

RE: Struts portlet

Liferay Master Beiträge: 658 Beitrittsdatum: 15.06.10 Neueste Beiträge
mohammad azaruddin:
Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon


Welcome Azhar...