Dashboard > WebWork 1 > WebWork CookBook > Populate Form Bean and access its value
  WebWork 1 Log In View a printable version of the current page.  
  Populate Form Bean and access its value
Added by Hani Suleiman, last edited by Dick Zetterberg on Oct 24, 2006  (view change)
Labels: 
(None)

First off, if you're coming from Struts, you may feel more comfortable using FormBeans instead of using the Action as your form bean. Be aware, though, that in Webwork you DO have the option of having the properties directly in the Action class. If you want to use a FormBean, 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:

<!-- This will call getMyBean() on your action and put it on the top of the value stack ->
<webwork:property value="myBean">
<!- This will call getName() on your TestBean and print it to the page -->
The name is: <webwork:property value="name"/>
</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.

myBean/name by using this techinque for string type field I got Numberformat exception

Posted by Anonymous at Aug 16, 2004 04:12 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators