Title: RE: [OS-webwork] how to access bean property?

Thanks, for the help Jason, Great explanation. It’s working now and I’m back on my way to happily exploring more stuff =D

 

Regards,

-Andre Mermegas

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Jason Carreira
Sent: Friday, January 31, 2003 9:51 PM
To: [EMAIL PROTECTED]
Subject: RE: [OS-webwork] how to access bean property?

 

Andre,

You'll want to do ActionContext.getContext() instead of new ActionContext().

ActionContext.getContext() gets the ThreadLocal instance which is populated by the ServletDispatcher.

You'll probably also want to maintain a reference to your TestBean :-)

Here's an example:

public class TestAction extends ActionSupport {
    private TestBean myBean;

    public TestBean getMyBean() {
        return myBean;
    }

    public void setMyBean(TestBean myBean) {
        this.myBean = myBean;
    }

    protected String doExecute() throws Exception {
        myBean = new TestBean();
        BeanUtil.setProperties(ActionContext.getContext().getParameters(), myBean);
        return SUCCESS;
    }
}

Then, in your success.jsp, which is mapped as the success result of TestAction in the views.properties or actions.xml (see the docs for how to configure actions and view mappings), you can do this:

<webwork:property value="myBean"> <!-- This will call getMyBean() on your action and put it on the top of the value stack -->

The name is: <webwork:property value="name"/> <!-- This will call getName() on your TestBean and print it to the page
</webwork:property>

This is a good way to do it if you have several parameters from the TestBean that you want to display, but, if you have just one, like in this case, it's probably better to do this:

<webwork:property value="myBean/name"/>

Which will call getMyBean.getName() and print that out to the page.

Hope that helps.

I've also put this up on the Wiki:

http://www.opensymphony.com:8668/space/How+do+I+populate+a+form+bean+and+get+the+value+using+the+taglib%3F

 -----Original Message-----
From:   [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andre Mermegas

Sent:   Friday, January 31, 2003 9:00 PM
To:     [EMAIL PROTECTED]
Subject:        [OS-webwork] how to access bean property?

Hey all,
If I’m doing something like:

In my Action.doExecute()
ActionContext ac = new ActionContext(); BeanUtil.setProperties(ac.getParameters(),new TestBean());

TestBean has one property "name".

How do I access the "name" property using the ww taglibs?

<ww:property value="name"/> doesn’t seem to be hitting the bean. <ww:property value="$name"/> does work, picking up the request parameter directly.

I thought maybe I had to name the object bean and then pass it in, like TestBean tb = new TestBean(); and then pass in the tb object and do <ww:property value="tb/name"/> but that doesn’t work either.

I've been looking through the docs, but I cant find it. I know I'm not hitting the Bean on the view.

Regards,
-Andre Mermegas




Regards,
-Andre Mermegas

 

Reply via email to