You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Close <ac...@gmail.com> on 2004/07/15 19:53:30 UTC

alrighty,  i've got this half figured out.  i can populate my
dropdowns, but my form doesn't seem to be scrapping the values back
off the page.
i have an action that gets a collection of beans and puts them in
session for the JSP to use.  the JSP renders and displays those
objects correctly in the dropdowns.  when the first dropdown is
changed an onchange event fires off the previous action to populate
the second dropdown.  however, the selected value in the first
dropdown doesn't show up in my Action or the Form.

here's part of the JSP:

<td align="left">
 <html:select name="shoppingListForm" property="selectedShoppingList"
onchange="sl_getGroups(this.form);" >
  <html:option value="-1" >- Please Select A List -</html:option>
  <html:optionsCollection name="lists" />
 </html:select>
 <br>
 <html:select name="shoppingListForm"
property="selectedShoppingListGroup"
onchange="sl_getItems(this.form);" >
  <logic:match name="selectedShoppingList" value="-1">
   <html:option value="-1" >- Please Select A List -</html:option>
  </logic:match>
  <logic:notMatch name="selectedShoppingList" value="-1">
   <html:option value="-1" >- Please Select A Group -</html:option>
   <html:option value="0" >- All Groups -</html:option>
   <html:optionsCollection name="groups" />
  </logic:notMatch>
 </html:select>
</td>

and i have an ActionForm created named shoppingListForm containing two
Strings: selectedShoppingList and selectedShoppingListGroup with
initial values set at "-1".  ShoppingListForm contains basic getters
and setters for these attributes.

so i'm guessing my problem lies within my Action.  i'm extending
DispatchAction and the getGroups method forwards to the above JSP on
"success".

