Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Action Classes with MVCPortlet Marco Weiland April 8, 2011 10:55 PM
RE: Action Classes with MVCPortlet Lalit Jugran April 9, 2011 2:01 AM
RE: Action Classes with MVCPortlet Marco Weiland April 9, 2011 10:04 AM
RE: Action Classes with MVCPortlet Deb Troxel April 9, 2011 10:11 AM
RE: Action Classes with MVCPortlet Marco Weiland April 9, 2011 11:46 PM
RE: Action Classes with MVCPortlet Marco Weiland April 11, 2011 12:15 AM
RE: Action Classes with MVCPortlet Deb Troxel April 11, 2011 9:13 AM
RE: Action Classes with MVCPortlet Marco Weiland April 11, 2011 1:09 PM
RE: Action Classes with MVCPortlet Deb Troxel April 11, 2011 1:49 PM
RE: Action Classes with MVCPortlet Corentin R May 17, 2011 5:24 AM
RE: Action Classes with MVCPortlet Marco Weiland May 18, 2011 11:57 AM
RE: Action Classes with MVCPortlet Marco Weiland May 18, 2011 11:58 AM
RE: Action Classes with MVCPortlet chris Rowse May 26, 2011 1:24 PM
RE: Action Classes with MVCPortlet Marco Weiland May 27, 2011 8:59 AM
RE: Action Classes with MVCPortlet Marco Weiland May 27, 2011 9:26 AM
RE: Action Classes with MVCPortlet chris Rowse May 30, 2011 10:50 PM
RE: Action Classes with MVCPortlet Brian Scott Schupbach November 17, 2011 1:28 PM
RE: Action Classes with MVCPortlet David Ross November 17, 2011 2:47 PM
RE: Action Classes with MVCPortlet Brian Scott Schupbach May 24, 2012 1:06 PM
RE: Action Classes with MVCPortlet Brian Scott Schupbach December 5, 2012 8:10 AM
RE: Action Classes with MVCPortlet Marco Weiland December 5, 2012 10:28 AM
RE: Action Classes with MVCPortlet Brian Scott Schupbach December 5, 2012 2:27 PM
RE: Action Classes with MVCPortlet Tanaji Londhe January 15, 2013 4:56 AM
RE: Action Classes with MVCPortlet Marco Weiland January 15, 2013 5:06 AM
RE: Action Classes with MVCPortlet Tanaji Londhe January 15, 2013 9:48 AM
Marco Weiland
Action Classes with MVCPortlet
April 8, 2011 10:55 PM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

hi,

is it possible to use multiple action classes with Liferay MVC Portlet?

i build a portlet from liferay ide, using mvcportlet and liferay 6.1 from trunk.
from that portlet template i see no way, to define multiple action paths.

its nice feature to bind actionmethod calls directly to name attribute of <actionURL>,
but that seems for me to get hundreds (maybe emoticon ) of "actionmethods" inside one
portletclass for bigger applications.

anybody any suggestions to call directly actionclasses inside one mvcportlet?

or maybe do i have wrong point of view?

cheers
marco
Lalit Jugran
RE: Action Classes with MVCPortlet
April 9, 2011 2:01 AM
Answer

Lalit Jugran

Rank: Junior Member

Posts: 25

Join Date: July 25, 2010

Recent Posts

Hi Marco Weiland ,

I don't have much idea about other mvc frameworks in java, but in struts there should be a single action class. By the way there is no use of making multiple action classes, rather you can make different util classes according to your requirement & call them directly from inside the single action class. Liferay MVCPortlet has made portlet development very easy in liferay..



emoticonemoticonemoticon
Marco Weiland
RE: Action Classes with MVCPortlet
April 9, 2011 10:04 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

thank u for ur suggestions, i have done it with that ActionUtil classes...

i like mvportlet and i dont want to change or add other technoligies only for not having to much methods.

