Monday, January 07, 2008

Struts 2 Portlet Tutorial

I have made available a new Struts 2 portlet tutorial in the Struts 2 Plugin Repository wiki. The tutorial is work in progress and is currently based on the 2.1.1-SNAPSHOT of Struts 2.

The tutorial is using the Struts 2 portlet archetype which includes much of the stuff I have written about in this blog to (hopefully) improve portlet developmet productivity.

Please try it out and let me know of any issues you encounter.


Anonymous said...

Could you please provide link for struts 2 app on JBoss Portal for download.


/Nils-H said...

The references to JBoss portal are from an old sample application. If JBoss Portal supports deployment of JSR168 portlets without extra deployment descriptors, you should be able to use the same war as produced by the tutorial. Otherwise, you will have to write the custom descriptors yourself.

Anonymous said...

Struts2 Portlet does not work with Liferay Portal. Could you please provide the default configuration files for Liferay Portal for Srtuts 2 sample?

/Nils-H said...

Struts 2 Portlet is a JSR168 framework, so it should work in any JSR168 compliant portal server. The deployment process for Liferay can be found in the Liferay documentation. This chapter may be particularly interesting:

Anonymous said...

I've copied the tutorial (or so I thought) and keep getting the following exception.

In DefaultActionProxy.prepare() it is not able to find the config for the action mappings. I have struts.xml in WEB-INF/classes directory but it doesn't seem to be getting loaded.

I'm running on Tomcat 5.5 and Vignette Application Portal 7.3. Any advice??

There is no Action mapped for namespace /view and action name index. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.serviceAction(
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.render(

/Nils-H said...

My guess is that you have an error at server startup, so the configuration is not loaded properly. Hard to say with this little information. Please take it to the struts user list if you require further help.

john said...

Thanks for the great tutorial!

I found that I had to change the signature of the setParameters method in EditBookmarkAction to comply w/ the ParameterAware interface.

One question though:

I'm trying to package up to use w/ JetSpeed and find that maven is failing throwing a NPE in surefire:test (Stack trace listed below). Any idea what the problem is?

Thanks again for your really helpful tutorial!


[INFO] [surefire:test]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
at org.apache.maven.plugin.surefire.SurefirePlugin.constructSurefireBooter(
at org.apache.maven.plugin.surefire.SurefirePlugin.execute(
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(
at org.apache.maven.DefaultMaven.doExecute(
at org.apache.maven.DefaultMaven.execute(
at org.apache.maven.cli.MavenCli.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.codehaus.classworlds.Launcher.launchEnhanced(
at org.codehaus.classworlds.Launcher.launch(
at org.codehaus.classworlds.Launcher.mainWithExitCode(
at org.codehaus.classworlds.Launcher.main(

siby said...

I have to deploy a struts 2 portlet in Liferay 4.4.2.Can anyone please help in this by providing me with a simple sample application so that I can understand the configuration files and make the changes accordimgly.

Max said...


We want to use a template framework with ours struts2 portlet2. We try tiles and sitemesh but nothing is working.

Do you have examples or solutions ?

Anonymous said...


please anyone help me.. i have done all things as you people had described above. But I am getting the exception "javax.portlet.UnavailableException: Unable to invoke portlet. Resource /PlutoInvoker/HelloPortlet unavailable for [Ljava.lang.String;@50a492 seconds."

/Nils-H said...

That's impossible to say without more information. Check your portlet.xml and pom.xml jetty configuration, and check your server logs for startup errors.

Anonymous said...

can u be more clear i didnt get u..

/Nils-H said...

As I said, without more information I can't help you. Check your configuration files for errors and check your server logs for error messages. If that's not clear enough for you, then I can't be of any assistance.

Anonymous said...

what corrections need to be done in the EditBookmark.action class???

/Nils-H said...

What's the error you get?

Anonymous said...

'class' or 'interface' expected

/Nils-H said...

Sounds like a copy & paste error.

Anonymous said...

error is this

com.mycompany.EditBookmarkAction is not abstract and does not override abstract method setParameters(java.util.Map java.lang.String,java.lang.Object ) in org.apache.struts2.interceptor.ParameterAware

/Nils-H said...

In that case, try removing the type information from the map-parameter in the setParameters method.

Anonymous said...

thanx finally i got the solution

Todd said...

Are there any known issues using the struts 2 session map in a portlet?

I keep seeing intermittent issues with my session dying in uportal.

Is it better practice to use PortletPreferences rather than the struts 2 session map?

Thanks in advance,
Todd Kofford

Nils-Helge Garli Hegvik said...

Not that I'm aware of, and not that has been reported. Have you tried deploying to a different container? If you can reproduce the issue, it would be helpful with a sample application I could use to debug in uPortal.

Web Design Quote said...

I haven't any idea for this struts 2 portlet before. But after the reading this i learn a lot from your post. Thanks for sharing.

Java said...

Thanks for the nice tutorial