http://wiki.opensymphony.com/space/Xwork+Interceptors
To summarize, declaring something as ModelDriven just puts it on the top of the value stack so when your parameters get resolved, the model gets populated.
For example:
public class Application { private String firstName; public String getFirstName() { return this.firstName ; } public void setName(String firstName ) {this.firstName = firstName;} }
public class ApplicationAction implements ModelDriven { public Application model = new Application(); public Object getModel() { return this.model ; } }
so, if I have
<ww:textfield name="firstName"/>
I would expect model.getFirstName() to return the value the user entered. This is very akin to a struts ActionForm with the exception you're not required to extend a concrete class.
If you're still having trouble, could you post the tags here that seem to be giving problems?
Cheers!
M
Peter White wrote:
I'm at the last major hurdle on my current WW2 proof of concept application and I am absolutely stuck at trying to populate my object model from the results of a submitted web page. A simplified version of my action looks like this:
*public** class* SubmitApplication* extends* ActionSupport {
* private* Application app; /* has public getters/setters */
* ** public* String doExecute()* throws* Exception {
OgnlValueStack stack = ActionContext.getContext().getValueStack();
log.debug("ValueStack firstName: " + stack.findValue("firstName"));
/* Figured this would be easier than getting the data straight from
the HttpServletRequest but you'll see it's not quite doing what
I expect...
*/
Map map = ActionContext.getContext().getParameters();
* for* (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry)iterator.next();
log.debug(entry.getKey() + ": " + entry.getValue());
}
HttpServletRequest request = ServletActionContext.getRequest();
log.debug("FIRSTNAME: " + request.getParameter("firstName"));
/* Sets app = a deep copied app template from the DB */ loadTemplate();
/* sets boolean template to false so we know it's a real app
and not an application template */
app.setTemplate(*false*);
List components = app.getComponents(); Iterator iter = components.iterator();
*** while* (iter.hasNext()) {
Object o = iter.next();
log.debug("Component ClassName: " + o.getClass().getName());
((AbstractComponent)o).processForm(stack);
}
*** return* SUCCESS;
}
}
The class that I'd ideally like to automatically populate looks something like this:
*public** class* Application* implements* Serializable {
/* has public getters/setters with AbstractComponent as parameter */
*** private* List components =* new* ArrayList();
}
The fields in my web form are all WW2 UI tags since I thought this was necessary for validation and auto population of fields. Each "component" is mapped to a different set of fields on the form. I figured I could use a ModelDriven interceptor to populate my model but I got stuck and trying to figure out what to name the fields within the components so they'd get populated (I had no problem populating the app's attributes, just the components caused me headaches).
After giving up on ModelDriven, I figured I'd just get the valueStack and pass it to each component's processForm method since the component would know which fields to grab. Unfortunately, I'm Ognl impaired and ended up with null values no matter what I named my fields or how I tried to reference them. After failing miserably with the valueStack, I figured I'd just get the parameter map and pass that to processForm but but I get memory addresses instead of string values out of the map (firstName=[Ljava.lang.String;@1353249). So, I guess only thing that leaves me with is request.getParameter() - works like a charm!
I'd rather work at a higher level of abstraction than directly with the request but that's what I'll do if that's what it takes to meet my Monday deadline (yeah, I'll be working all weekend…).
So, my questions are: Does anyone know how I should name the fields in my JSP to get this thing working with the ModelDriven interceptor or OgnlValueStack? If not, is there a WW2/XWork method I can call to translate the addresses in the map to a useable value?
Thanks in advance! Peter
------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork