You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by t t <wa...@yahoo.com> on 2004/10/20 16:02:57 UTC

Help! problem with checkbox

Hi, all,
 
I have JSP file J1 with form F1 inside. It is used to
accept user's input. And I will display the result in
JSP file J2 with form F2. And there are a checkbox
and multibox in F2.

At first, I didn't associate F2 form bean with Action A1 which
is triggered in F1. I just associated F1 form bean with A1, and
forward the result to J2. But the server complained
that there is no getter method for the checkbox. 
So I created another action A2 (to which A1 forwards), and associate F2  form bean with
it, and I use System.out.println to print out the
result of the getter method for the checkbox. And I
did get the result. That means F2 form bean had been associated
with A2, and the getter method is there, but the
server still complains the same problem.
 
Any help will be appreciated!
Tong
 


		
---------------------------------
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!

Re: Help! problem with checkbox

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Tong,

While I appreciate that you are trying to present your information in a 
generic manner -- it is rather difficult to know what's going on without 
specifics. For checkboxes, the property needs to be a boolean. If you 
cannot figure out the problem, I suggest you include the relevant 
portions from your struts-config.xml and the ActionForm.

t t wrote:

> Hi, all,
>  
> I have JSP file J1 with form F1 inside. It is used to
> accept user's input. And I will display the result in
> JSP file J2 with form F2. And there are a checkbox
> and multibox in F2.
> 
> At first, I didn't associate F2 form bean with Action A1 which
> is triggered in F1. I just associated F1 form bean with A1, and
> forward the result to J2. But the server complained
> that there is no getter method for the checkbox. 
> So I created another action A2 (to which A1 forwards), and associate F2  form bean with
> it, and I use System.out.println to print out the
> result of the getter method for the checkbox. And I
> did get the result. That means F2 form bean had been associated
> with A2, and the getter method is there, but the
> server still complains the same problem.
>  
> Any help will be appreciated!
> Tong
>  
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> vote.yahoo.com - Register online to vote today!


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


Re: Help! problem with checkbox ( relevant code included)

Posted by t t <wa...@yahoo.com>.
Thank you, Bill, Jeff, and Wendy for all your help!
Tong

Jeff Beal <jb...@webmedx.com> wrote:
The relevant section is Section 8.8 of the specification:

"Thus when we extract a property or event name from the middle of an 
existing Java name, we normally convert the first character to lower 
case. However to support the occasional use of all upper-case names, we 
check if the first two characters of the name are both upper case and if 
so leave it alone. So for example,

'FooBah' becomes 'fooBah'
'Z' becomes 'z'
'URL' becomes 'URL'"

-- Jeff

Wendy Smoak wrote:
> From: "t t" 
> 
>>Salute you! Bill. It works! Thank you so much!
>>But why? Why does the name of a property matter? Why
>>does the upper case "A" matter?
> 
> 
> Form beans need to conform to the JavaBeans specification. That's what
> makes it possible for the framework to "know" what method to call when it
> goes through the parameters in the request and populates the Form bean.
> 
> http://java.sun.com/products/javabeans/reference/api/index.html
> 
> You must have had a mismatch between the name of the property and the name
> of the method.
> 


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


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Help! problem with checkbox ( relevant code included)

Posted by Jeff Beal <jb...@webmedx.com>.
The relevant section is Section 8.8 of the specification:

"Thus when we extract a property or event name from the middle of an 
existing Java name, we normally convert the first character to lower 
case. However to support the occasional use of all upper-case names, we 
check if the first two characters of the name are both upper case and if 
so leave it alone. So for example,

     'FooBah' becomes 'fooBah'
     'Z' becomes 'z'
     'URL' becomes 'URL'"

-- Jeff

Wendy Smoak wrote:
> From: "t t" <wa...@yahoo.com>
> 
>>Salute you! Bill. It works! Thank you so much!
>>But why? Why does the name of a property matter? Why
>>does the upper case "A" matter?
> 
> 
> Form beans need to conform to the JavaBeans specification.  That's what
> makes it possible for the framework to "know" what method to call when it
> goes through the parameters in the request and populates the Form bean.
> 
> http://java.sun.com/products/javabeans/reference/api/index.html
> 
> You must have had a mismatch between the name of the property and the name
> of the method.
> 


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