but in fact, u can map in struts multiple action paths to multiple action classes inside one portlet.
that is the feature i searched for in mvcportlet.

@ lalit : what do u mean as action class? i only have one blablaportletclass extending mvcportlet class, but no action class
which are called struts like from xml config like (liferay example) :

<action path="/document_library/select_file_entry" type="com.liferay.portlet.documentlibrary.action.ViewAction">
<forward name="portlet.document_library.error" path="portlet.document_library.error" />
<forward name="portlet.document_library.view" path="portlet.document_library.select_file_entry" />
</action>

<action path="/document_library/select_folder" type="com.liferay.portlet.documentlibrary.action.EditFolderAction">
<forward name="portlet.document_library.edit_folder" path="portlet.document_library.select_folder" />
<forward name="portlet.document_library.error" path="portlet.document_library.error" />
</action>

which are also called by one portlet ( or maybe they are reusable by other portlets, if u want to)
Deb Troxel
RE: Action Classes with MVCPortlet
April 9, 2011 10:11 AM
Answer

Deb Troxel

Rank: Junior Member

Posts: 81

Join Date: February 22, 2010

Recent Posts

Hi Marco,

If I understand correctly what you are looking for, I think that it is possible to move the action methods into separate classes when using MVCPortlet.

I have not done this, but according to Rich Sezov's Liferay in Action book you can add this to your portlet.xml:
1<init-param>
2    <name>action.package.prefix</name>
3    <value>com.myorg.myapp.portlet.action</value>
4</init-param>

(Using your class package in the value, obviously)

The name of the action is used to locate the class in that package. If you have an action "MyAction" you should create <MyAction>ActionCommand which must must implement com.liferay.util.bridges.mvc.ActionCommand.

The processCommand() method of the <MyAction>ActionCommand class would be called to perform the action. Looking at the source of MVCPortlet, it appears that you can chain together a list of actions to perform in a single request. This would be done by setting the ActionRequest.ACTION_NAME parameter to a comma separated list of actions.

Like I said, I haven't used this yet, so please let us know if you try it and whether it works for you. emoticon
Marco Weiland
RE: Action Classes with MVCPortlet
April 9, 2011 11:46 PM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

hi,
that sounds very good!! i will try that and give feedback!

thank u very much!
Marco Weiland
RE: Action Classes with MVCPortlet
April 11, 2011 12:15 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

i got it working, for anybody else who want to use that here my guideline

1. u have to define the package ( or maybe comma separated list of packages) where to find ur implementations of
com.liferay.util.bridges.mvc.ActionCommand inside portlet.xml
1
2        <init-param>
3            <name>action.package.prefix</name>
4            <value>de.goopen.erp.portlet.mvc</value>
5        </init-param>


2. implement ur ActionCommand class
 1
 2package de.goopen.erp.portlet.mvc;
 3
 4import javax.portlet.PortletException;
 5import javax.portlet.PortletRequest;
 6import javax.portlet.PortletResponse;
 7
 8import com.liferay.util.bridges.mvc.ActionCommand;
 9
10/**
11 * @author mawe
12 *
13 */
14public class ArticleActionCommand implements ActionCommand {
15
16    /* (non-Javadoc)
17     * @see com.liferay.util.bridges.mvc.ActionCommand#processCommand(javax.portlet.PortletRequest, javax.portlet.PortletResponse)
18     */
19    @Override
20    public boolean processCommand(PortletRequest arg0, PortletResponse arg1) throws PortletException {
21        System.out.println("this is the action command called from jsp form");
22        return true;
23    }
24
25}


3. call it from ur jsp
1
2
3<portlet:actionURL var="actionCommandUrl">
4    <portlet:param name="<%=ActionRequest.ACTION_NAME %>" value="Article"></portlet:param>
5</portlet:actionURL>
6<aui:form action="" method="post" name="fmAc1">
7    <aui:button name="actionCommandButton" value="actionCommand" onClick="<%= actionCommandUrl %>"></aui:button>
8</aui:form>


