You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by alanbrown <al...@pacbell.net> on 2003/09/16 08:17:40 UTC

FormBean question...

I am using 2 different beans to populate 2 forms on 2 pages.  However
some of the fields have the same names, as both customers and contacts
have addresses and both companies and contacts have descriptions and
notes associated with them.  After entering a company the user is
prompted to enter some details of a person within that company with,
hopefully, some of the form already filled out (the address fields have
default values for instance taken from the company info that was just
entered).  However the description field and the notes field are also
filled out with the values entered in the addCompany.jsp page and this
should not happen.
 
This seems very strange as I've got 2 different formBeans used to
populate the fields.  Here are the relevant parts of the strutsconfig
file.
 
        <form-bean
            name="companyForm"
            type="com.alan.crm.forms.CompanyForm">
        </form-bean>
        <form-bean
            name="contactForm"
            type="com.alan.crm.forms.ContactForm">
        </form-bean>
 
and.
 
        <action
            path="/addCompany"
            type="com.alan.crm.controller.AddCompanyAction"
            scope="request"
            name="companyForm"
            validate="true"
            input="/add/company.jsp">
            <forward name="Success" path="/addContactView.do"/>
            <forward name="Failure" path="/add/company.jsp"/>
        </action>
        <action
            path="/addContactView"
            type="com.alan.crm.controller.PrepareAddContactAction"
            scope="request"
            name="contactForm"
            validate="false">
            <forward name="next" path="/add/contact.jsp"/>
        </action>
 
As you can see they are using different types of form so I find it very
odd that the description and note fields are pre populated as well as
the address.  The way I've tried to populate the fields I want
pre-polulated is by having the following code at the end of my
addCompanyAction class
 
        ContactForm contactForm = new ContactForm(new
Integer(companyId).toString(), companyForm.getAddress());
        request.setAttribute("addContactForm", contactForm);
        return mapping.findForward("Success");
 
and then, when forwarded to the prepareAddContactAction class, have the
following code.
 
    public ActionForward executeAction(ActionMapping mapping,
                                       ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response,
                                       UserContainer container) {
        ContactForm contactForm =
(ContactForm)request.getAttribute("addContactForm");
        //if "addContactForm" is not null in the request scope then we
should use it to populate our form.
        form = contactForm == null? form : contactForm;
        ((ContactForm)form).setContactStatus("open");
        return mapping.findForward("next");
   }
 
But somehow I'm getting all the companyForm's fields populating the
contact form.   IE. I put a company description in the addCompany jsp
and it shows up as a contact description in the addContact jsp, and I
don't pass the description field to the contactForm.
 
Is there something I'm not understanding about the struts architecture?
 
Help is, of course, greatly appreciated.
 
alan



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org