Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can you have a composition in an ActionForm ?

Status
Not open for further replies.

petraNemcova

Programmer
Oct 24, 2006
1
US
Hi there,

I wonder if it's to create a form bean with composition. I mean, assuming I have the following 2 classes:
AccountInformation ( fname, lname...)
CreditCard (number, type...)

I would like to know if I can create a form, registration, that is composed from AccountInformation and CreditCard???

it will look like this:
class Regitration
AccountInfomration accountInfo;
CreditCard creditCard;

So...
1. is it possible to do that?
2. if yes, how would the registration.jsp page will look like?

If it was a regular form, it would have been:

<td>
<fmt:message key="register.creditcard.number"/>
</td>

<td>
<html:text property="ccNumber"
size="30"
maxlength="30" />
<html:errors property="ccNumber" />
</td>

what comes in the property (i tought creditCard.number but that doesn't work)

thanks for any advise.
 
The "property" attribute in your <html:text... tag will try to map to a getter method within your form called getCcNumber().

The following should get you what you're looking for:

Code:
...
<td>
    <html:text property="ccNumber"
...

in the form class...

public String getCcNumber() {
     return creditCard.number;
}

public void setCcNumber(String ccNumber) {
      this.creditCard.number = ccNumber;
}

As long as your getter and setter methods are named correctly, you should be able to use any type of composite class for your form.

-G

p.s. If getCcNumber() doesn't work, try getccNumber(). There is a definite syntax for getter/setter capitalization.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top