can you have a composition in an ActionForm ?
can you have a composition in an ActionForm ?
(OP)
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.
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.
RE: can you have a composition in an ActionForm ?
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.