Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Nested form beans

    14 answers - 1864 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I'm facing a situation where ideally I'd like to have a single ActionForm
    like so:
    public class MyActionForm extends ActionForm {
    AnotherActionForm1 af1;
    AnotherActionForm2 af2;
    }
    When in my JSP I do:
    <html:text property="af1.field1" />
    I do indeed see the value as I expect. The way I did this is to have
    an Action mapping that references MyActionForm, then within the Action I
    instantiate AnotherActionForm1, set the value of field1 on it, and then
    set af1 to that new AnotherActionForm1 instance. That all works nicely.
    Here's where I run into a problem
    the page I basically have 2 separate HTML forms, one for
    AnotherActionForm1 and another for AnotherActionForm2. However, I have a
    SINGLE submit button at the end (just plain button that makes an AJAX
    request). onClick of that button, I create a query string from the values
    of both forms, and make a request to the server with the query string
    attached. The parameter names of the query string arguments are
    af1.field1 and af2.field2, mimicing what's in MyActionForm. The mapping
    that the request goes to again references MyActionForm.
    What I've been told should happen is that Struts should be able to
    instantiate those two nested beans and set the properties, since the
    parameter names give it the information it needs. This does not however
    seem to be happening.
    So, two questions first, is that in fact the expected behavoir? And
    two, if so, any ideas what I'm doing wrong? I can post all the pertinent
    config and code, but thought it might be something more generic that
    wouldn't require all that. This is the first time I've ever had a need to
    nest forms like this, so it's a new question for me.
    Thanks all!
    Frank
  • No.1 | | 2407 bytes | |

    So what does happen when you submit the form? Are you getting NPEs?

    By the time Struts attempts to populate the form bean, the nested
    forms should already be instantiated. You should have getters and
    setters for af1 and af2, and getAf1() and getAf2() should not return a
    null. This could be an issue if the form bean is new, either because
    it's in request scope, or in session scope but was not previously
    instantiated.

    Hubert

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:
    I'm facing a situation where ideally I'd like to have a single ActionForm
    like so:

    public class MyActionForm extends ActionForm {
    AnotherActionForm1 af1;
    AnotherActionForm2 af2;
    }

    When in my JSP I do:

    <html:text property="af1.field1" />

    I do indeed see the value as I expect. The way I did this is to have
    an Action mapping that references MyActionForm, then within the Action I
    instantiate AnotherActionForm1, set the value of field1 on it, and then
    set af1 to that new AnotherActionForm1 instance. That all works nicely.

    Here's where I run into a problem

    the page I basically have 2 separate HTML forms, one for
    AnotherActionForm1 and another for AnotherActionForm2. However, I have a
    SINGLE submit button at the end (just plain button that makes an AJAX
    request). onClick of that button, I create a query string from the values
    of both forms, and make a request to the server with the query string
    attached. The parameter names of the query string arguments are
    af1.field1 and af2.field2, mimicing what's in MyActionForm. The mapping
    that the request goes to again references MyActionForm.

    What I've been told should happen is that Struts should be able to
    instantiate those two nested beans and set the properties, since the
    parameter names give it the information it needs. This does not however
    seem to be happening.

    So, two questions first, is that in fact the expected behavoir? And
    two, if so, any ideas what I'm doing wrong? I can post all the pertinent
    config and code, but thought it might be something more generic that
    wouldn't require all that. This is the first time I've ever had a need to
    nest forms like this, so it's a new question for me.

    Thanks all!

    Frank
    --
  • No.2 | | 4980 bytes | |

    Hi Hubert,

    Yes, I get nulls for af1 and af2 I do have getters and setters for them.

    Lemme throw some data your way I was hoping to avoid posting all this,
    but I suspect there to be something my eyes just aren't catching, so

    Here's ActionForm1:

    package app.test.formbeans;
    import ;
    public class Action1Form extends ActionForm {
    private String field1;
    public void setField1(String inField1) {
    this.field1 = inField1;
    }
    public String getField1() {
    return this.field1;
    }
    }

    ActionForm2 is identical, just replacing the number 1 with 2 everywhere.
    Here's MasterForm:

    package app.test.formbeans;
    import ;
    public class MasterForm extends ActionForm {
    public Action1Form action1Form;
    public Action2Form action2Form;
    public void setAction1Form(Action1Form inAction1Form) {
    this.action1Form = inAction1Form;
    }
    public Action1Form getAction1Form() {
    return this.action1Form;
    }
    public void setAction2Form(Action2Form inAction2Form) {
    this.action2Form = inAction2Form;
    }
    public Action2Form getAction2Form() {
    return this.action2Form;
    }
    }

    The Action everything gets submitted to is just a ForwardAction, which
    forwards to:

    <%@ page language="java" import="app.test.formbeans.*" %>
    <%
    MasterForm masterForm = (MasterForm)request.getAttribute("masterForm");
    %>
    <%="masterForm = " + masterForm + "<br>"%>
    <%
    Tab1Form tab1Form = null;
    Tab2Form tab2Form = null;
    if (masterForm != null) {
    tab1Form = masterForm.getTab1Form();
    tab2Form = masterForm.getTab2Form();
    }
    %>
    <%="tab1Form = " + tab1Form + "<br>"%>
    <%="tab2Form = " + tab2Form + "<br>"%>
    <% if (tab1Form != null) { %>
    <%="field1 = " + tab1Form.getField1() + "<br>"%>
    <% } %>
    <% if (tab2Form != null) { %>
    <%="field2 = " + tab2Form.getField2() + "<br>"%>
    <% } %>

    The result I see from this is:

    masterForm = app.test.formbeans.MasterForm@e3849c
    tab1Form = null
    tab2Form = null

    The page that does that submit, in its final rendered form on the client is:

    <html>
    <head>
    <script>
    var finalSubmit = null;
    function getXHR() {
    if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
    } else if (window.ActiveX) {
    return new ActiveX("Microsoft.XMLHTTP");
    }
    }
    function submitAll() {
    var tab1Form = dojo.io.encodeForm(
    document.getElementById("tab1Form"));
    var tab2Form = dojo.io.encodeForm(
    document.getElementById("tab2Form"));
    finalSubmit = getXHR();
    finalSubmit.onreadystatechange = finalSubmitCallback;
    finalSubmit.open("PST", "final.do", true);
    finalSubmit.send(tab1Form + tab2Form);
    }
    function finalSubmitCallback() {
    if (finalSubmit.readyState == 4) {
    document.getElementById("divResult").innerHTML =
    finalSubmit.responseText;
    }
    }
    </script>
    </head>
    <body onload="init();">
    <form name="masterForm" id="tab1Form" method="post" action="/test/tab1.do">
    Field1: <input name="tab1Form.field1" value="val1" type="text"><br>
    </form>
    <br>
    <form name="masterForm" id="tab2Form" method="post" action="/test/tab2.do">
    Field2: <input name="tab2Form.field2" value="val2" type="text"><br>
    </form>
    <br>
    <input value="Submit All" onclick="submitAll();" type="button">
    <br><br>
    <div id="divResult"></div>
    </body>
    </html>

    Note that I removed all the Dojo-related stuff, and some stuff that isn't
    related to this submissino, just to try and keep it small, but, the
    important thing to note is that when the submission is made, the request
    that goes across is a PST to , as
    expected, and the PST body is:

    also as expected, verified in Firebug. Lastly, here's struts-config:

    <?xml version="1.0" encoding="IS" ?>
    <!DCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
    Configuration 1.2//EN"
    "">
    <struts-config>
    <form-beans>
    <form-bean name="masterForm" type="app.test.formbeans.MasterForm" />
    </form-beans>
    <action-mappings>
    <action path="/final" type="app.test.actions.FinalAction"
    name="masterForm" scope="request" validate="false">
    <forward name="defaultForward" path="/final.jsp" />
    </action>
    </action-mappings>
    </struts-config>

    Note here that I removed the stuff that generated the markup from above
    too, since that seems to be working just fine, I'm pretty sure this is all
    that would be relevant.

    So, seeing any obvious blunders on my part? Thanks Hubert!

    Frank
  • No.3 | | 127 bytes | |

    Sorry, by af1 and af2 I did mean actionForm1 and actionForm2 my mistake
    wasn't quite *THAT* obvious! ;) LL
    Frank
  • No.4 | | 395 bytes | |

    In your no-arg constructor of your outer ActionForm (the container), make
    sure it instantiates each of the nested ActionForms using their no-arg
    constructors.
    (*Chris*)

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:

    Sorry, by af1 and af2 I did mean actionForm1 and actionForm2 my mistake
    wasn't quite *THAT* obvious! ;) LL

    Frank
    --
  • No.5 | | 773 bytes | |

    Either that or create new beans (if they're null) when their getters are called.

    By the time Struts attempts to populate the form bean, the nested
    forms should already be instantiated. MasterForm.getAction1Form() and
    MasterForm.getAction2Form() should not return a null.

    Hubert

    9/22/06, Chris Pratt <thechrispratt (AT) gmail (DOT) comwrote:
    In your no-arg constructor of your outer ActionForm (the container), make
    sure it instantiates each of the nested ActionForms using their no-arg
    constructors.
    (*Chris*)

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:

    Sorry, by af1 and af2 I did mean actionForm1 and actionForm2 my mistake
    wasn't quite *THAT* obvious! ;) LL

    Frank
    --
  • No.6 | | 448 bytes | |

    Hi Chris thanks for the suggestion, I gave that a shot at one point
    actually what I get is now the fields in the subforms (I guess that's
    as good a term as any!) don't get set

    masterForm = app.test.formbeans.MasterForm@141fab6
    tab1Form = app.test.formbeans.Tab1Form@b301f2
    tab2Form = app.test.formbeans.Tab2Form@44cbbe
    field1 = null
    field2 = null

    That's what I see in my final JSP output.

    Frank
  • No.7 | | 264 bytes | |

    As a follow-up, I threw some logging in the field1 and field2 setters in
    the subbeans they don't appear to ever get called. I don't have to do
    anything special to tell Struts I'm using nested beans, do I? I didn't
    think so
    Frank
  • No.8 | | 589 bytes | |

    It still sounds like Struts is getting nulls for the subbeans when it
    tries to populate subbean.fieldX. Put some more logging, this time in
    the getters for the subbean in MasterForm, and log what it's
    returning.

    Hubert

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:
    As a follow-up, I threw some logging in the field1 and field2 setters in
    the subbeans they don't appear to ever get called. I don't have to do
    anything special to tell Struts I'm using nested beans, do I? I didn't
    think so

    Frank
    --
  • No.9 | | 205 bytes | |

    Yeah, I'm sure that previous post was confusing :) tab1Form and tab2Form
    are the names of the action forms I forgot I changed them at one point.
    The code itself all references the proper names.
  • No.10 | | 605 bytes | |

    Hehe, way ahead of you :) I put logging in every method constructors,
    getters setter, all three forms. Here's the output:

    MasterForm constructor
    Tab1Form constructor
    Tab2Form constructor
    IN JSP--
    MasterForm getTab1Form() = app.test.formbeans.Tab1Form@8ab08f
    MasterForm getTab2Form() = app.test.formbeans.Tab2Form@14d921a
    getting field1 = null
    getting field2 = null

    Notice the fields don't get set, nor do the subbeans get set on the
    containing bean. The MasterForm constructor instantiates Tab1Form and
    Tab2Form, as the output indicates.

    Frank
  • No.11 | | 999 bytes | |

    I can't see anything that would cause your problem.
    I guess if it were me, I'd fire up my debugger and start stepping
    through some code.
    Sorry.
    All I can say at this point is that I know what you're doing is
    possible cause that's how FormDef does nested beans.

    Hubert

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:
    Hehe, way ahead of you :) I put logging in every method constructors,
    getters setter, all three forms. Here's the output:

    MasterForm constructor
    Tab1Form constructor
    Tab2Form constructor
    IN JSP--
    MasterForm getTab1Form() = app.test.formbeans.Tab1Form@8ab08f
    MasterForm getTab2Form() = app.test.formbeans.Tab2Form@14d921a
    getting field1 = null
    getting field2 = null

    Notice the fields don't get set, nor do the subbeans get set on the
    containing bean. The MasterForm constructor instantiates Tab1Form and
    Tab2Form, as the output indicates.

    Frank
    --
  • No.12 | | 21386 bytes | |

    Fri, September 22, 2006 3:59 pm, Hubert Rabago wrote:
    I can't see anything that would cause your problem.
    I guess if it were me, I'd fire up my debugger and start stepping
    through some code.
    Sorry.

    Yeah, that's the next step. Was hoping to avoid it with an easy answer,
    but that's the way it goes sometimes :)

    All I can say at this point is that I know what you're doing is
    possible cause that's how FormDef does nested beans.

    Actually, that's a pretty big help in and of itself I wasn't frankly
    aware the subbeans would get populated, so knowing it *should* work at
    least means I'm not on a wild goose chase. Thanks for the effort, I
    definitely appreciate it!

    Hubert

    Frank

    9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:
    >Hehe, way ahead of you :) I put logging in every method
    >constructors,
    >getters setter, all three forms. Here's the output:
    >>

    >MasterForm constructor
    >Tab1Form constructor
    >Tab2Form constructor
    >IN JSP--
    >MasterForm getTab1Form() = app.test.formbeans.Tab1Form@8ab08f
    >MasterForm getTab2Form() = app.test.formbeans.Tab2Form@14d921a
    >getting field1 = null
    >getting field2 = null
    >>

    >Notice the fields don't get set, nor do the subbeans get set on the
    >containing bean. The MasterForm constructor instantiates Tab1Form and
    >Tab2Form, as the output indicates.
    >>

    >Frank
    >>
    >>

    >--
    >Frank W. Zammetti
    >Founder and Chief Software Architect
    >Technologies
    >http://www.omnytex.com
    >AIM/Yahoo: fzammetti
    >MSN: fzammetti (AT) hotmail (DOT) com
    >Author of "Practical Ajax Projects With Java Technology"
    >(2006, Apress, ISBN 1-59059-695-1)
    >Java Web Parts -
    >Supplying the wheel, so you don't have to reinvent it!
    >>

    >Fri, September 22, 2006 2:53 pm, Hubert Rabago wrote:
    >It still sounds like Struts is getting nulls for the subbeans when it
    >tries to populate subbean.fieldX. Put some more logging, this time in
    >the getters for the subbean in MasterForm, and log what it's
    >returning.
    >>

    >Hubert
    >>

    >9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:
    >>As a follow-up, I threw some logging in the field1 and field2 setters

    >in
    >>the subbeans they don't appear to ever get called. I don't have

    >to
    >>do
    >>anything special to tell Struts I'm using nested beans, do I? I

    >didn't
    >>think so
    >>>

    >>Frank
    >>>
    >>>

    >>--
    >>Frank W. Zammetti
    >>Founder and Chief Software Architect
    >>Technologies
    >>http://www.omnytex.com
    >>AIM/Yahoo: fzammetti
    >>MSN: fzammetti (AT) hotmail (DOT) com
    >>Author of "Practical Ajax Projects With Java Technology"
    >>(2006, Apress, ISBN 1-59059-695-1)
    >>Java Web Parts -
    >>Supplying the wheel, so you don't have to reinvent it!
    >>>

    >>Fri, September 22, 2006 2:47 pm, Frank W. Zammetti wrote:
    >>Hi Chris thanks for the suggestion, I gave that a shot at one

    >point
    >>actually what I get is now the fields in the subforms (I guess
    >>that's
    >>as good a term as any!) don't get set
    >>>

    >>masterForm = app.test.formbeans.MasterForm@141fab6
    >>tab1Form = app.test.formbeans.Tab1Form@b301f2
    >>tab2Form = app.test.formbeans.Tab2Form@44cbbe
    >>field1 = null
    >>field2 = null
    >>>

    >>That's what I see in my final JSP output.
    >>>

    >>Frank
    >>>
    >>>

    >>--
    >>Frank W. Zammetti
    >>Founder and Chief Software Architect
    >>Technologies
    >>http://www.omnytex.com
    >>AIM/Yahoo: fzammetti
    >>MSN: fzammetti (AT) hotmail (DOT) com
    >>Author of "Practical Ajax Projects With Java Technology"
    >>(2006, Apress, ISBN 1-59059-695-1)
    >>Java Web Parts -
    >>Supplying the wheel, so you don't have to reinvent it!
    >>>

    >>Fri, September 22, 2006 2:40 pm, Chris Pratt wrote:
    >>>In your no-arg constructor of your outer ActionForm (the

    >container),
    >>>make
    >>>sure it instantiates each of the nested ActionForms using their

    >>no-arg
    >>>constructors.
    >>>(*Chris*)
    >>>>
    >>>9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:

    >>
    >>Sorry, by af1 and af2 I did mean actionForm1 and actionForm2

    >my
    >>mistake
    >>wasn't quite *THAT* obvious! ;) LL
    >>
    >>Frank
    >>
    >>
    >>--
    >>Frank W. Zammetti
    >>Founder and Chief Software Architect
    >>Technologies
    >>http://www.omnytex.com
    >>AIM/Yahoo: fzammetti
    >>MSN: fzammetti (AT) hotmail (DOT) com
    >>Author of "Practical Ajax Projects With Java Technology"
    >>(2006, Apress, ISBN 1-59059-695-1)
    >>Java Web Parts -
    >>Supplying the wheel, so you don't have to reinvent it!
    >>
    >>Fri, September 22, 2006 1:31 pm, Frank W. Zammetti wrote:
    >>Hi Hubert,
    >>>

    >>Yes, I get nulls for af1 and af2 I do have getters and

    >setters
    >>for
    >>them.
    >>>

    >>Lemme throw some data your way I was hoping to avoid posting
    >>all
    >>this,
    >>but I suspect there to be something my eyes just aren't

    >catching,
    >>so
    >>>
    >>>

    >>Here's ActionForm1:
    >>>
    >>>

    >>package app.test.formbeans;
    >>import ;
    >>public class Action1Form extends ActionForm {
    >>private String field1;
    >>public void setField1(String inField1) {
    >>this.field1 = inField1;
    >>}
    >>public String getField1() {
    >>return this.field1;
    >>}
    >>}
    >>>
    >>>

    >>ActionForm2 is identical, just replacing the number 1 with 2
    >>everywhere.
    >>Here's MasterForm:
    >>>
    >>>

    >>package app.test.formbeans;
    >>import ;
    >>public class MasterForm extends ActionForm {
    >>public Action1Form action1Form;
    >>public Action2Form action2Form;
    >>public void setAction1Form(Action1Form inAction1Form) {
    >>this.action1Form = inAction1Form;
    >>}
    >>public Action1Form getAction1Form() {
    >>return this.action1Form;
    >>}
    >>public void setAction2Form(Action2Form inAction2Form) {
    >>this.action2Form = inAction2Form;
    >>}
    >>public Action2Form getAction2Form() {
    >>return this.action2Form;
    >>}
    >>}
    >>>
    >>>

    >>The Action everything gets submitted to is just a

    >ForwardAction,
    >>which
    >>forwards to:
    >>>
    >>>

    >><%@ page language="java" import="app.test.formbeans.*" %>
    >><%
    >>MasterForm masterForm =
    >>(MasterForm)request.getAttribute("masterForm");
    >>%>
    >><%="masterForm = " + masterForm + "<br>"%>
    >><%
    >>Tab1Form tab1Form = null;
    >>Tab2Form tab2Form = null;
    >>if (masterForm != null) {
    >>tab1Form = masterForm.getTab1Form();
    >>tab2Form = masterForm.getTab2Form();
    >>}
    >>%>
    >><%="tab1Form = " + tab1Form + "<br>"%>
    >><%="tab2Form = " + tab2Form + "<br>"%>
    >><% if (tab1Form != null) { %>
    >><%="field1 = " + tab1Form.getField1() + "<br>"%>
    >><% } %>
    >><% if (tab2Form != null) { %>
    >><%="field2 = " + tab2Form.getField2() + "<br>"%>
    >><% } %>
    >>>
    >>>

    >>The result I see from this is:
    >>>
    >>>

    >>masterForm = app.test.formbeans.MasterForm@e3849c
    >>tab1Form = null
    >>tab2Form = null
    >>>
    >>>

    >>The page that does that submit, in its final rendered form on

    >the
    >>client
    >>is:
    >>>
    >>>

    >><html>
    >><head>
    >><script>
    >>var finalSubmit = null;
    >>function getXHR() {
    >>if (window.XMLHttpRequest) {
    >>return new XMLHttpRequest();
    >>} else if (window.ActiveX) {
    >>return new ActiveX("Microsoft.XMLHTTP");
    >>}
    >>}
    >>function submitAll() {
    >>var tab1Form = dojo.io.encodeForm(
    >>document.getElementById("tab1Form"));
    >>var tab2Form = dojo.io.encodeForm(
    >>document.getElementById("tab2Form"));
    >>finalSubmit = getXHR();
    >>finalSubmit.onreadystatechange = finalSubmitCallback;
    >>finalSubmit.open("PST", "final.do", true);
    >>finalSubmit.send(tab1Form + tab2Form);
    >>}
    >>function finalSubmitCallback() {
    >>if (finalSubmit.readyState == 4) {
    >>document.getElementById("divResult").innerHTML =
    >>finalSubmit.responseText;
    >>}
    >>}
    >></script>
    >></head>
    >><body onload="init();">
    >><form name="masterForm" id="tab1Form" method="post"
    >>action="/test/tab1.do">
    >>Field1: <input name="tab1Form.field1" value="val1"
    >>type="text"><br>
    >></form>
    >><br>
    >><form name="masterForm" id="tab2Form" method="post"
    >>action="/test/tab2.do">
    >>Field2: <input name="tab2Form.field2" value="val2"
    >>type="text"><br>
    >></form>
    >><br>
    >><input value="Submit All" onclick="submitAll();"

    >type="button">
    >><br><br>
    >><div id="divResult"></div>
    >></body>
    >></html>
    >>>
    >>>

    >>Note that I removed all the Dojo-related stuff, and some stuff
    >>that
    >>isn't
    >>related to this submissino, just to try and keep it small, but,
    >>the
    >>important thing to note is that when the submission is made,

    >the
    >>request
    >>that goes across is a PST to

    >,
    >>as
    >>expected, and the PST body is:
    >>>

    >>
    >>>

    >>also as expected, verified in Firebug. Lastly, here's
    >>struts-config:
    >>>
    >>>

    >><?xml version="1.0" encoding="IS" ?>
    >><!DCTYPE struts-config PUBLIC "-//Apache Software

    >Foundation//DTD
    >>Struts
    >>Configuration 1.2//EN"
    >>"">
    >><struts-config>
    >><form-beans>
    >><form-bean name="masterForm"
    >>type="app.test.formbeans.MasterForm"
    >>/>
    >></form-beans>
    >><action-mappings>
    >><action path="/final" type="app.test.actions.FinalAction"
    >>name="masterForm" scope="request" validate="false">
    >><forward name="defaultForward" path="/final.jsp" />
    >></action>
    >></action-mappings>
    >></struts-config>
    >>>
    >>>

    >>Note here that I removed the stuff that generated the markup

    >from
    >>above
    >>too, since that seems to be working just fine, I'm pretty sure
    >>this
    >>is
    >>all
    >>that would be relevant.
    >>>

    >>So, seeing any obvious blunders on my part? Thanks Hubert!
    >>>

    >>Frank
    >>>
    >>>

    >>--
    >>Frank W. Zammetti
    >>Founder and Chief Software Architect
    >>Technologies
    >>http://www.omnytex.com
    >>AIM/Yahoo: fzammetti
    >>MSN: fzammetti (AT) hotmail (DOT) com
    >>Author of "Practical Ajax Projects With Java Technology"
    >>(2006, Apress, ISBN 1-59059-695-1)
    >>Java Web Parts -
    >>Supplying the wheel, so you don't have to reinvent it!
    >>>

    >>Fri, September 22, 2006 1:10 pm, Hubert Rabago wrote:
    >>>So what does happen when you submit the form? Are you getting

    >>NPEs?
    >>>>
    >>>By the time Struts attempts to populate the form bean, the

    >nested
    >>>forms should already be instantiated. You should have getters

    >>and
    >>>setters for af1 and af2, and getAf1() and getAf2() should not

    >>return
    >>a
    >>>null. This could be an issue if the form bean is new, either

    >>because
    >>>it's in request scope, or in session scope but was not

    >previously
    >>>instantiated.
    >>>>
    >>>Hubert
    >>>>
    >>>9/22/06, Frank W. Zammetti <fzlists (AT) omnytex (DOT) comwrote:

    >>I'm facing a situation where ideally I'd like to have a

    >single
    >>ActionForm
    >>like so:
    >>
    >>public class MyActionForm extends ActionForm {
    >>AnotherActionForm1 af1;
    >>AnotherActionForm2 af2;
    >>}
    >>
    >>When in my JSP I do:
    >>
    >><html:text property="af1.field1" />
    >>
    >>I do indeed see the value as I expect. The way I did this

    >is
    >>to
    >>have
    >>an Action mapping that references MyActionForm, then within

    >the
    >>Action
    >>I
    >>instantiate AnotherActionForm1, set the value of field1 on

    >it,
    >>and
    >>then
    >>set af1 to that new AnotherActionForm1 instance. That all

    >works
    >>nicely.
    >>
    >>Here's where I run into a problem
    >>
    >>the page I basically have 2 separate HTML forms, one for
    >>AnotherActionForm1 and another for AnotherActionForm2.

    >However,
    >>I
    >>have
    >>a
    >>SINGLE submit button at the end (just plain button that makes

    >an
    >>AJAX
    >>request). onClick of that button, I create a query string

    >from
    >>the
    >>values
    >>of both forms, and make a request to the server with the

    >query
    >>string
    >>attached. The parameter names of the query string arguments

    >are
    >>af1.field1 and af2.field2, mimicing what's in MyActionForm.

    >The
    >>mapping
    >>that the request goes to again references MyActionForm.
    >>
    >>What I've been told should happen is that Struts should be

    >able
    >>to
    >>instantiate those two nested beans and set the properties,

    >since
    >>the
    >>parameter names give it the information it needs. This does

    >not
    >>however
    >>seem to be happening.
    >>
    >>So, two questions first, is that in fact the expected
    >>behavoir? And
    >>two, if so, any ideas what I'm doing wrong? I can post all

    >the
    >>pertinent
    >>config and code, but thought it might be something more

    >generic
    >>that
    >>wouldn't require all that. This is the first time I've ever

    >had
    >>a
    >>need
    >>to
    >>nest forms like this, so it's a new question for me.
    >>
    >>Thanks all!
    >>
    >>Frank
    >>
    >>
    >>--
    >>Frank W. Zammetti
    >>Founder and Chief Software Architect
    >>Technologies
    >>http://www.omnytex.com
    >>AIM/Yahoo: fzammetti
    >>MSN: fzammetti (AT) hotmail (DOT) com
    >>Author of "Practical Ajax Projects With Java Technology"
    >>(2006, Apress, ISBN 1-59059-695-1)
    >>Java Web Parts -
    >>Supplying the wheel, so you don't have to reinvent it!
    >>
    >>
    >>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>
    >>
    >>>>
    >>>
    >>>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>>
    >>>

    >>
    >>
    >>
    >>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>
    >>
    >>>>
    >>>
    >>>

    >>
    >>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>>
    >>>
    >>>
    >>>

    >>
    >>To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >>For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>>
    >>>

    >>

    >
    >To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>
    >>
    >>
    >>

    >
    >To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    >For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    >>
    >>

    >


    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
    --

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.13 | | 439 bytes | |

    Quick update: it has something to do with the fact that its an AJAX
    request at the end or because its a PST, one or the other I built a
    URL with the parameters as a query string, and it worked fine I don't
    know what it is yet yet, exploring now the request looks identical
    aside from method, which shouldn't matter, AFAIKT, but something is
    obviously bad with it will let you know when I figure it out

    Frank
  • No.14 | | 447 bytes | |

    Got it had to explicitly set the Content-Type of the request to
    on the XMLHttpRequest object. Didn't
    even occur to me because I set the method to PST, didn't even consider
    that might not be sufficient. Weird thing is, I know I have code where I
    PST but don't set the header and it works, not sure why these nested
    names would be different.

    Well, should it come up for anyone else, there you go :)

    Frank

Re: Nested form beans


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "Java"

EMSDN.COM