On 4/23/07 1:03 PM, "Skip Hollowell" <[EMAIL PROTECTED]> wrote:
> I have the following Bean, which represents an Account I am working on:
>
> public class PaymentBean {
> String acctNumber;
> DebtorBean debtor;
> PayorBean payor;
> CreditCardBean cc;
> SinglePaymentBean[] singlePayment;
> }
>
> I have tried several different ways in my AccountAction to populate this
> bean from the data entered on the form. I can, of course, read
> multiple layers down inside my nested beans and display it in a JSP, but
> how I do I allow for data entry into them?
Yes, reading is more intuitive than writing into the data model.
I don't know how others do this, but this is what I do.
You have the PaymentBean which has dependencies. So, in my action's
prepare() method I would instantiate those beans and wire them together.
Public class MyAction extends ActionSupport implements Preparable {
private PaymentBean paymentBean;
public void prepare () {
this.paymentBean = new PaymentBean ();
paymentBean.setDebtor (new DebtorBean () );
// Continue this pattern of instantiating and wiring.
}
...
public PaymentBean getPaymentBean() {
return this.paymentBean;
}
...
}
There might be a way of doing this using the type conversion support, but
I'm personally not familiar with it. (I use factory methods to produce my
various prototype entities, so my controller layer is not tied to a
particular domain model implementation.)
To fill in the DebtorBean.firstName property, if there was one, would be
like this in the JSP:
That will OGNL expression will get the paymentBean from your action, call
getDebtor() on the paymentBean, then call setFirstName() on the DebtorBean.
> Does one create a simple form that has a bunch of simple text fields,
> and the action then uses all of these to populate the pieces of the
> various beans that make up Payment Bean.
You could but it is cumbersome and error prone in my opinion.
Mark
--
Mark Menard
Business: http://www.vitarara.net/
Personal: http://www.vitarara.org/
Mark's Struts 2 Cookbook: http://www.vitarara.org/cms/struts_2_cookbook
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]