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