Mr Weirdo
Mr Weirdo

Reputation: 590

Call portlet action from external application

I have liferay portal with some portlets. Portlet has for example some action:

@RenderMapping(params = "action=displayHome")
public String displayHome(final RenderRequest request, final RenderResponse response, final ModelMap map) {

    return "home";
}

Inside liferay I can use this action by and everything works fine. But! I have second application ( normal spring mvc hibernate etc) on which I need to call this action. Srsly I don`t know how to do this. Can anyone help me?

I created routes file with :

<route>
    <pattern>/test_pattern</pattern>
    <implicit-parameter name="action">testAction</implicit-parameter>

    <implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
    <implicit-parameter name="p_p_id">xxx_WAR_xxxportlet_INSTANCE_73iYU2pK0li</implicit-parameter>
    <implicit-parameter name="p_p_state">normal</implicit-parameter>
    <implicit-parameter name="p_p_mode">view</implicit-parameter>
    <implicit-parameter name="p_p_col_id">column-1</implicit-parameter>
    <implicit-parameter name="p_p_col_count">1</implicit-parameter>
</route>

And I have problem, that it is not working. Always send me to actual page -> Action is not called :/

Upvotes: 2

Views: 850

Answers (2)

Mr Weirdo
Mr Weirdo

Reputation: 590

solution : liferay-portlet.xml:

    <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
    <friendly-url-mapping>xxx_mapping</friendly-url-mapping>
    <friendly-url-routes>config/xxx-friendly-url-routes.xml</friendly-url-routes>
    <instanceable>false</instanceable>

routes in resources/config:

<routes>
    <route>
        <pattern>/displayXXXPattern</pattern>
        <generated-parameter name="action">displayXXX</generated-parameter>
        <implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
        <implicit-parameter name="p_p_mode">view</implicit-parameter>
        <implicit-parameter name="p_p_state">normal</implicit-parameter>
        <implicit-parameter name="p_p_id"xxx_WAR_dekraaquaportlet</implicit-parameter>
    </route>

</routes>

important-> when instanceable is set to false we don't need to pass instance ID -> In other case it will not work if we in p_p_id do not pass correct instance id (what is add, liferay don`t show any bugs or errors ).

in portlet we can turn off:

<init-param>
        <name>check-auth-token</name>
        <value>false</value>
    </init-param>

in other case we need to supress p_p_auth

Upvotes: 0

Milen Dyankov
Milen Dyankov

Reputation: 3052

  • Option 1 - copy the url from the page where you can use it and paste it in your Spring app. Downside - many things can change in the portal, resulting in url change and your application will not work anymore.

  • Option 2 - learn how URLs are constructed and generate one from your Spring app. Downside - portlet URL are complex and long (there is not enough space here to describe all options in details)

  • Option 3 - generate a Fiendly URL(s) for your portlet and use that in your Spring app. Downside - will stop working if you move the portlet to a different page)

  • Option 4 - don't use portlet alone, use local/remote service + portlet instead. Put your logic in local service, call it via portlet when local and via remote service form other apps (even mobile ones)

Upvotes: 1

Related Questions