You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Thill <mt...@compsciresources.net> on 2003/10/23 00:19:53 UTC

DynaValidatorForm ArrayList problem

I'm having a problem with checkboxes.  I have an ArrayList of objects in
which the objects have a getter and setter for this Boolean value which
is basically the on or off for the checkbox.  The checkbox displays
correctly, but I can never uncheck the box.  Here is the code I'm trying
to use:

 

I am using DynaValidatorForm, and my struts-config.xml looks like such:

 

com.test.struts.ThresholdForm extends DynaValidatorForm because I was
trying to override the reset method there, but that didn't seem to do it
either. 

 

<form-beans>

    <form-bean name="thresholdForm" type="com.test.struts.ThresholdForm"
dynamic="true" >

      <form-property name="symbol" type="java.lang.String" />

      <form-property name="portfolioStockId" type="java.lang.String" />

      <form-property name="dayThresholds" type="java.util.ArrayList" />

    </form-bean>

 

The dayThresholds property is an ArrayList of AllowedThreshold objects.
Within this object I have the setter and getter for a boolean property:

 

  private Boolean selected = Boolean.FALSE;

  

  public void setSelected(Boolean b) {

    System.out.println("+++++ setSelected called");

    selected = b;

  }

  

  public Boolean getSelected() {

    //System.out.println("+++++ getSelected called");

    return this.selected;

  }

 

This property conforms to a checkbox on my JSP page which looks like:

 

  <logic:iterate id="dayThreshold" name="thresholdForm"
property="dayThresholds" type="com.csr.sf.om.LKThresholdsAllowed">

  

    <bean:write name="dayThreshold" property="thresholdAmount" /> 

    <html:checkbox indexed="true" name="dayThreshold"
property="selected" value="true" />

  

  </logic:iterate>

 

I populate this ArrayList of objects, each object having the appropriate
Boolean value set for the selected property in the action.  The JSP page
displays the checkboxes correctly checked, but when I try to uncheck
them they never get unchecked.  I can see that when I submit the form it
goes back to the action class, but the setter for this Boolean property
is never being called.  I've read a bunch of postings about similar
problems, but I can't seem to find one with this exact problem.  Is this
a bug in DynaValidatorForm or am I doing something wrong.

 

Any help would be greatly appreciated!!!

 

Mark T.


Re: DynaValidatorForm ArrayList problem

Posted by Barry Volpe <st...@childrencare.com>.
Sorry after reading further It looks like
you have defined correctly in your struts-config.

----- Original Message ----- 
From: "Barry Volpe" <st...@childrencare.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, October 22, 2003 3:37 PM
Subject: Re: DynaValidatorForm ArrayList problem


> Here is a portion of the following link:
>
> If need be, you can extend the DynaActionForm to add custom validate and
> reset methods you might need.
> Simply specify your subclass in the struts-config instead. However, you
> cannot mix conventional properties and
> DynaProperties. A conventional getter or setter on a DynaActionForm won't
be
> found by the reflection utilities.
>
>
http://jakarta.apache.org/struts/userGuide/building_controller.html#dyna_action_form_classes
>
> "Simply specify your subclass in the struts-config instead"
>
> Not sure if this is a hint but you do need to put your subclass
> in the struts-config instead of
> org.apache.struts.validator.DynaValidatorForm
> or DynaActionForm if you are not validating
>
> Barry
>
> ----- Original Message ----- 
> From: "Mark Thill" <mt...@compsciresources.net>
> To: <st...@jakarta.apache.org>
> Sent: Wednesday, October 22, 2003 3:19 PM
> Subject: DynaValidatorForm ArrayList problem
>
>
> > I'm having a problem with checkboxes.  I have an ArrayList of objects in
> > which the objects have a getter and setter for this Boolean value which
> > is basically the on or off for the checkbox.  The checkbox displays
> > correctly, but I can never uncheck the box.  Here is the code I'm trying
> > to use:
> >
> >
> >
> > I am using DynaValidatorForm, and my struts-config.xml looks like such:
> >
> >
> >
> > com.test.struts.ThresholdForm extends DynaValidatorForm because I was
> > trying to override the reset method there, but that didn't seem to do it
> > either.
> >
> >
> >
> > <form-beans>
> >
> >     <form-bean name="thresholdForm" type="com.test.struts.ThresholdForm"

