Solved

Struts html:checkbox always enabled.

Posted on 2007-04-02
6
1,073 Views
Last Modified: 2013-11-24
I'm using the Struts html:checkbox .  I have a checkbox called showTimeline.  If checked, I show a timeline graph on my jsp page.  if not, I want to not show the graph.

The problem is that if I set the checkbox to false , the checkbox sets itself to true.  Almost like something always turns the checkbox on.

My form has these methods:
       boolean showTimeline;
       public boolean isShowTimeline() {
            return showTimeline;
      }
      public boolean getShowTimeline(){
            return showTimeline;
      }

My JSP has this code:
      <tr><td>Enable Timeline</td>
          <td><html:checkbox property="showTimeline"></html:checkbox>
          </td>
      </tr>


So far my Action class does nothing but print the parameter:
   System.out.println(form.isShowTimeline());  // always prints "true"


How do I make my html:checkbox behave properly?  Meaning I uncheck the box and resubmit the form, I want to form to contain "false" and the box to remain unchecked.
0
Comment
Question by:tmonteit
  • 3
  • 2
6 Comments
 

Author Comment

by:tmonteit
Comment Utility
!!correction!! the form has these methods:

My form has these methods:
       boolean showTimeline;
       public boolean isShowTimeline() {
            return showTimeline;
      }
      public void setShowTimeline(boolean showTimeline){
           this.showTimeline = showTimeline;
     }
0
 
LVL 10

Accepted Solution

by:
Jaax earned 250 total points
Comment Utility
In your reset method, explicitly set the ShowTimeline to false and then try.
0
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 250 total points
Comment Utility
Try Jaax's suggestion.

If it still does not work, try to retrieve the values not as boolean but as a String and see what do you get.

David
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:tmonteit
Comment Utility
I would actually prefer to work this checkbox with a String rather than a boolean.  

The only example of html:checkbox used a boolean.

Do you have an example of how to build an html:checkbox using a STRING.  like "TRUE" if checked "FALSE" if not.
0
 
LVL 10

Expert Comment

by:Jaax
Comment Utility
Please read the info present here :http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html
It states that.

It states 'The underlying property value associated with this field should be of type boolean'
and also cautions developers to set the checkbox values to false in the reset
0
 

Author Comment

by:tmonteit
Comment Utility
So, I already am using boolean.  What's wrong with the code that makes it not work properly?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now