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/07/16 19:55:21 UTC

RE: FormBean question...

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
field...

	  out.write("<td valign=\"middle\" align=\"left\">\r\n
");
        if (_jspx_meth_html_textarea_0(_jspx_th_html_form_0,
pageContext))
          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 =
(org.apache.struts.taglib.html.TextareaTag)
_jspx_tagPool_html_textarea_rows_property_cols.get(org.apache.struts.tag
lib.html.TextareaTag.class);
    _jspx_th_html_textarea_0.setPageContext(pageContext);
    _jspx_th_html_textarea_0.setParent(_jspx_th_html_form_0);
    _jspx_th_html_textarea_0.setProperty("description");
    _jspx_th_html_textarea_0.setCols("60");
    _jspx_th_html_textarea_0.setRows("3");
    int _jspx_eval_html_textarea_0 =
_jspx_th_html_textarea_0.doStartTag();
    if (_jspx_th_html_textarea_0.doEndTag() ==
javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
      return true;
 
_jspx_tagPool_html_textarea_rows_property_cols.reuse(_jspx_th_html_texta
rea_0);
    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?

alan


-----Original Message-----
From: Mainguy, Mike [mailto:MMainguy@kmart.com] 
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
to
set all the values to "" or null beforehand for fields that should be
empty.
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
hands
if you have overlapping field names in multiple forms.

My $.02...


-----Original Message-----
From: alanbrown [mailto:alanbrown@pacbell.net] 
Sent: Tuesday, September 16, 2003 2:18 AM
To: struts-user@jakarta.apache.org
Subject: 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


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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


RE: FormBean question...

Posted by alanbrown <al...@pacbell.net>.
And it's stranger than that also.  If I come to the addContact page From
the addCompany page then any fields I pre-fill in my addContactForm bean
are ignored.  But if I come directly to the addContact page then the
prefilled fields are as I'd expect.  It's as though I can't change the
formBean that's being used by struts once it's placed in request scope.
That is to say that once the addCompanyForm bean is used to add the
company to the database, I don't appear able to replace it with an
addContactForm bean to populate the fields I want to populate.





-----Original Message-----
From: alanbrown [mailto:alanbrown@pacbell.net] 
Sent: Wednesday, July 16, 2003 10:55 AM
To: 'Struts Users Mailing List'
Subject: RE: FormBean question...

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
field...

	  out.write("<td valign=\"middle\" align=\"left\">\r\n
");
        if (_jspx_meth_html_textarea_0(_jspx_th_html_form_0,
pageContext))
          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 =
(org.apache.struts.taglib.html.TextareaTag)
_jspx_tagPool_html_textarea_rows_property_cols.get(org.apache.struts.tag
lib.html.TextareaTag.class);
    _jspx_th_html_textarea_0.setPageContext(pageContext);
    _jspx_th_html_textarea_0.setParent(_jspx_th_html_form_0);
    _jspx_th_html_textarea_0.setProperty("description");
    _jspx_th_html_textarea_0.setCols("60");
    _jspx_th_html_textarea_0.setRows("3");
    int _jspx_eval_html_textarea_0 =
_jspx_th_html_textarea_0.doStartTag();
    if (_jspx_th_html_textarea_0.doEndTag() ==
javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
      return true;
 
_jspx_tagPool_html_textarea_rows_property_cols.reuse(_jspx_th_html_texta
rea_0);
    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?

alan


-----Original Message-----
From: Mainguy, Mike [mailto:MMainguy@kmart.com] 
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
to
set all the values to "" or null beforehand for fields that should be
empty.
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
hands
if you have overlapping field names in multiple forms.

My $.02...


-----Original Message-----
From: alanbrown [mailto:alanbrown@pacbell.net] 
Sent: Tuesday, September 16, 2003 2:18 AM
To: struts-user@jakarta.apache.org
Subject: 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


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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



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



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