Saturday 21 April 2012

Spring portlet and friendly URL

Hello,
    I did sample spring portlet with friendly routes. You can check it in this post.    
    Some info can be found here.
    Now let's create our portlet. First what we need form:

<%@ include file="/WEB-INF/pages/init.jsp"%>




 



 


Render 



 
  


  


  

 

 Second, some mapping at controller side:
  /**
   * Render.
   *
   * @return the string
   */
  @RenderMapping
  public String render() {
    return "view";
  }
  
  /**
   * Render action.
   *
   * @return the string
   */
  @RequestMapping(params = "action=render-page")
  public String renderPage() {
    return "render-page";
  }
  
  /**
   * Post action.
   *
   * @return the string
   */
  @RequestMapping(params = "action=submit")
  public void submitForm(final ActionRequest request) {
    return ;
  }

    And some configs for friendly URL mappings:
          1) At liferay-portlet.xml:

 spring-friendly-url
 /icon.png
 com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper
 spring-friendly-url
 com/paul/spring/sceleton/portlet/routes.xml
 false
 /css/main.css
 /js/main.js
 spring-friendly-url

          2) Add routes.xml to appropriate path:


 
  /action-route
  submit
 
 
  /render-route
  render-page
 


You can check source code here.

BR,
Paul

2 comments:

  1. Hello, thanks for the post.

    When I'm trying to import this project I got this:

    One or more constraints have not been satisfied.
    Cannot change version of project facet Dynamic Web Module to 2.5.

    And Null Pointer Exception when trying to deploy it.

    ReplyDelete
  2. Hi,
    Try to set Dynamic Web Module to version 3.0 into Porject properties - Project Facets under Eclipse IDE.

    Also you should have Maven installed because all dependencies are managed by it, you can check pom.xml for it.

    BR

    ReplyDelete