Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mohammad Azharuddin
Struts portlet
April 29, 2013 3:27 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

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
Mohammad Azharuddin
RE: Struts portlet
April 29, 2013 4:00 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

Hi all
Is it possible .....?
Apoorva Prakash
RE: Struts portlet
April 29, 2013 4:10 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

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:
 1import org.apache.struts.action.Action;
 2import org.apache.struts.action.ActionForm;
 3import org.apache.struts.action.ActionForward;
 4import org.apache.struts.action.ActionMapping;
 5
 6public class SampleAction extends Action {
 7
 8    public ActionForward execute(
 9            ActionMapping mapping, ActionForm form, HttpServletRequest request,
10            HttpServletResponse response)
11        throws Exception {
12
13            return mapping.findForward("/html/sample/view.jsp");
14        }
15    }
16}


HTH.

Thanks and Regards,
Apoorva Prakash
Vilmos Papp
RE: Struts portlet
April 29, 2013 4:16 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Liferay Master

Posts: 521

Join Date: October 21, 2010

Recent Posts

1<portlet:actionURL name="myFunction" var="myFuncionURL" />
Mohammad Azharuddin
RE: Struts portlet
April 29, 2013 4:18 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

HI Apoorva Prakash

Thank you for your answeremoticon
How if i'm extending Action class and want to jump to perticular custom method....?
Vilmos Papp
RE: Struts portlet
April 29, 2013 4:23 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Liferay Master

Posts: 521

Join Date: October 21, 2010

Recent Posts

Probably you could check out our demo struts portlet as well: https://github.com/liferay/liferay-plugins/tree/master/portlets/sample-struts-liferay-portlet
Mohammad Azharuddin
RE: Struts portlet
April 29, 2013 4:35 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

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
Apoorva Prakash
RE: Struts portlet
April 29, 2013 4:38 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

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
Mohammad Azharuddin
RE: Struts portlet
April 29, 2013 5:13 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon
Apoorva Prakash
RE: Struts portlet
April 29, 2013 6:37 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

mohammad azaruddin:
Hi Apoorva Prakash

Thank Youemoticon the article is helpfulemoticon


Welcome Azhar...
Mohammad Azharuddin
RE: Struts portlet
May 2, 2013 4:38 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

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"));

Apoorva Prakash
RE: Struts portlet
May 2, 2013 5:41 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

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
Mohammad Azharuddin
RE: Struts portlet
May 2, 2013 10:13 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

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>