be careful with naming convention ( u may debug commandcache initialisation to get it); the postfix "ActionCommand" will be attached to the value given in the portlet param.

@ deb: imho its not possible to chain multiple actioncommands inside one request, what u saw is that u can define multiple packages, where ur actioncommands r located @, thank u veryverymuch for ur hint!!!!!!!!!
Deb Troxel
RE: Action Classes with MVCPortlet
April 11, 2011 9:13 AM
Answer

Deb Troxel

Rank: Junior Member

Posts: 81

Join Date: February 22, 2010

Recent Posts

Marco Weiland:

@ deb: imho its not possible to chain multiple actioncommands inside one request, what u saw is that u can define multiple packages, where ur actioncommands r located @, thank u veryverymuch for ur hint!!!!!!!!!


This made me curious 'cause it really looked like the code was there to handle an action list. What I found is that it does work, but there is a bug in how it parses the action list. If you don't add a comma at the end of the list, the last action won't be performed.

1<portlet:actionURL var="actionCommandUrl">
2   <portlet:param name="<%=ActionRequest.ACTION_NAME %>" value="First,Second"/>
3</portlet:actionURL>

Only triggers FirstActionCommand.

1<portlet:actionURL var="actionCommandUrl">
2   <portlet:param name="<%=ActionRequest.ACTION_NAME %>" value="First,Second,"/>
3</portlet:actionURL>

Triggers both FirstActionCommand and SecondActionCommand.

I opened http://issues.liferay.com/browse/LPS-16422 to track this. The fix should be easy so I may make it one of my 100 Paper Cut fixes.
Marco Weiland
RE: Action Classes with MVCPortlet
April 11, 2011 1:09 PM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

hi deb,

nice one, ur right! i only tried the method without ending comma, and did not debug further.

i fixed that problem in my env replacing the getActionCommandChain method with this:


public List<ActionCommand> getActionCommandChain(
String actionCommandChain) {

List<ActionCommand> actionCommands = _actionCommandChainCache.get(
actionCommandChain);

if (actionCommands != null) {
return actionCommands;
}else {
actionCommands = new ArrayList<ActionCommand>();
}

for ( String commandString : actionCommandChain.split(CharPool.COMMA+"\\s*")){

ActionCommand actionCommand = getActionCommand(commandString);

if (actionCommand != EMPTY) {
actionCommands.add(actionCommand);
}else {
if (_log.isWarnEnabled()) {
_log.warn(
"Unable to find ActionCommand " + actionCommandChain);
}
}
}

_actionCommandChainCache.put(actionCommandChain, actionCommands);

return actionCommands;
}


that is now working as expected, i was wondering about npe access on actionCommands.


<portlet:actionURL var="actionCommandUrl">
<portlet:param name="<%=ActionRequest.ACTION_NAME %>" value="Article,Supplier"></portlet:param>
</portlet:actionURL>


i also posted that into ur issue...

thanks
Deb Troxel
RE: Action Classes with MVCPortlet
April 11, 2011 1:49 PM
Answer

Deb Troxel

Rank: Junior Member

Posts: 81

Join Date: February 22, 2010

Recent Posts

Nice! Thanks Marco. emoticon
Corentin R
RE: Action Classes with MVCPortlet
May 17, 2011 5:24 AM
Answer

Corentin R

Rank: Junior Member

Posts: 92

Join Date: June 18, 2010

Recent Posts

Hello !
It seems not possible anymore to call action method from the MVCPortlet class when using the init-param
1<init-param>
2    <name>action.package.prefix</name>
3    <value>com.myorg.myapp.portlet.action</value>
4</init-param>

Then all <portlet:actionURL> in the portlet have to call separate ActionCommand class.

Am I wrong with that ?
Marco Weiland
RE: Action Classes with MVCPortlet
May 18, 2011 11:57 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