public ActionForward getGroups (

<snip>

try {
    HttpSession session = request.getSession(false);
    ShoppingListForm slForm = (ShoppingListForm)form;
			
    if (slForm == null) {
        session.setAttribute("selectedShoppingList", "-1");
        session.setAttribute("selectedShoppingListGroup", "-1");
    } else {
        session.setAttribute("selectedShoppingList",
slForm.getSelectedShoppingList());
        session.setAttribute("selectedShoppingListGroup",
slForm.getSelectedShoppingListGroup());
				
        System.out.println("\n\nShopping List Form...");
        System.out.println("Shopping List: " +
slForm.getSelectedShoppingList());
        System.out.println("Shopping List Group: " +
slForm.getSelectedShoppingListGroup() + "\n\n\n");
    }

... go on to populate collection for lists, etc...

the first time through the form will be null because this action is
called from another page.  the action populates 'lists' and forwards
to the above JSP.  onchange in the JSP calls this same action and
should pass it my ShoppingListForm, in which should be found the value
to selectedShoppingList.  however this value remains "-1".
on success the same JSP is displayed...

here is the action-mapping for this particular action:

<action path="/refresh" 
 parameter="step"
 type="sl.controllers.SLMainAction"
 name="shoppingListForm"
 validate="true">
  <forward name="success" path="/jsp/SLMain.jsp" />
  <forward name="failure" path="/jsp/SLError.jsp" />
</action>

thanks for any help
andy

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


Re:

Posted by Andrew Close <ac...@gmail.com>.
the weird thing is that i just added a textfield to the form and my
form/action picks that up.  so what do you have to do to get
<html:select><html:options> read by a form?

andy


On Thu, 15 Jul 2004 13:56:48 -0500, Andrew Close <ac...@gmail.com> wrote:
> sl_getGroups is being called.  i printed out alerts when i was writing
> it.  and i have Sys.outs in the action.  besides, my JSP wouldn't show
> up if it wasn't :)
> 
> the javascript is fairly simple:  (i know there is a more Strutsy way
> to do this, i'm getting there...)
> 
> function sl_getGroups(frm) {
> if (frm.selectedShoppingList.options[frm.selectedShoppingList.selectedIndex].value
> != "-1") {
>   frm.selectedShoppingList.options[frm.selectedShoppingList.selectedIndex].value
> = "-1";
>   frm.action += "?step=getGroups";
>   frm.submit();
>  }
> }
> 
> the javascript just checks to see that the selectedShoppingList is not
> "-1", the initial value.  it then appends my step parameter to the
> action.  this is working.  what is funny is that the javascript
> recognizes that the selectedShoppingList is not "-1", but the form
> doesn't pick that up...
> 
> any suggestions?
> 
> andy
> 
> 
> 
> 
> On Thu, 15 Jul 2004 14:36:14 -0400, Bill Siggelkow
> <bi...@bellsouth.net> wrote:
> > Hmmm ... looks pretty darn hairy. You didn't show the JavaScript thats
> > called by the onchange --  I would verify first that "getGroups" is
> > being called.

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


Re:

Posted by Andrew Close <ac...@gmail.com>.
sl_getGroups is being called.  i printed out alerts when i was writing
it.  and i have Sys.outs in the action.  besides, my JSP wouldn't show
up if it wasn't :)

the javascript is fairly simple:  (i know there is a more Strutsy way
to do this, i'm getting there...)

function sl_getGroups(frm) {
if (frm.selectedShoppingList.options[frm.selectedShoppingList.selectedIndex].value
!= "-1") {
  frm.selectedShoppingList.options[frm.selectedShoppingList.selectedIndex].value
= "-1";
  frm.action += "?step=getGroups";
  frm.submit();
 }
}

the javascript just checks to see that the selectedShoppingList is not
"-1", the initial value.  it then appends my step parameter to the
action.  this is working.  what is funny is that the javascript
recognizes that the selectedShoppingList is not "-1", but the form
doesn't pick that up...

any suggestions?

andy


On Thu, 15 Jul 2004 14:36:14 -0400, Bill Siggelkow
<bi...@bellsouth.net> wrote:
> Hmmm ... looks pretty darn hairy. You didn't show the JavaScript thats
> called by the onchange --  I would verify first that "getGroups" is
> being called.
> 
> 
> 
> Andrew Close wrote:
> 
> > alrighty,  i've got this half figured out.  i can populate my
> > dropdowns, but my form doesn't seem to be scrapping the values back
> > off the page.
> > i have an action that gets a collection of beans and puts them in
> > session for the JSP to use.  the JSP renders and displays those
> > objects correctly in the dropdowns.  when the first dropdown is
> > changed an onchange event fires off the previous action to populate
> > the second dropdown.  however, the selected value in the first
> > dropdown doesn't show up in my Action or the Form.
> >
> > here's part of the JSP:
> >
> > <td align="left">
> >  <html:select name="shoppingListForm" property="selectedShoppingList"
> > onchange="sl_getGroups(this.form);" >
> >   <html:option value="-1" >- Please Select A List -</html:option>
> >   <html:optionsCollection name="lists" />
> >  </html:select>
> >  <br>
> >  <html:select name="shoppingListForm"
> > property="selectedShoppingListGroup"
> > onchange="sl_getItems(this.form);" >
> >   <logic:match name="selectedShoppingList" value="-1">
> >    <html:option value="-1" >- Please Select A List -</html:option>
> >   </logic:match>
> >   <logic:notMatch name="selectedShoppingList" value="-1">
> >    <html:option value="-1" >- Please Select A Group -</html:option>
> >    <html:option value="0" >- All Groups -</html:option>
> >    <html:optionsCollection name="groups" />
> >   </logic:notMatch>
> >  </html:select>
> > </td>
> >
> > and i have an ActionForm created named shoppingListForm containing two
> > Strings: selectedShoppingList and selectedShoppingListGroup with
> > initial values set at "-1".  ShoppingListForm contains basic getters
> > and setters for these attributes.
> >
> > so i'm guessing my problem lies within my Action.  i'm extending
> > DispatchAction and the getGroups method forwards to the above JSP on
> > "success".
> >
> > public ActionForward getGroups (
> >
> > <snip>
> >
> > try {
> >     HttpSession session = request.getSession(false);
> >     ShoppingListForm slForm = (ShoppingListForm)form;
> >
> >     if (slForm == null) {
> >         session.setAttribute("selectedShoppingList", "-1");
> >         session.setAttribute("selectedShoppingListGroup", "-1");
> >     } else {
> >         session.setAttribute("selectedShoppingList",
> > slForm.getSelectedShoppingList());
> >         session.setAttribute("selectedShoppingListGroup",
> > slForm.getSelectedShoppingListGroup());
> >
> >         System.out.println("\n\nShopping List Form...");
> >         System.out.println("Shopping List: " +
> > slForm.getSelectedShoppingList());
> >         System.out.println("Shopping List Group: " +
> > slForm.getSelectedShoppingListGroup() + "\n\n\n");
> >     }
> >
> > ... go on to populate collection for lists, etc...
> >
> > the first time through the form will be null because this action is
> > called from another page.  the action populates 'lists' and forwards
> > to the above JSP.  onchange in the JSP calls this same action and
> > should pass it my ShoppingListForm, in which should be found the value
> > to selectedShoppingList.  however this value remains "-1".
> > on success the same JSP is displayed...
> >
> > here is the action-mapping for this particular action:
> >
> > <action path="/refresh"
> >  parameter="step"
> >  type="sl.controllers.SLMainAction"
> >  name="shoppingListForm"
> >  validate="true">
> >   <forward name="success" path="/jsp/SLMain.jsp" />
> >   <forward name="failure" path="/jsp/SLError.jsp" />
> > </action>
> >
> > thanks for any help
> > andy

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


Re:

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Hmmm ... looks pretty darn hairy. You didn't show the JavaScript thats 
called by the onchange --  I would verify first that "getGroups" is 
being called.

Andrew Close wrote:

> alrighty,  i've got this half figured out.  i can populate my
> dropdowns, but my form doesn't seem to be scrapping the values back
> off the page.
> i have an action that gets a collection of beans and puts them in
> session for the JSP to use.  the JSP renders and displays those
> objects correctly in the dropdowns.  when the first dropdown is
> changed an onchange event fires off the previous action to populate
> the second dropdown.  however, the selected value in the first
> dropdown doesn't show up in my Action or the Form.
> 
> here's part of the JSP:
> 
> <td align="left">
>  <html:select name="shoppingListForm" property="selectedShoppingList"
> onchange="sl_getGroups(this.form);" >
>   <html:option value="-1" >- Please Select A List -</html:option>
>   <html:optionsCollection name="lists" />
>  </html:select>
>  <br>
>  <html:select name="shoppingListForm"
> property="selectedShoppingListGroup"
> onchange="sl_getItems(this.form);" >
>   <logic:match name="selectedShoppingList" value="-1">
>    <html:option value="-1" >- Please Select A List -</html:option>
>   </logic:match>
>   <logic:notMatch name="selectedShoppingList" value="-1">
>    <html:option value="-1" >- Please Select A Group -</html:option>
>    <html:option value="0" >- All Groups -</html:option>
>    <html:optionsCollection name="groups" />
>   </logic:notMatch>
>  </html:select>
> </td>
> 
> and i have an ActionForm created named shoppingListForm containing two
> Strings: selectedShoppingList and selectedShoppingListGroup with
> initial values set at "-1".  ShoppingListForm contains basic getters
> and setters for these attributes.
> 
> so i'm guessing my problem lies within my Action.  i'm extending
> DispatchAction and the getGroups method forwards to the above JSP on
> "success".
> 
> public ActionForward getGroups (
> 
> <snip>
> 
> try {
>     HttpSession session = request.getSession(false);
>     ShoppingListForm slForm = (ShoppingListForm)form;
> 			
>     if (slForm == null) {
>         session.setAttribute("selectedShoppingList", "-1");
>         session.setAttribute("selectedShoppingListGroup", "-1");
>     } else {
>         session.setAttribute("selectedShoppingList",
> slForm.getSelectedShoppingList());
>         session.setAttribute("selectedShoppingListGroup",
> slForm.getSelectedShoppingListGroup());
> 				
>         System.out.println("\n\nShopping List Form...");
>         System.out.println("Shopping List: " +
> slForm.getSelectedShoppingList());
>         System.out.println("Shopping List Group: " +
> slForm.getSelectedShoppingListGroup() + "\n\n\n");
>     }
> 
> ... go on to populate collection for lists, etc...
> 
> the first time through the form will be null because this action is
> called from another page.  the action populates 'lists' and forwards
> to the above JSP.  onchange in the JSP calls this same action and
> should pass it my ShoppingListForm, in which should be found the value
> to selectedShoppingList.  however this value remains "-1".
> on success the same JSP is displayed...
> 
> here is the action-mapping for this particular action:
> 
> <action path="/refresh" 
>  parameter="step"
>  type="sl.controllers.SLMainAction"
>  name="shoppingListForm"
>  validate="true">
>   <forward name="success" path="/jsp/SLMain.jsp" />
>   <forward name="failure" path="/jsp/SLError.jsp" />
> </action>
> 
> thanks for any help
> andy


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