struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "alanbrown" <>
Subject RE: FormBean question...
Date Wed, 16 Jul 2003 17:55:21 GMT
Really?  That seems strange.  I thought that the reason we name the
formbean in the strutsconfig file is so struts knows which bean it is
using to populate the form fields.  Am I mistaken in that?  How does
Struts decide which bean is being used to populate the fields?  I've
specifically replaced the Form in the Action class that prepares the
form so it contains the values I want.  But Struts seems to ignore those
values and use the ones in the bean from the last page I used.

I've looked into the generated java file that struts produces and I find
this (which sheds no light on anything as far as I'm concerned...

Here is the code that is laying out the Html for the description

	  out.write("<td valign=\"middle\" align=\"left\">\r\n
        if (_jspx_meth_html_textarea_0(_jspx_th_html_form_0,
          return true;
        out.write("\r\n    ");

and here is the method that's referred to....

private boolean _jspx_meth_html_textarea_0(javax.servlet.jsp.tagext.Tag
_jspx_th_html_form_0, javax.servlet.jsp.PageContext pageContext)
          throws Throwable {
    JspWriter out = pageContext.getOut();
    /* ----  html:textarea ---- */
    org.apache.struts.taglib.html.TextareaTag _jspx_th_html_textarea_0 =
    int _jspx_eval_html_textarea_0 =
    if (_jspx_th_html_textarea_0.doEndTag() ==
      return true;
    return false;

I don't see where the value is getting loaded into this field or where
it might be coming from.  I've searched through the file for any
setValue() methods but there aren't any (I thought there might be based
on the javadocs).

Can anyone explain what happens behind the scenes when I'm trying to
direct struts to discard the old formbean and use a new one in my
preparatory Action class?


-----Original Message-----
From: Mainguy, Mike [] 
Sent: Tuesday, September 16, 2003 4:35 AM
To: 'Struts Users Mailing List'
Subject: RE: FormBean question...

This is by design.  If you want to ensure this will not happen, you need
set all the values to "" or null beforehand for fields that should be
The short answer is "change the field name".  Especially if you are
going to
store data in a form in the session you will have a big mess on your
if you have overlapping field names in multiple forms.

My $.02...

-----Original Message-----
From: alanbrown [] 
Sent: Tuesday, September 16, 2003 2:18 AM
Subject: FormBean question...

I am using 2 different beans to populate 2 forms on 2 pages.  However
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
the form already filled out (the address fields have default values for
instance taken from the company info that was just entered).  However
description field and the notes field are also filled out with the
entered in the addCompany.jsp page and this should not happen.
This seems very strange as I've got 2 different formBeans used to
the fields.  Here are the relevant parts of the strutsconfig file.
            <forward name="Success" path="/"/>
            <forward name="Failure" path="/add/company.jsp"/>
            <forward name="next" path="/add/contact.jsp"/>
As you can see they are using different types of form so I find it very
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
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 =
        //if "addContactForm" is not null in the request scope then we
should use it to populate our form.
        form = contactForm == null? form : contactForm;
        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
pass the description field to the contactForm.
Is there something I'm not understanding about the struts architecture?
Help is, of course, greatly appreciated.

To unsubscribe, e-mail:
For additional commands, e-mail:

This message and its contents (to include attachments) are the property
of Kmart Corporation (Kmart) and may contain confidential and
proprietary information. You are hereby notified that any disclosure,
copying, or distribution of this message, or the taking of any action
based on information contained herein is strictly prohibited.
Unauthorized use of information contained herein may subject you to
civil and criminal prosecution and penalties. If you are not the
intended recipient, you should delete this message immediately.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message