Re: Help! problem with checkbox ( relevant code included)

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "t t" <wa...@yahoo.com>
> Salute you! Bill. It works! Thank you so much!
> But why? Why does the name of a property matter? Why
> does the upper case "A" matter?

Form beans need to conform to the JavaBeans specification.  That's what
makes it possible for the framework to "know" what method to call when it
goes through the parameters in the request and populates the Form bean.

http://java.sun.com/products/javabeans/reference/api/index.html

You must have had a mismatch between the name of the property and the name
of the method.

-- 
Wendy Smoak


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


Re: Help! problem with checkbox ( relevant code included)

Posted by t t <wa...@yahoo.com>.
Salute you! Bill. It works! Thank you so much!

But why? Why does the name of a property matter? Why
does the upper case "A" matter?

Thanks again.
Tong
--- Bill Siggelkow <bi...@bellsouth.net> wrote:

> I believe the problem is the property name in your
> ActionForm. Having a 
> method named getSAll() is going to cause problems.
> Make it getSall() and 
> then the property will be 'sall' and everything will
> be much happier. Or 
> you could try more meaningful names ;)
> 
> -Bill Siggelkow
> 
> t t wrote:
> 
> > Thank you, Bill and Jeff,
> > Sorry I didn't include relevant code in my first
> post.
> > Here is the relevant code.
> > 
> > 
> > Code in J2:(with checkbox)
> >
>
----------------------------------------------------------------------
> > <html:form action="/PrepareEditMessage?reply=no"
> >            onsubmit="return
> > validateSearchResultForm(this);">
> > 
> > 
> > <table border="0" widt
h="100%">
> > 
> >   <tr>
> >   	<td><html:checkbox property="sAll" value="true"
> > title="Select all" onclick="for( i=0 ;
> > i<this.form.elements.length;
> >
>
i++){if(this.form.elements[i].name=='stringMultibox'){this.form.elements[i].checked=this.checked;}}"/></td>
> > (with other tds)
> >   </tr>
> >   <c:forEach var="person" begin="0"
> > items="${sessionScope.searchResult}">
> >     <tr>
> > 	<td><html:multibox  property="sMultibox"
> > value="${person.userID}" /></td> (with other tds)
> >     </tr>
> > 
> >   </c:forEach>
> >  
> >
>
----------------------------------------------------------------------------
> >   
> >   
> >  code in strut-config.xml:
> > 
> >
>
--------------------------------------------------------------------------------
> > 
> >   
> >        <action    path="/StartSearching"
> >                   type="javaClasses.SearchAction"
> >                   name="SearchForm"
> >                  scope="request"
> >                  input="search">
> >          	<forward name="success"             
> > path="/DisplaySearchResult.do"/>
> >        </action>
> > 
> >        <!--Show search result-->
> > 	<action path="/DisplaySearchResult"
> > 		type="javaClasses.DisplaySearchResultAction"
> > 		name="SearchResultForm"
> > 		scope="request"
> > 		validate="false">
> >                 <forward name="success"           
>  
> > path="/searchresult.jsp"/>
> > 	</action>
> > 	
> >
>
---------------------------------------------------------------------------------------
> > 
> > code of form bean:
> > 
> >
>
---------------------------------------------------------------------------------------
> > 	
> > 	public final class SearchResultForm extends
> > ValidatorForm  {
> > 
> > 
> > 
> > 
> > 	private String sMultibox[]= new String[0];
> >     	private boolean sAll=false;
> > 
> > 
> > 
> > 
> >        public String[] getSMultibox(){
> >        	  return this.sMultibox;
> >        }
> > 
> >        public void setSMultibox(String[]
> > stringMultibox){
> >           this.sMultibox=sMultibox;
> >        }
> > 
> >        public boolean getSAll(){
> >        	  return this.sAll;
> >        }
> > 
> >        public void setSAll(boolean sAll){
> >           this.sAll=sAll;
> >        }
> > 
> >     public void reset(ActionMapping mapping,
> > HttpServletRequest request) {
> > 
> >         this.sMultibox=new String[0];
> > 	this.sAll=false;
> >     }
> > 
> >     public ActionErrors validate(ActionMapping
> > mapping,
> >                                 
> HttpServletRequest
> > request) {
> > 
> >        
> >         ActionErrors errors =
> super.validate(mapping,
> > request);
> > 
> >         return errors;
> > 
> >     }
> > }
> > 
> >
>
-----------------------------------------------------------------------------------------------
> > 
> > 
> > --- Jeff Beal <jb...@webmedx.com> wrote:
> > 
> > 
> >>What's the code in J2 that you use to put the
> >>checkbox?  Are you using 
> >>an <html:form/> tag?  If so, does that tag refer
> to
> >>yet another action, 
> >>A3?  If so, which form bean is associated with A3?
> >>
> >>-- Jeff
> >>
> >>t t wrote:
> >>
> >>>Hi, all,
> >>> 
> >>>I have JSP file J1 with form F1 inside. It is
> used
> >>
> >>to
> >>
> >>>accept user's input. And I will display the
> result
> >>
> >>in
> >>
> >>>JSP file J2 with form F2. And there are a
> checkbox
> >>>and multibox in F2.
> >>>
> >>>At first, I didn't associate F2 form bean with
> >>
> >>Action A1 which
> >>
> >>>is triggered in F1. I just associated F1 form
> bean
> >>
> >>with A1, and
> >>
> >>>forward the result to J2. But the server
> >>
> >>complained
> >>
> >>>that there is no getter method for the checkbox. 
> >>>So I created another action A2 (to which A1
> >>
> >>forwards), and associate F2  form bean with
> >>
> >>>it, and I use System.out.println to print out the
> >>>result of the getter method for the checkbox. And
> >>
> >>I
> >>
> >>>did get the result. That means F2 form bean had
> >>
> >>been associated
> >>
> >>>with A2, and the getter method is there, but the
> >>>server still complains the same problem.
> >>> 
> >>>Any help will be appreciated!
> >>>Tong
> 
=== message truncated ===



		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

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


