Fórum

need to pass parameter values next to layout friendly URL as friendly url

Muhammad Taha, modificado 8 Anos atrás.

need to pass parameter values next to layout friendly URL as friendly url

Junior Member Postagens: 63 Data de Entrada: 01/05/12 Postagens Recentes
Hi guys,

I want the render URL of custom my portlet like below.
http://localhost:8080/group/group-name/layout-or-page-friendlyurl/parameter-value1/parameter-value2

to achieve this I created an ext project.
for com.liferay.portal.servlet.FriendlyURLServlet class, to overcome the resource not found exception. and I'm reading parameter values in my custom porltet without any issue.

if(friendlyURL.contains("/mylayoutfrienldyurl")){
friendlyURL=CharPool.SLASH+friendlyURL.split(String.valueOf(CharPool.SLASH))[1]+(friendlyURL.indexOf("/-/")>-1? "/-/"+friendlyURL.split("/-/")[1]:"");
}

and somehow I am not comfortable with ext plugin. Please suggest if you know any other way to achieve this.

Regards,
Mahammad
thumbnail
Chandan Sharma, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u

Junior Member Postagens: 63 Data de Entrada: 28/05/12 Postagens Recentes
Hi,

You can simply use the Servlet filter hook to do this instead of creating the ext project and a servlet. or if you want to use new struts action hook you can also do that the struts action hook will work as it is your servlet do and it will be a hook plugin..


Thanks
Chandan
Muhammad Taha, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u

Junior Member Postagens: 63 Data de Entrada: 01/05/12 Postagens Recentes
Hi Chandan,

First -- Thanks for your suggestions..
I really liked creating a new struts action using hook, wish my team likes that too. Actually I need to provide dynamically configurable preferences for business folks.. currently I have them provided as portlet preferences in configuration mode.

also there the URL will have more number of values separated with "/ " like http://localhost:8080/mystrutsaction/value1/value2/..../value-n

Can you also suggest if same or similar thing can be achieved using struts action or any other solution?

can you explain how servlet filter helps in my case.

Thanks
thumbnail
Punam Shah, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u (Resposta)

Regular Member Postagens: 117 Data de Entrada: 20/01/12 Postagens Recentes
Well, Passing number of parameter is not a best practices. Try to find some alternate solution rather then passing n-number of values from parameter.

Moreover, Here you cannot not achieve the same with the help of Struts Action.

Please refer : https://www.liferay.com/community/forums/-/message_boards/message/60733554 - have explained about Servlet-Filter usage.
Muhammad Taha, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u (Resposta)

Junior Member Postagens: 63 Data de Entrada: 01/05/12 Postagens Recentes
Thanks Shah,
it's very simple with url rewrite.
i placed below lines in \ROOT\WEB-INF\urlrewrite.xml.

<rule>
<from>^/mylayout/(.*)$</from>
<to>/web/mygroup/mylayout?params=$1</to>
</rule>
thumbnail
Punam Shah, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u

Regular Member Postagens: 117 Data de Entrada: 20/01/12 Postagens Recentes
But, With this will you be able to pass n-number of parameters dynamically ?
Muhammad Taha, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u

Junior Member Postagens: 63 Data de Entrada: 01/05/12 Postagens Recentes
yes.
when I have the above rule in urlrewrite.xml and i enter URL http://localhost:8080/mylayout/a/apple/shimla in browser

Here is the code in my portlet's doview.

String currentURL = PortalUtil.getCurrentURL(renderRequest); // currentURL = /web/mygroup/mylayout?params=a/apple/shimla

Thank you.
thumbnail
Punam Shah, modificado 8 Anos atrás.

RE: need to pass parameter values next to layout friendly URL as friendly u

Regular Member Postagens: 117 Data de Entrada: 20/01/12 Postagens Recentes
Cool !!! Thank s for sharing information !!!