i have attached u a portlet frame as war and as liferay ide project that is properly working in 6.1.x, if u did not patch actioncommandchain with http://issues.liferay.com/browse/LPS-16422, u have to attach comma after supplier inside actionurl to get it working
Attachments: liferay-mvc-portlet-6.1.0.1.war (19.7k), liferay-mvc-portlet.zip (27.9k)
Marco Weiland
RE: Action Classes with MVCPortlet
May 18, 2011 11:58 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

upd
chris Rowse
RE: Action Classes with MVCPortlet
May 26, 2011 1:24 PM
Answer

chris Rowse

Rank: New Member

Posts: 21

Join Date: March 18, 2009

Recent Posts

Hi Marco / Deb

I have a bit of a conceptual block understanding the chain that Liferay MVC marries a liferay service builder definition to a form. I am reading Rich Sezof's Liferay in action and have copied his code for PRRegistration as far as I can.

What is the missing magic?

How do the names all tie up from Service Builder to Action class and view.jsp?

a) In serviceBuilder.xml I have
1    <entity name="ISGSicCode" local-service="true"
2        remote-service="true">
3   


b) Then I have an action
1
2package com.shorai.isg.action
3public class Sic extends MVCPortlet {
4    public void addSic(ActionRequest request, ActionResponse response) throws Exception {


c) In portlet.xml
 1
 2    <portlet>
 3        <portlet-name>sic</portlet-name>
 4        <display-name>Sic</display-name>
 5        <portlet-class>com.shorai.isg.action.Sic</portlet-class>
 6        <init-param>
 7            <name>view-jsp</name>
 8            <value>/html/sic/view.jsp</value>
 9        </init-param>
10        <init-param>
11                <name>action.package.prefix</name>
12                    <value>com.shorai.isg.action</value>
13    </init-param>

d) In jsp
1
2<%@ page import="com.shorai.isg.action.Sic" %>
3<%@ page import="com.shorai.isg.action.SicUtil" %>
4......
5<portlet:actionURL name="addSic" var="addSicURL">
6    <aui:form action="<%= addSicURL.toString() %>" method="post">

Tomcat responds
 1
 2Caused by: org.apache.jasper.JasperException: Unable to compile class for JSP:
 3
 4An error occurred at line: 80 in the jsp file: /html/sic/view.jsp
 5addSicURL cannot be resolved
 677:
 778:
 879: <portlet:actionURL name="addSic" var="addSicURL">
 980:     <aui:form action="<%= addSicURL.toString() %>" method="post">
1081:             <aui:fieldset label="Add Sic Code">
1182:                     <aui:input name="code" />
1283:                     <aui:input name="parent" />
13Stacktrace:
14        at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
15        at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)


when I look in view.java I find the following, but dont have a way to enumerate _jspx_page_context.
I tried enumerating the application, page, session and request attributes but cant find the missing addSicURL

1
2java.lang.String addSicURL = null;<br/>
3addSicURL = (java.lang.String) _jspx_page_context.findAttribute("addSicURL");


thanks in advance, I've pulled nearlty all my remaining hair out on this one.

Chris
Marco Weiland
RE: Action Classes with MVCPortlet
May 27, 2011 8:59 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

hi,
at first i did not reproduce that, but please mention, that tags must be terminated.

<portlet:actionURL name="addSic" var="addSicURL"> --> <portlet:actionURL name="addSic" var="addSicURL" />

maybe that could produce the compile error with resolving ur addSicURL.

further i do not recommend u to initialize any variable with null values ( regarding to old scjp best practices), which does not effect ur problem ...

try to terminate the tag, if it is not working, plz post entire stacktrace
Marco Weiland
RE: Action Classes with MVCPortlet
May 27, 2011 9:26 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

for now i did reproduce ur problem, i think its the tag termination problem.