Re: Help! problem with checkbox ( relevant code included)

Posted by Bill Siggelkow <bi...@bellsouth.net>.
I believe the problem is the property name in your ActionForm. Having a 
method named getSAll() is going to cause problems. Make it getSall() and 
then the property will be 'sall' and everything will be much happier. Or 
you could try more meaningful names ;)

-Bill Siggelkow

t t wrote:

> Thank you, Bill and Jeff,
> Sorry I didn't include relevant code in my first post.
> Here is the relevant code.
> 
> 
> Code in J2:(with checkbox)
> ----------------------------------------------------------------------
> <html:form action="/PrepareEditMessage?reply=no"
>            onsubmit="return
> validateSearchResultForm(this);">
> 
> 
> <table border="0" width="100%">
> 
>   <tr>
>   	<td><html:checkbox property="sAll" value="true"
> title="Select all" onclick="for( i=0 ;
> i<this.form.elements.length;
> i++){if(this.form.elements[i].name=='stringMultibox'){this.form.elements[i].checked=this.checked;}}"/></td>
> (with other tds)
>   </tr>
>   <c:forEach var="person" begin="0"
> items="${sessionScope.searchResult}">
>     <tr>
> 	<td><html:multibox  property="sMultibox"
> value="${person.userID}" /></td> (with other tds)
>     </tr>
> 
>   </c:forEach>
>  
> ----------------------------------------------------------------------------
>   
>   
>  code in strut-config.xml:
> 
> --------------------------------------------------------------------------------
> 
>   
>        <action    path="/StartSearching"
>                   type="javaClasses.SearchAction"
>                   name="SearchForm"
>                  scope="request"
>                  input="search">
>          	<forward name="success"             
> path="/DisplaySearchResult.do"/>
>        </action>
> 
>        <!--Show search result-->
> 	<action path="/DisplaySearchResult"
> 		type="javaClasses.DisplaySearchResultAction"
> 		name="SearchResultForm"
> 		scope="request"
> 		validate="false">
>                 <forward name="success"             
> path="/searchresult.jsp"/>
> 	</action>
> 	
> ---------------------------------------------------------------------------------------
> 
> code of form bean:
> 
> ---------------------------------------------------------------------------------------
> 	
> 	public final class SearchResultForm extends
> ValidatorForm  {
> 
> 
> 
> 
> 	private String sMultibox[]= new String[0];
>     	private boolean sAll=false;
> 
> 
> 
> 
>        public String[] getSMultibox(){
>        	  return this.sMultibox;
>        }
> 
>        public void setSMultibox(String[]
> stringMultibox){
>           this.sMultibox=sMultibox;
>        }
> 
>        public boolean getSAll(){
>        	  return this.sAll;
>        }
> 
>        public void setSAll(boolean sAll){
>           this.sAll=sAll;
>        }
> 
>     public void reset(ActionMapping mapping,
> HttpServletRequest request) {
> 
>         this.sMultibox=new String[0];
> 	this.sAll=false;
>     }
> 
>     public ActionErrors validate(ActionMapping
> mapping,
>                                  HttpServletRequest
> request) {
> 
>        
>         ActionErrors errors = super.validate(mapping,
> request);
> 
>         return errors;
> 
>     }
> }
> 
> -----------------------------------------------------------------------------------------------
> 
> 
> --- Jeff Beal <jb...@webmedx.com> wrote:
> 
> 
>>What's the code in J2 that you use to put the
>>checkbox?  Are you using 
>>an <html:form/> tag?  If so, does that tag refer to
>>yet another action, 
>>A3?  If so, which form bean is associated with A3?
>>
>>-- Jeff
>>
>>t t wrote:
>>
>>>Hi, all,
>>> 
>>>I have JSP file J1 with form F1 inside. It is used
>>
>>to
>>
>>>accept user's input. And I will display the result
>>
>>in
>>
>>>JSP file J2 with form F2. And there are a checkbox
>>>and multibox in F2.
>>>
>>>At first, I didn't associate F2 form bean with
>>
>>Action A1 which
>>
>>>is triggered in F1. I just associated F1 form bean
>>
>>with A1, and
>>
>>>forward the result to J2. But the server
>>
>>complained
>>
>>>that there is no getter method for the checkbox. 
>>>So I created another action A2 (to which A1
>>
>>forwards), and associate F2  form bean with
>>
>>>it, and I use System.out.println to print out the
>>>result of the getter method for the checkbox. And
>>
>>I
>>
>>>did get the result. That means F2 form bean had
>>
>>been associated
>>
>>>with A2, and the getter method is there, but the
>>>server still complains the same problem.
>>> 
>>>Any help will be appreciated!
>>>Tong
>>> 
>>>
>>>
>>>		
>>>---------------------------------
>>>Do you Yahoo!?
>>>vote.yahoo.com - Register online to vote today!
>>
>>
>>
> ---------------------------------------------------------------------
> 
>>To unsubscribe, e-mail:
>>user-unsubscribe@struts.apache.org
>>For additional commands, e-mail:
>>user-help@struts.apache.org
>>
>>
> 
> 
> 
> 
> 		
> __________________________________
> Do you Yahoo!?
> Y! Messenger - Communicate in real time. Download now. 
> http://messenger.yahoo.com


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


