Showing posts with label portlet. Show all posts
Showing posts with label portlet. Show all posts

Monday, 15 March 2010

Integrate struts2-jquery and portlets

In this FAQ we can see how to install the struts2-jquery plugin, but we have to make some little changes if we are developing porlets:

1.Add the next servlet-mapping to the web.xml file:
<servlet>
        <servlet-name>struts2servlet</servlet-name>
        <servlet-class>org.apache.struts2.dispatcher.ng.servlet.StrutsServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>struts2servlet</servlet-name>
        <url-pattern>*.action</url-pattern>
</servlet-mapping> 
<servlet>
        <servlet-name>struts2Resources</servlet-name>
        <servlet-class>org.apache.struts2.dispatcher.ng.servlet.StrutsServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>struts2Resources</servlet-name>
        <url-pattern>/struts/*</url-pattern>
</servlet-mapping> 

This could be done by a filter-mapping too, but with filter-mapping we can have some problems in a Websphere server.

2.Define some pakage in the struts2 config to manage the ajax request
<package name="ajax" extends="json-default" namespace="/ajax">
...
</package>

3.To make a valid ajax request from the portlet, all the request must be as the next examples:
<form id="compraVentaForm" action='<s:url value="/ajax/compraVentaSave.action"/>'  method="post">
...
</form>
<s:url id="ordenesActivasResultado" value="/ajax/ordenesActivas.action"/>
<sj:div href="%{ordenesActivasResultado}" indicator="indicator" onCompleteTopics="completeDiv" reloadTopics="reloadDiv">
 <img id="loading" src="<s:url value='/img/ajax-loader.gif'/>" alt="Loading..."/>
</sj:div>

Wednesday, 19 August 2009

Developing Portlets using Eclipse. Part I

On this entries I will show you how to develop portlets, create and debug portlets, in Eclipse with the WTP plugin and Jetspeed-2 . Lately I will deploy those portlets for the Websphere Portal 6.1.

Some frameworks that I will use:
The environmentLocations that I use to use with Linux:
  • /data/eclipse/eclipseWTP -> here's the eclipse.exe
  • /data/eclipse/eXtra/Jetspeed-2.2.0 -> for Jetspeed
  • /data/workspace/groupA -> for development
Locations that I use to use with Windows:
  • c:\eclipse\eclipseWTP -> here's the eclipse.exe
  • c:\eclipse\eXtra\Jetspeed-2.2.0 -> for Jetspeed
  • c:\apps\workspace\groupA -> for developement
OK, now it's time to configure our eclipse:
  • Add a new server runtime. In eclipse "Preferences/Sever/Runtime Enviroment", add "Apache Tomcat v6.0" and use the installation of the Jetspeed as "Tomcat installation directory "/data/eclipse/eXtra/Jetspeed-2.2.0".
  • Configure the new server. Here's the most important thing, just after we create the new server, we have to edit the server configuration and then "use Tomcat installation" (the default could be "use workspace") and change the "deploy path" to point where we had the "webapps" in our Jetspeed installation "/data/eclipse/eXtra/Jetspeed-2.2.0/webapps". Also we have to change the timeout to start the server.

The portlet

In eclipse, create a new Dynamic Web Project with target runtime: "Jetspeed 2.2.0". Project name: Struts2PortletTemplate :)
OK, now change the project properties, in "Java build path"... I like this "Struts2PortletTemplate/WebContent/WEB-INF/classes" as the output folder.

This will be the web.xml: