• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Can Struts transform httpRequest to Java Objects?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I know that Struts can transform an incoming http request to primitives and Strings - but can it also transform to Java Objects?

Other web frameworks like WebWork can do this using OGNL - and am wondering if Struts can do the same out of the box; or if not if there are any other external libraries that can provide this functionality?


thanks,

Jac
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about transforming request parameters to Object type instead of String?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With Struts1.x, it's recommended that you stick with Strings in your ActionForm and conversion of request parameters to objects is not supported. Struts 2, which is coming out soon, is based on WebWorks and will have all the features available in WebWorks. If this is important to you, you may want to switch to Struts 2 when it comes out. A pre-release version is available for download now at the Struts home page.
 
Jac Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merrill,

thanks for the reply - thats the answer I was hoping for!

After downloading the pre-release and reading through the documentation it reads as though you have to migrate the whole application from Struts 1 to Struts 2 -- do you know if this is the case or not? We have a large web-app and wont have time to convert the whole application across to Struts 2 - so I'm hoping theres a way to have both Struts 1 & 2 co-exist so we can migrate to Struts 2 gradually?


thanks again,

Jac
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that you do have to migrate the whole project. Struts 2 is substantially different from Struts 1, and I don't think they will both work together in the same web application.

Don't take my word for it, though. I'm just starting to investigate Struts 2 the same as you are. You may want to get on the mailing list and ask this question there.
 
Jac Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merrill,

good news, it looks like you can gradually migrate a codebase across from S1 to S2 within the same web container, as the migration strategy says "S1 and S2 can run side by side, within the same web application. Teams can implement new features in the latest version, and migrate older pieces as needed".

http://cwiki.apache.org/WW/migration-strategies.html


Jac
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have played with WebWork a little, and I agree that it handles object much better than Struts. It is handy to be able to declare fields of type Date or Integer and not have to jump through the hoops that Struts 1.x requires.

I will add that Struts can do some object population. For example, if you put this in your jsp:


Struts will try to populate the User object on your form with the value from the page. Something like this:


The setAge() method still should take a String and you have to make sure that getUser() does not return null (at least I think you do).

A few months ago I subscribed to the Struts mailing list, but I could not keep up with the traffic. The migration path from 1.x to 2.x was a topic discussed often. The discussion was that since WebWork used a filter mechanism and Struts used a Servlet mechanism it was likely that you could run both 1.x and 2.x pages in the same application. When the dust settles, I will be curious to see how easy it is and how much can be reused between the two sides.

I thought that on the opensymphony.com site you could read the STRUTS-DEV mailing list posts in a nice news group type interface, but I could not find it. This page lists a few sites that archive the Struts mailing lists: http://struts.apache.org/mail.html

- Brent
 
Jac Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,

thanks for the reply. The whole String oriented nature of Struts 1.x pretty much inhibits one from passing domain objects into the JSP, as per your example that "The setAge() method still should take a String". I guess you could always expose a setAge(String age) method on domain objects - but I'd prefer to keep domain objects clean.

I've been trying to find out if Struts 2 supports tiles - do you have any idea on this?


Jac
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gave a quick brown bag on WebWork a few months ago and that question was asked. I did not have an answer but it looked like Sitemesh (which I know very little about) is supported and provides much of the same functionality.

A quick search turned up this page about using Tiles with WebWork...I have to assume that it will apply to Struts 2.x.

http://raibledesigns.com/page/rd?entry=how_to_use_tiles_with

- Brent
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic