Solved

Struts html:checkbox always enabled.

Posted on 2007-04-02
6
1,078 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
DevOps Toolchain Recommendations

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

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to disable hibernate query cache 2 76
for loop with Set 4 48
array11 challenge 16 59
printing a file in reverse order is easy in recursion rather than in iteration 3 48
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…
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.

929 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

12 Experts available now in Live!

Get 1:1 Help Now