|
INTERVIEW QUESTIONS
J2EE
STRUTS
DETAILS
Question: Why are my checkboxes not being set from ON to OFF?
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
|
|
|
Category |
Struts Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9705 users |
Added on |
8/31/2014 |
Views |
70523 |
Rate it! |
|
|
Question:
Why are my checkboxes not being set from ON to OFF?
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 Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Why doesn't the focus feature on the <html:form> tag work in every circumstance?
|
View Answer
|
|
Can I use multiple HTML form elements with the same name?
|
View Answer
|
|
Can I use multiple HTML form elements with the same name?
|
View Answer
|
|
Do ActionForms have to be true JavaBeans?
|
View Answer
|
|
Why is ActionForm a base class rather than an interface?
|
View Answer
|
|
Why are some of the class and element names counter-intuitive?
|
View Answer
|
|
What is a modular application? What does module-relative mean?
|
View Answer
|
|
Why was reload removed from Struts (since 1.1)?
|
View Answer
|
|
Is there a particularly good IDE to use with Struts
|
View Answer
|
|
What about JSTL and JavaServer Faces ?
|
View Answer
|
|
Will the Struts tags support other markup languages such as WML ?
|
View Answer
|
|
Are the Struts tags XHTML compliant ?
|
View Answer
|
|
Why aren't the Struts tags maintained as part of the Jakarta Taglibs project ?
|
View Answer
|
|
What's the difference between Struts and Turbine? What's the difference between Struts and Espresso?
|
View Answer
|
|
Where can I get help with Struts?
|
View Answer
|
|
If the framework doesn't do what I want, can I request that a feature be added?
|
View Answer
|
|
Does Struts include its own unit tests?
|
View Answer
|
|
When do I need "struts.jar" on my classpath?
|
View Answer
|
|
How do I install Struts?
|
View Answer
|
|
Where can I get a copy of Struts?
|
View Answer
|