• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to implement pojo to web form mapping in struts2

 
Ranch Hand
Posts: 42
Android Google Web Toolkit Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I've been looking for a decent way to map a pojo to a web form, and in the struts2 release info you can read "POJO forms - No more ActionForms! Use any JavaBean to capture form input or put properties directly on an Action class. Use both binary and String properties!". Does anybody know of an online example concerning this? It would be nice to automatically populate my pojos directly with web input somehow.

Thanks a whole lot!
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you want to look into the ModelDriven interface

Have your action implement ModelDriven this requires having a method

T getModel()

where T is the domain model you want populated. Now when your request comes in, it will call the getters and setters on the return from getModel instead of directly on the action. (any property not found on the model will fall back to trying to find that property on the action.)

Often you'll also want to pair this with the Preparable interface. Under the standard/default interceptor stack, one of the key section does "params; prepare; params". The first params call will throw all the parameters onto the action (that have properties there). Prepare can then be used to initialize either a new model object, or grab one from the DB based on the set parameters on hte action, the following params interceptor will set the parameters onto the model action. This normally reduces the execute method for Create/update type actions to a simple call to save the object with no other object retrieveal/setters needing to be used.

I'm not seeing any good/complete examples on-line right now. But both of the released Struts 2 books ( "Practical Apache Struts2 Web 2.0 Projects" and "A Tutorial: Struts 2 Design and Programming") have good examples of this.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic