JSP Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 183 Page Views: 

Why are my checkboxes not being set from ON to OFF?



Posted By: Avi Date: 6 November 2010 06:47:00 AM
 Answer:

A problem with a checkbox is that the browser will only include it in the request when it is checked. If it is not checked, the HTML specification suggests that it not be sent (i.e. omitted from the request). If the value of the checkbox is being persisted, either in a session bean or in the model, a checked box can never unchecked by a HTML form -- because the form can never send a signal to uncheck the box. The application must somehow ascertain that since the element was not sent that the corresponding value is unchecked. The recommended approach for Struts applications is to use the reset method in the ActionForm to set all properties represented by checkboxes to null or false. The checked boxes submitted by the form will then set those properties to true. The omitted properties will remain false. Another solution is to use radio buttons instead, which always submit a value. It is important to note that the HTML specification recommends this same behavior whenever a control is not "successful". Any blank element in a HTML form is not guaranteed to submitted. It is therefor very important to set the default values for an ActionForm correctly, and to implement the reset method when the ActionForm might kept in session scope.


Posted By: avibtech


Date: 6 November 2010 06:47:00 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image Ol38k5
Related Questions
JSP : How can I enable session tracking for JSP pages if the browser has disabled cookies?

How can I enable session tracking for JSP pages if the browser has disabled cookies?

You can still use session tracking using URL rewriting and it should to append the session ID for ea....
Category: JSP Date: 11/3/2010 8:48:57 PM
JSP : What is deployment descriptor?

What is deployment descriptor?

A deployment descriptor is an XML based file which describes a web application's  deployment se....
Category: JSP Date: 11/3/2010 3:31:59 PM
JSP : What is Server side push?

What is Server side push?

It used to refresh a servlet and that happens when client first connects to Server, then Server keep....
Category: JSP Date: 11/3/2010 2:26:57 PM
JSP : What are the parameters for service method ?

What are the parameters for service method ?

ServletRequest and ServletResponse
Category: JSP Date: 11/3/2010 1:53:57 PM
JSP : What is URL Encoding and URL Decoding ?

What is URL Encoding and URL Decoding ?

URL encoding is the method of replacing all the spaces and other extra characters into their corresp....
Category: JSP Date: 11/3/2010 12:04:58 PM