пятница, 25 октября 2013 г.

Spring Portlet MVC 3 on WebSphere Portal 7 cookbook

Here are my personal experience of Spring Portlet MVC 3 on WebSphere Portal 7.
  1. Spring profiles feature is not working in portlet environment.
  2. If your portlet use session for anonymous user, then you can enable it with container-runtime-option feature in portlet.xml like this:
         <container-runtime-option>
            <name>com.ibm.portal.public.session</name>
            <value>true</value>
        </container-runtime-option>
  3. Using client side aggregation and file upload doesn't work together. Switch you page to server side aggregation mode.
  4. When you first time add the event processing feature to portlets and deploy them to portal then you better switch the client side aggregation to server side aggregation. If you don't do this, then you cannot setup wires between your portlets.
  5. If you want your spring portlet to work in client side aggregation, then in your "form:form" tag set attribute htmlEscape="false".
  6. If you use Spring JDBC on WebSphere Portal  then  set connection extractor on your jdbc template like this:
    <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" />. This is especially useful if you need to work with special database types and\or stored procedures.
  7. Spring JDBC. Use jndi to create the datasource like this in application context:
    <jee:jndi-lookup id="myDataSource" jndi-name="jdbc/myds" cache="true" resource-ref="true" lookup-on-startup="false" proxy-interface="javax.sql.DataSource" />
  8. If you use JNDI resources in portlet then declare them in ibm-web-bnd.xml file like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-bnd
        xmlns="http://websphere.ibm.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
        version="1.0">
        <virtual-host name="default_host" />
        <resource-ref name="jdbc/mydb" binding-name="jdbc/mydb" />
    </web-bnd>
    Also don't forget to declare it in web.xml:
     <resource-ref>
        <res-ref-name>jdbc/mydb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
        <mapped-name>jdbc/mydb</mapped-name>
      </resource-ref>
  9. When declare portlet.xml use the following declaration:
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
        version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
            http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
        id="myportlet.war">.
    Take a look at id attribute. This is how WebSphere Portal distinguishes your war files on portal.
  10. When work with AJAX use @ResourceMapping annotation extensively.
  11. Use spring portlet mvc mock objects for unit testing your controllers.
  12. Use @ExceptionHandler annotation to process exceptions in controller.
  13. Some other interesting information can be found http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html .
Update 24.11.2013:
When using @ResourceMapping  method you can return string, that will map to the jsp, so you can conveniently serve jsp content.

Комментариев нет:

Отправить комментарий