Help! problem with checkbox ( relevant code included)

Posted by t t <wa...@yahoo.com>.
Thank you, Bill and Jeff,
Sorry I didn't include relevant code in my first post.
Here is the relevant code.


Code in J2:(with checkbox)
----------------------------------------------------------------------
<html:form action="/PrepareEditMessage?reply=no"
           onsubmit="return
validateSearchResultForm(this);">


<table border="0" width="100%">

  <tr>
  	<td><html:checkbox property="sAll" value="true"
title="Select all" onclick="for( i=0 ;
i<this.form.elements.length;
i++){if(this.form.elements[i].name=='stringMultibox'){this.form.elements[i].checked=this.checked;}}"/></td>
(with other tds)
  </tr>
  <c:forEach var="person" begin="0"
items="${sessionScope.searchResult}">
    <tr>
	<td><html:multibox  property="sMultibox"
value="${person.userID}" /></td> (with other tds)
    </tr>

  </c:forEach>
 
----------------------------------------------------------------------------
  
  
 code in strut-config.xml:

--------------------------------------------------------------------------------

  
       <action    path="/StartSearching"
                  type="javaClasses.SearchAction"
                  name="SearchForm"
                 scope="request"
                 input="search">
         	<forward name="success"             
path="/DisplaySearchResult.do"/>
       </action>

       <!--Show search result-->
	<action path="/DisplaySearchResult"
		type="javaClasses.DisplaySearchResultAction"
		name="SearchResultForm"
		scope="request"
		validate="false">
                <forward name="success"             