furhter, if u want to put the actionurl in the action attribute of the form, u have to define the aui button as type="submit", please have a look at the attachment to see actioncommandchaing working; i updated ur way
Attachments: liferay-mvc-portlet.zip (28.0k)
chris Rowse
RE: Action Classes with MVCPortlet
May 30, 2011 10:50 PM
Answer

chris Rowse

Rank: New Member

Posts: 21

Join Date: March 18, 2009

Recent Posts

Hi Marco,
Thanks for the quick reply.

Its probably not the tags - I have checked them thoroughly with both XML validators and manually. I should have warned that I posted only stubs of the code.

I am primarily interested in understanding how the names in the jsp, portlet.xml, Portlet.java and service.xml relate to one another and manage the URL dynamically. This, I believe is where my misunderstanding and problem lies.

I have downloaded the examples from 'Liferay in Action' and can compile and run those. The error is therefore in my code, and I will figure it out and repost to this thread for future reference.

Many thanks for your trouble.

Chris
Brian Scott Schupbach
RE: Action Classes with MVCPortlet
November 17, 2011 1:28 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Is there a way to forward to a different .jsp file from the ActionCommand class ? I've setup multiple actions but I can't figure out how to forward to another .jsp file. Is this even possible to do from the PortletRequest object?

Thanks,

Brian
David Ross
RE: Action Classes with MVCPortlet
November 17, 2011 2:47 PM
Answer

David Ross

Rank: New Member

Posts: 19

Join Date: July 9, 2008

Recent Posts

Yes, I think this is what you want.

1
2
3public void myAction(ActionRequest request, ActionResponse response) {
4    response.setRenderParameter("jspPage", "/html/mypage.jsp");
5}


Thanks,

Dave
Brian Scott Schupbach
RE: Action Classes with MVCPortlet
May 24, 2012 1:06 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Thanks!
Brian Scott Schupbach
RE: Action Classes with MVCPortlet
December 5, 2012 8:10 AM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Is it possible to forward to another action class while in a separate one?

Thanks,

Brian
Marco Weiland
RE: Action Classes with MVCPortlet
December 5, 2012 10:28 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

you can do it with the actioncommandchain, i think.

<portlet:actionURL var="actionCommandUrl">
<portlet:param name="<%=ActionRequest.ACTION_NAME %>" value="Article, Order, Balance"></portlet:param>
</portlet:actionURL>


Where ArticleActionCommand, OrderActionCommand and BalanceActionCommand are different actionclasses inside the
actionpackage.
Brian Scott Schupbach
RE: Action Classes with MVCPortlet
December 5, 2012 2:27 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Thanks, Marco! That is good to know.

Brian
Tanaji Londhe
RE: Action Classes with MVCPortlet
January 15, 2013 4:56 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 196

Join Date: April 25, 2012

Recent Posts

Hi All,
Is it possible to use my custom method name instead of using
public boolean processCommand(PortletRequest actionRequest, PortletResponse actionResponse)
throws PortletException {
-------------------------
}

e.g I want to separate this method into another action class from my portlet class.
public void myActionMtd(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
---------------------------
}
I have done this by using ActionCommand interface, but i want to use my custom name for that method instead of processCommand.
Marco Weiland
RE: Action Classes with MVCPortlet
January 15, 2013 5:06 AM
Answer

Marco Weiland

Rank: Junior Member

Posts: 26

Join Date: October 28, 2007

Recent Posts

from my point of view, thats breaking the nice encapsulation and separation of concerns the actioncommand pattern follows. looking at the implementation of the actioncommand i dont find any way to do that; let me know, if you find something, but that possibility will cause some method overload like in portletclass imho.
Tanaji Londhe
RE: Action Classes with MVCPortlet
January 15, 2013 9:48 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 196

Join Date: April 25, 2012

Recent Posts

Hi Macro,
Thanks for reply, sure I will update, if I get solution for this problem.