Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Action Classes with MVCPortlet Marco Weiland 8 aprile 2011 22.55
RE: Action Classes with MVCPortlet Lalit Jugran 9 aprile 2011 2.01
RE: Action Classes with MVCPortlet Marco Weiland 9 aprile 2011 10.04
RE: Action Classes with MVCPortlet Deb Troxel 9 aprile 2011 10.11
RE: Action Classes with MVCPortlet Marco Weiland 9 aprile 2011 23.46
RE: Action Classes with MVCPortlet Marco Weiland 11 aprile 2011 0.15
RE: Action Classes with MVCPortlet Deb Troxel 11 aprile 2011 9.13
RE: Action Classes with MVCPortlet Marco Weiland 11 aprile 2011 13.09
RE: Action Classes with MVCPortlet Deb Troxel 11 aprile 2011 13.49
RE: Action Classes with MVCPortlet Corentin R 17 maggio 2011 5.24
RE: Action Classes with MVCPortlet Marco Weiland 18 maggio 2011 11.57
RE: Action Classes with MVCPortlet Marco Weiland 18 maggio 2011 11.58
RE: Action Classes with MVCPortlet chris Rowse 26 maggio 2011 13.24
RE: Action Classes with MVCPortlet Marco Weiland 27 maggio 2011 8.59
RE: Action Classes with MVCPortlet Marco Weiland 27 maggio 2011 9.26
RE: Action Classes with MVCPortlet chris Rowse 30 maggio 2011 22.50
RE: Action Classes with MVCPortlet Brian Scott Schupbach 17 novembre 2011 13.28
RE: Action Classes with MVCPortlet David Ross 17 novembre 2011 14.47
RE: Action Classes with MVCPortlet Brian Scott Schupbach 24 maggio 2012 13.06
RE: Action Classes with MVCPortlet Brian Scott Schupbach 5 dicembre 2012 8.10
RE: Action Classes with MVCPortlet Marco Weiland 5 dicembre 2012 10.28
RE: Action Classes with MVCPortlet Brian Scott Schupbach 5 dicembre 2012 14.27
RE: Action Classes with MVCPortlet Tanaji Londhe 15 gennaio 2013 4.56
RE: Action Classes with MVCPortlet Marco Weiland 15 gennaio 2013 5.06
RE: Action Classes with MVCPortlet Tanaji Londhe 15 gennaio 2013 9.48
Marco Weiland
Action Classes with MVCPortlet
8 aprile 2011 22.55
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
9 aprile 2011 2.01
Risposta

Lalit Jugran

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 25 luglio 2010

Messaggi recenti

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
9 aprile 2011 10.04
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
9 aprile 2011 10.11
Risposta

Deb Troxel

Punteggio: Junior Member

Messaggi: 81

Data di Iscrizione: 22 febbraio 2010

Messaggi recenti

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
9 aprile 2011 23.46
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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

thank u very much!
Marco Weiland
RE: Action Classes with MVCPortlet
11 aprile 2011 0.15
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
11 aprile 2011 9.13
Risposta

Deb Troxel

Punteggio: Junior Member

Messaggi: 81

Data di Iscrizione: 22 febbraio 2010

Messaggi recenti

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
11 aprile 2011 13.09
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
11 aprile 2011 13.49
Risposta

Deb Troxel

Punteggio: Junior Member

Messaggi: 81

Data di Iscrizione: 22 febbraio 2010

Messaggi recenti

Nice! Thanks Marco. emoticon
Corentin R
RE: Action Classes with MVCPortlet
17 maggio 2011 5.24
Risposta

Corentin R

Punteggio: Junior Member

Messaggi: 92

Data di Iscrizione: 18 giugno 2010

Messaggi recenti

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
18 maggio 2011 11.57
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
Allegati: liferay-mvc-portlet-6.1.0.1.war (19,7k), liferay-mvc-portlet.zip (27,9k)
Marco Weiland
RE: Action Classes with MVCPortlet
18 maggio 2011 11.58
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

upd
chris Rowse
RE: Action Classes with MVCPortlet
26 maggio 2011 13.24
Risposta

chris Rowse

Punteggio: New Member

Messaggi: 21

Data di Iscrizione: 18 marzo 2009

Messaggi recenti

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
27 maggio 2011 8.59
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
27 maggio 2011 9.26
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
Allegati: liferay-mvc-portlet.zip (28,0k)
chris Rowse
RE: Action Classes with MVCPortlet
30 maggio 2011 22.50
Risposta

chris Rowse

Punteggio: New Member

Messaggi: 21

Data di Iscrizione: 18 marzo 2009

Messaggi recenti

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
17 novembre 2011 13.28
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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
17 novembre 2011 14.47
Risposta

David Ross

Punteggio: New Member

Messaggi: 19

Data di Iscrizione: 9 luglio 2008

Messaggi recenti

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
24 maggio 2012 13.06
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

Thanks!
Brian Scott Schupbach
RE: Action Classes with MVCPortlet
5 dicembre 2012 8.10
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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

Thanks,

Brian
Marco Weiland
RE: Action Classes with MVCPortlet
5 dicembre 2012 10.28
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
5 dicembre 2012 14.27
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

Thanks, Marco! That is good to know.

Brian
Tanaji Londhe
RE: Action Classes with MVCPortlet
15 gennaio 2013 4.56
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

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
15 gennaio 2013 5.06
Risposta

Marco Weiland

Punteggio: Junior Member

Messaggi: 26

Data di Iscrizione: 28 ottobre 2007

Messaggi recenti

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
15 gennaio 2013 9.48
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

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