Search code examples
spring-mvcportletliferay-6

simple Spring portlet not working at Action mapping at liferay 6.2


A Simple portlet which is functioning properly at LifeRay 6.0 and Open Portlet Container but when I deploy to Liferay 6.2 it breaks at action mapping. I found the two issues at debugging . 1) the form data is not available (not populated) at action method 2) can not able to go to render method with parameter using setRenderParameter

Appreciate any help in advance.

Code sample as follows - not included the 2nd option (i.e setRenderParamer)

<portlet:defineObjects/>
<portlet:actionURL var="doFormActionURL">
   <portlet:param name="action" value="doFormAction" />
</portlet:actionURL>



  <form:form name="form" modelAttribute="someObject" method="post"  action="${doFormActionURL}" htmlEscape="false" >
   <table>
  <tr>
    <td><form:input path="id" /></td>
  </tr>
  <tr>
    <td><form:input path="name" /></td>
  </tr>
   </table>
<input type="submit" value="Just do it" />
 </form:form>

in controller

@Controller
@RequestMapping("VIEW")
public class ControllerMain
{

@RenderMapping
public String setModelAndView(PortletRequest request, Model model) {

    model.addAttribute("someObject", new SomeObject());
    return "home";
 }

@ActionMapping(params = "action=doFormAction")
public void doFormAction(@ModelAttribute ("someObject") SomeObject someObject, ActionRequest request) {
    String strname = request.getParameter("name");
    System.out.println("someObject : "+someObject.toString());
    System.out.println("name : "+strname);


}

In context

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- property name="cache" value="true" /-->
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="requestContextAttribute"><value>rc</value></property>
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

output :

someObject : 0 null null name : null

Does any one try spring on liferay 6.2 . Please share your experiences


Solution

  • But found some changes in liferay-portlet.xml of Sample Spring portlet from the github code of Liferay plugins.

    Try below changes. Set to false in your liferay-portlet.xml and try again by deploying the portlet.

    <portlet>
        <portlet-name>welcome</portlet-name>
        <requires-namespaced-parameters>false</requires-namespaced-parameters>
    </portlet>
    

    Reference taken from Sample Spring Portlet code from Liferay github code. LR 6.1 - https://github.com/liferay/liferay-plugins/blob/6.1.x/portlets/sample-spring-portlet/docroot/WEB-INF/liferay-portlet.xml

    LR 6.2 - https://github.com/liferay/liferay-plugins/blob/6.2.x/portlets/sample-spring-portlet/docroot/WEB-INF/liferay-portlet.xml