Solved

Struts html:checkbox always enabled.

Posted on 2007-04-02
6
1,094 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

839 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