> > dynamic="true" >
> >
> >       <form-property name="symbol" type="java.lang.String" />
> >
> >       <form-property name="portfolioStockId" type="java.lang.String" />
> >
> >       <form-property name="dayThresholds" type="java.util.ArrayList" />
> >
> >     </form-bean>
> >
> >
> >
> > The dayThresholds property is an ArrayList of AllowedThreshold objects.
> > Within this object I have the setter and getter for a boolean property:
> >
> >
> >
> >   private Boolean selected = Boolean.FALSE;
> >
> >
> >
> >   public void setSelected(Boolean b) {
> >
> >     System.out.println("+++++ setSelected called");
> >
> >     selected = b;
> >
> >   }
> >
> >
> >
> >   public Boolean getSelected() {
> >
> >     //System.out.println("+++++ getSelected called");
> >
> >     return this.selected;
> >
> >   }
> >
> >
> >
> > This property conforms to a checkbox on my JSP page which looks like:
> >
> >
> >
> >   <logic:iterate id="dayThreshold" name="thresholdForm"
> > property="dayThresholds" type="com.csr.sf.om.LKThresholdsAllowed">
> >
> >
> >
> >     <bean:write name="dayThreshold" property="thresholdAmount" />
> >
> >     <html:checkbox indexed="true" name="dayThreshold"
> > property="selected" value="true" />
> >
> >
> >
> >   </logic:iterate>
> >
> >
> >
> > I populate this ArrayList of objects, each object having the appropriate
> > Boolean value set for the selected property in the action.  The JSP page
> > displays the checkboxes correctly checked, but when I try to uncheck
> > them they never get unchecked.  I can see that when I submit the form it
> > goes back to the action class, but the setter for this Boolean property
> > is never being called.  I've read a bunch of postings about similar
> > problems, but I can't seem to find one with this exact problem.  Is this
> > a bug in DynaValidatorForm or am I doing something wrong.
> >
> >
> >
> > Any help would be greatly appreciated!!!
> >
> >
> >
> > Mark T.
> >
> >
>
>
>
> ---------------------------------------------------------------------
> 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: DynaValidatorForm ArrayList problem

Posted by Mark Thill <mt...@compsciresources.net>.
Barry
The "dayThresholds" form-property is an ArrayList (see the portion of
the struts-config below).  Let's say a List of maybe 10 Stock objects.
The getter and setter methods I have down below are part of the Stock
object that is in the ArrayList.  So I don't believe that I am mixing
conventional and non-conventional here (I don't think that would be
considered).  When I display the JSP page the results I get are correct.
If maybe 5 of the 10 Stock objects have that Boolean selected property
set to true I see those 5 stocks displayed with checkboxes.  So the
getter method seems to be called correctly.  The problem is, when I
uncheck the checkbox, and submit the form the form comes back checked
still.  The setter method of my Stock object never seems to get called.
Here is what my form class looks like that extends DynaValidatorForm,
and as you saw was already configured in my struts-config file:

public class ThresholdForm extends
org.apache.struts.validator.DynaValidatorForm {
  
  /** Creates a new instance of ThresholdForm */
  public ThresholdForm() {
  }
 
  public void reset (ActionMapping mapping, HttpServletRequest request)
{
      super.reset(mapping, request);
  }  
  
}

Any suggestions or thoughts as to why the setter isn't getting called in
that "Stock" object that is part of the ArrayList???

Thanks for your help
Mark T.

-----Original Message-----
From: Barry Volpe [mailto:struts@childrencare.com] 
Sent: Wednesday, October 22, 2003 5:37 PM
To: Struts Users Mailing List
Subject: Re: DynaValidatorForm ArrayList problem

Here is a portion of the following link:

If need be, you can extend the DynaActionForm to add custom validate and
reset methods you might need.
Simply specify your subclass in the struts-config instead. However, you
cannot mix conventional properties and
DynaProperties. A conventional getter or setter on a DynaActionForm
won't be
found by the reflection utilities.

http://jakarta.apache.org/struts/userGuide/building_controller.html#dyna
_action_form_classes

"Simply specify your subclass in the struts-config instead"

Not sure if this is a hint but you do need to put your subclass
in the struts-config instead of
org.apache.struts.validator.DynaValidatorForm
or DynaActionForm if you are not validating

Barry

----- Original Message ----- 
From: "Mark Thill" <mt...@compsciresources.net>
To: <st...@jakarta.apache.org>
Sent: Wednesday, October 22, 2003 3:19 PM
Subject: DynaValidatorForm ArrayList problem


