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.

24 comments:

Anonymous said...

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

Thanks
Vishnu

/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?
Thanks.

/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: http://content.liferay.com/4.3/doc/devel/liferay_4_portlet_development_guide/multipage/ch04.html

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(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:34)
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.serviceAction(Jsr168Dispatcher.java:415)
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.render(Jsr168Dispatcher.java:299)

/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!

--john

[INFO] [surefire:test]
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at org.apache.maven.plugin.surefire.SurefirePlugin.constructSurefireBooter(SurefirePlugin.java:594)
at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:391)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:447)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:333)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:126)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

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...

Hi,

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...

hello,

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
tkofford@ku.edu

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