Solved

Struts html:checkbox always enabled.

Posted on 2007-04-02
6
1,102 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
ID: 18841462
!!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
ID: 18841553
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
ID: 18841679
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tmonteit
ID: 18848617
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
ID: 18848646
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
ID: 18850553
So, I already am using boolean.  What's wrong with the code that makes it not work properly?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

685 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