> I'm having a problem with checkboxes.  I have an ArrayList of objects
in
> which the objects have a getter and setter for this Boolean value
which
> is basically the on or off for the checkbox.  The checkbox displays
> correctly, but I can never uncheck the box.  Here is the code I'm
trying
> to use:
>
>
>
> I am using DynaValidatorForm, and my struts-config.xml looks like
such:
>
>
>
> com.test.struts.ThresholdForm extends DynaValidatorForm because I was
> trying to override the reset method there, but that didn't seem to do
it
> either.
>
>
>
> <form-beans>
>
>     <form-bean name="thresholdForm"
type="com.test.struts.ThresholdForm"
> dynamic="true" >
>
>       <form-property name="symbol" type="java.lang.String" />
>
>       <form-property name="portfolioStockId" type="java.lang.String"
/>
>
>       <form-property name="dayThresholds" type="java.util.ArrayList"
/>
>
>     </form-bean>
>
>
>
> The dayThresholds property is an ArrayList of AllowedThreshold
objects.
> Within this object I have the setter and getter for a boolean
property:
>
>
>
>   private Boolean selected = Boolean.FALSE;
>
>
>
>   public void setSelected(Boolean b) {
>
>     System.out.println("+++++ setSelected called");
>
>     selected = b;
>
>   }
>
>
>
>   public Boolean getSelected() {
>
>     //System.out.println("+++++ getSelected called");
>
>     return this.selected;
>
>   }
>
>
>
> This property conforms to a checkbox on my JSP page which looks like:
>
>
>
>   <logic:iterate id="dayThreshold" name="thresholdForm"
> property="dayThresholds" type="com.csr.sf.om.LKThresholdsAllowed">
>
>
>
>     <bean:write name="dayThreshold" property="thresholdAmount" />
>
>     <html:checkbox indexed="true" name="dayThreshold"
> property="selected" value="true" />
>
>
>
>   </logic:iterate>
>
>
>
> I populate this ArrayList of objects, each object having the
appropriate
> Boolean value set for the selected property in the action.  The JSP
page
> displays the checkboxes correctly checked, but when I try to uncheck
> them they never get unchecked.  I can see that when I submit the form
it
> goes back to the action class, but the setter for this Boolean
property
> is never being called.  I've read a bunch of postings about similar
> problems, but I can't seem to find one with this exact problem.  Is
this
> a bug in DynaValidatorForm or am I doing something wrong.
>
>
>
> Any help would be greatly appreciated!!!
>
>
>
> Mark T.
>
>



---------------------------------------------------------------------
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: DynaValidatorForm ArrayList problem

Posted by Barry Volpe <st...@childrencare.com>.
Here is a portion of the following link:

If need be, you can extend the DynaActionForm to add custom validate and
reset methods you might need.
Simply specify your subclass in the struts-config instead. However, you
cannot mix conventional properties and
DynaProperties. A conventional getter or setter on a DynaActionForm won't be
found by the reflection utilities.

http://jakarta.apache.org/struts/userGuide/building_controller.html#dyna_action_form_classes

"Simply specify your subclass in the struts-config instead"

Not sure if this is a hint but you do need to put your subclass
in the struts-config instead of
org.apache.struts.validator.DynaValidatorForm
or DynaActionForm if you are not validating

Barry

----- Original Message ----- 
From: "Mark Thill" <mt...@compsciresources.net>
To: <st...@jakarta.apache.org>
Sent: Wednesday, October 22, 2003 3:19 PM
Subject: DynaValidatorForm ArrayList problem


> I'm having a problem with checkboxes.  I have an ArrayList of objects in
> which the objects have a getter and setter for this Boolean value which
> is basically the on or off for the checkbox.  The checkbox displays
> correctly, but I can never uncheck the box.  Here is the code I'm trying
> to use:
>
>
>
> I am using DynaValidatorForm, and my struts-config.xml looks like such:
>
>
>
> com.test.struts.ThresholdForm extends DynaValidatorForm because I was
> trying to override the reset method there, but that didn't seem to do it
> either.
>
>
>
> <form-beans>
>
>     <form-bean name="thresholdForm" type="com.test.struts.ThresholdForm"
> dynamic="true" >
>
>       <form-property name="symbol" type="java.lang.String" />
>
>       <form-property name="portfolioStockId" type="java.lang.String" />
>
>       <form-property name="dayThresholds" type="java.util.ArrayList" />
>
>     </form-bean>
>
>
>
> The dayThresholds property is an ArrayList of AllowedThreshold objects.
> Within this object I have the setter and getter for a boolean property:
>
>
>
>   private Boolean selected = Boolean.FALSE;
>
>
>
>   public void setSelected(Boolean b) {
>
>     System.out.println("+++++ setSelected called");
>
>     selected = b;
>
>   }
>
>
>
>   public Boolean getSelected() {
>
>     //System.out.println("+++++ getSelected called");
>
>     return this.selected;
>
>   }
>
>
>
> This property conforms to a checkbox on my JSP page which looks like:
>
>
>
>   <logic:iterate id="dayThreshold" name="thresholdForm"
> property="dayThresholds" type="com.csr.sf.om.LKThresholdsAllowed">
>
>
>
>     <bean:write name="dayThreshold" property="thresholdAmount" />
>
>     <html:checkbox indexed="true" name="dayThreshold"
> property="selected" value="true" />
>
>
>
>   </logic:iterate>
>
>
>
> I populate this ArrayList of objects, each object having the appropriate
> Boolean value set for the selected property in the action.  The JSP page
> displays the checkboxes correctly checked, but when I try to uncheck
> them they never get unchecked.  I can see that when I submit the form it
> goes back to the action class, but the setter for this Boolean property
> is never being called.  I've read a bunch of postings about similar
> problems, but I can't seem to find one with this exact problem.  Is this
> a bug in DynaValidatorForm or am I doing something wrong.
>
>
>
> Any help would be greatly appreciated!!!
>
>
>
> Mark T.
>
>



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