Hi Matt,

Thanks for the pointer but the write up was insufficient for my needs. I was
able to get ModelDriven to work with my Application class' member variables
but I also need to be able to set the member variables of contained objects.
Sorry to switch context on you be this example might illustrate what I'm
trying to do better:

public class Zoo {
    private List animals;

    public List getAnimals() { return this.animals; }
    public void setAnimals(List animals) {this.animals = animals;} }

public class ZooAction implements ModelDriven {
    public Zoo model = new Zoo();
    public Object getModel() { return this.model ; } }

In this case, the list would be an ArrayList of AbstractAnimal. For the sake
of this example, let's say that our List contains 2 members, an instance of
"Monkey" and an instance of "Cheetah". When my web form is submitted, it
will contain a "zooConfigId" which allows me to retrieve the exact model
that was used to generate the web form being submitted.

So, what I'd liked to be able to do is something like this:

public class ZooAction implements ModelDriven {
    public String zooConfigId; // Has getters/setters and is correctly auto
populated by WW.
    public Zoo model;
    public Object getModel() { return this.model ; }
    public String doExecute() throws Exception {
        model = loadZoo(zooConfigId); // Loads a deep copied clone of the
appropriate Zoo template
        ...do something with the model now...
    }
}

Given what I'd like to do, is it possible to configure XWork/WW to populate
the model *after* I've had a chance to load it in my doExecute() or some
other mechanism? i.e. Can I do this by writing my own interceptor which
executes before ModelDriven?

If this is possible, how do I name my fields so they map to the contained
derived Animal objects? For example, I'd like to name the fields something
along the lines of:

<ww:textfield name="model.animals[0].Monkey.name"/>
<ww:textfield name="model.animals[1].Cheetah.name"/>

In this case, I need to figure a way to map the Monkey's name field to the
name field contained within the Monkey instance in my List of Animal and I
need to do the same thing for the Cheetah's name, etc...

I hope this is a more understandable explanation of what I'm trying to do.
If it's possible to configure my application so ModelDriven works with this
object hierarchy I'd be ecstatic. If not, I'd be happy to get a definitive
"No, it can't be done with ModelDriven" answer so I can stop wasting my time
with ModelDriven and move ahead in a different direction.

Thanks for all the help guys!
Peter

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Matt Ho
> Sent: Friday, October 10, 2003 11:23 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [OS-webwork] Need help with WW2 form processing...
> 
> I'm not sure exactly of the problem you're having.  However, 
> there's a write up on model driven on
> 
>       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
> 




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

Reply via email to