path="/searchresult.jsp"/>
	</action>
	
---------------------------------------------------------------------------------------

code of form bean:

---------------------------------------------------------------------------------------
	
	public final class SearchResultForm extends
ValidatorForm  {




	private String sMultibox[]= new String[0];
    	private boolean sAll=false;




       public String[] getSMultibox(){
       	  return this.sMultibox;
       }

       public void setSMultibox(String[]
stringMultibox){
          this.sMultibox=sMultibox;
       }

       public boolean getSAll(){
       	  return this.sAll;
       }

       public void setSAll(boolean sAll){
          this.sAll=sAll;
       }

    public void reset(ActionMapping mapping,
HttpServletRequest request) {

        this.sMultibox=new String[0];
	this.sAll=false;
    }

    public ActionErrors validate(ActionMapping
mapping,
                                 HttpServletRequest
request) {

       
        ActionErrors errors = super.validate(mapping,
request);

        return errors;

    }
}

-----------------------------------------------------------------------------------------------


--- Jeff Beal <jb...@webmedx.com> wrote:

> What's the code in J2 that you use to put the
> checkbox?  Are you using 
> an <html:form/> tag?  If so, does that tag refer to
> yet another action, 
> A3?  If so, which form bean is associated with A3?
> 
> -- Jeff
> 
> t t wrote:
> > Hi, all,
> >  
> > I have JSP file J1 with form F1 inside. It is used
> to
> > accept user's input. And I will display the result
> in
> > JSP file J2 with form F2. And there are a checkbox
> > and multibox in F2.
> > 
> > At first, I didn't associate F2 form bean with
> Action A1 which
> > is triggered in F1. I just associated F1 form bean
> with A1, and
> > forward the result to J2. But the server
> complained
> > that there is no getter method for the checkbox. 
> > So I created another action A2 (to which A1
> forwards), and associate F2  form bean with
> > it, and I use System.out.println to print out the
> > result of the getter method for the checkbox. And
> I
> > did get the result. That means F2 form bean had
> been associated
> > with A2, and the getter method is there, but the
> > server still complains the same problem.
> >  
> > Any help will be appreciated!
> > Tong
> >  
> > 
> > 
> > 		
> > ---------------------------------
> > Do you Yahoo!?
> > vote.yahoo.com - Register online to vote today!
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now. 
http://messenger.yahoo.com

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


Re: Help! problem with checkbox

Posted by Jeff Beal <jb...@webmedx.com>.
What's the code in J2 that you use to put the checkbox?  Are you using 
an <html:form/> tag?  If so, does that tag refer to yet another action, 
A3?  If so, which form bean is associated with A3?

-- Jeff

t t wrote:
> Hi, all,
>  
> I have JSP file J1 with form F1 inside. It is used to
> accept user's input. And I will display the result in
> JSP file J2 with form F2. And there are a checkbox
> and multibox in F2.
> 
> At first, I didn't associate F2 form bean with Action A1 which
> is triggered in F1. I just associated F1 form bean with A1, and
> forward the result to J2. But the server complained
> that there is no getter method for the checkbox. 
> So I created another action A2 (to which A1 forwards), and associate F2  form bean with
> it, and I use System.out.println to print out the
> result of the getter method for the checkbox. And I
> did get the result. That means F2 form bean had been associated
> with A2, and the getter method is there, but the
> server still complains the same problem.
>  
> Any help will be appreciated!
> Tong
>  
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> vote.yahoo.com - Register online to vote today!


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