[S2] Data entry form for nested beans
I have the following Bean, which represents an Account I am working on: public class PaymentBean { String acctNumber; DebtorBean debtor; // The person who owes money(s). MAkes sense to use this bean as I used it throughout the app PayorBean payor; // The person making the payment(s) Same reason as above. CreditCardBean cc; // The card used to make the payment(s). SinglePaymentBean[] singlePayment; // A bunch of singlePayments to be made, with a $ amount, a fee, and a date } 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? 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. Or is there a correct way to represent this structure inside of my form so that the data goes directly into the appropriate subBean upon form submittal? I went through the person showcase, and thought I was on the right track, but based upon that simple example, i was never able to get the data from the form to the bean. Yes, I can get errors to you from the experiment if it helps. I could supply jsp and action code examples, but they are all just failed tests at this point. I am so in need of direction on how best to design and implement this base concept in Struts 2. Any, ANY, advice and help would be greatly appreciated. Skip Hollowell - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] Data entry form for nested beans
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: s:textfield name=paymentBean.debtor.firstName / 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]