Foren

Problems with Freidnly URL and calling Actions

Stefan Petrushevski, geändert vor 9 Jahren.

Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Hello... I'm having issues with mapping friendly URL action to a method in the controller.

The route is recognized and the friendly url is 'built' right. I can see the friendly url in browser as http://.../help_support/-/topic/N, but when i click it, the method is the MVCPortlet class is not called.

Here is the route, the jsp part and the method in my MVC class:
http://pastebin.com/cAH0VrKb
thumbnail
Bijan Vakili, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Expert Beiträge: 375 Beitrittsdatum: 10.03.09 Neueste Beiträge
Shouldn't you have parameter like this?
"javax.portlet.action" and not "action"?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Tried that too... Didn't help.
thumbnail
Tina Agrawal, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Expert Beiträge: 297 Beitrittsdatum: 03.01.08 Neueste Beiträge
Can you try this -

<portlet:actionurl var="opentopicURL" name="openTopic">
    <portlet:param name="topicId" value="<%= t.getId().toString() %>" />
 </portlet:actionurl>


Tina
thumbnail
Tina Agrawal, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Expert Beiträge: 297 Beitrittsdatum: 03.01.08 Neueste Beiträge
Also make sure you dont have a processAction method in your class.

Tina
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
What do you mean? But I want to have action method in my portlet class to handle the request.

I'm done with the portlet class and the methods. Everything works fine, I now want to introduce friendly URLs.
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
I have done something similar but my code is slightly different then yours. Based on the pastebin... try these changes.

<route>
<pattern>/topic/{topicId:\d+}/</pattern>
<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
<implicit-parameter name="javax.portlet.action">openTopic</implicit-parameter>
</route>


<portlet:actionURL var="opentopicURL" name="openTopic">
<portlet:param name="topicId" value="<%= t.getId().toString() %>" />
</portlet:actionURL>


@ProcessAction(name="openTopic")
public void openTopic(ActionRequest request, ActionResponse response) throws Exception {
System.out.println("IN ACTION");
}


That worked for me.
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Thanks for the suggestion but this didn't help either.

I still get the rule matched and the links display with friendly URL but the action method in the portlet is not being fired.
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Suggestion. In your portlet class, override the doAction method and add a logging statement to see if it is getting there. That should at least tell you whether or not you are actually invoking an action (that maybe the annotation is messed up) or if you are going straight to the render phase?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
I overrode processAction and no, the Action matched by the FriendlyURL route is not firing action method (processAction) meaning it goes straight to render phase.

	@Override
	public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws java.io.IOException, javax.portlet.PortletException{
		System.out.println("ZZZ in Action!");
	}


Any ideas why is this happening? Maybe I need to make changes to the default FriendlyURL class?
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Stefan,

Apologies, the week got away from me. Are yo ustill struggling with this? If you are, can you send the url you are using again?

Also, if you remove the friendly URL configuration, does your action method fire?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Yes the methods work fine without friendlyURL. Apparently when I add the routes and they are matched, the action method is not fired.

I can't share the URL, it's private one. (If that's what you meant) emoticon

Sorry for the late reply.
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hey Stefan,

I didn't mean for me to go to the site or anything, I just mean to copy and paste the URL in here... delete the domain and port if you like. Also, it occurred to me that I once had a problem like this where I made the mistake and set the method type "GET" on the form which doesn't fire the actions. But since you have no issue when the Friendly URL is disabled, I am guessing that is not it.

If you can share with me the url (minus the domain and port) I can try to reproduce on my side.
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Here are the details:


before:
http://ws/testing?p_p_id=eGain_WAR_Egainportlet&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_count=1&amp;_eGain_WAR_Egainportlet_topicId=1338&amp;_eGain_WAR_Egainportlet_javax.portlet.action=openTopic
----
	liferay-portal.xml
	<friendly-url-mapper-class>
	com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper
	</friendly-url-mapper-class>
	<friendly-url-mapping>
		help-support
	</friendly-url-mapping>
	<friendly-url-routes>
		com/iwmn/egain/portlets/egain-portlet-friendly-url-routes.xml
	</friendly-url-routes>
----
	route:
	<route>
		<pattern>/topic/{topicId:\d+}/</pattern>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
		<implicit-parameter name="javax.portlet.action">openTopic</implicit-parameter>
	</route>
-----	
	jsp:
	...
	<portlet:actionurl name="openArticle" var="OpenArticleURL">
		<portlet:param name="articleId" value="<%= a.getId().toString() %>" />
	</portlet:actionurl>
	<li><a href="${OpenArticleURL}">&lt;%=a.getName() %&gt;</a></li>
	...
----
after:
http://dwww.vip.mk/testing/-/help-support/topic/1338/
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Just replied on the IRC channel, but can you try using

_eGain_WAR_Egainportlet_javax.portlet.action

for your implicit action mapping in the route file?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
I changed the rule as you suggested and now the links are not matched to it:

	<route>
		<pattern>/topic/{topicId:\d+}/</pattern>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
		<implicit-parameter name="_eGain_WAR_Egainportlet_javax.portlet.action">openTopic</implicit-parameter>
	</route>
thumbnail
Meera Prince, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 1111 Beitrittsdatum: 08.02.11 Neueste Beiträge
HI
Have a look into following article it may help you..

http://www.liferaysavvy.com/2014/06/liferay-friendly-url.html


Regards,
Meera Prince
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
you action url has a name of "openArticle" but your mapping is using "openTopic" -- was that just a typo? or are these out of synch?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Andew Jardine:
you action url has a name of "openArticle" but your mapping is using "openTopic" -- was that just a typo? or are these out of synch?



Yes ... it's a typo. I have the openTopic method defined in my portlet class and using that name in my jsp page..
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
Andew Jardine had the time and nerves to go over this again in great detail and we finally have a solution emoticon. Tnx Andrew!

The route that works is:

<route>
<pattern>/topic/{topicId}</pattern>
<implicit-parameter name="javax.portlet.action">openTopic</implicit-parameter>
<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
</route>


The whole issue was the \d+ in the pattern <pattern>/topic/{topicId:\d+}</pattern>. Anyone has idea why?
Stefan Petrushevski, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

New Member Beiträge: 13 Beitrittsdatum: 28.04.14 Neueste Beiträge
The issue was the actual variable name 'topicId'. I switched it do 'tId' and the pattern works fine now.


	<route>
		<pattern>/topic/{tId:\d+}</pattern>
		<implicit-parameter name="javax.portlet.action">openTopic</implicit-parameter>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
	</route>
thumbnail
Bijan Vakili, geändert vor 9 Jahren.

RE: Problems with Freidnly URL and calling Actions

Expert Beiträge: 375 Beitrittsdatum: 10.03.09 Neueste Beiträge
Just to be sure, it works without the route? And when add route, the issue occurs, right?