Solved

Velocity with checkbox

Posted on 2009-04-15
4
2,558 Views
Last Modified: 2013-11-23
Hi,
I need to create a checkbox that reads the value if it is checked or not and then I will do some stuff depending on that.

But I cant get the checked or not checked into the code. Why?
In my servlet I add:

actionMap.put("showServer", ShowServerAction.class);
 

it goes to ShowServerAction.class
 

in my showServer.vm I have writen this:

        <tr>

        <td class="header">Hibernate&nbsp;databas&nbspupdate</td>

        <td>

        <input type="checkbox"  name="deployHibernate" value ="$deploy.hibernate"/>

        </td>

        </tr>
 

and the box shows and I can check it. When I then press the button it will bring the checkbox value....I guess.
 

I try to get the value

String deployHibernate = request.getParameter("deployHibernate");
 

The value that gets into the string is. 

deployHibernate=$deploy.hibernate
 

I would likte the string to be something like checked or notchecked.

Open in new window

0
Comment
Question by:Mickeys
  • 3
4 Comments
 
LVL 2

Expert Comment

by:gaston_acevedo
ID: 24149079
The checkbox html object not use the value attribute to inform his state. use instead the checked attribute.
If checkbox contains the checked attribute whit ANY value then his estate is checked.
You must control programatically if the templade adds or remove this attribute.
0
 

Author Comment

by:Mickeys
ID: 24154781
could you please show an example in code?
0
 
LVL 2

Expert Comment

by:gaston_acevedo
ID: 24157699
hi,
and example of what?
checkbox
or java code
0
 
LVL 2

Accepted Solution

by:
gaston_acevedo earned 500 total points
ID: 24157838
well
supose you have a variable named "mustCheck"
in velocity template, the code is

<input id="$name.$value" type="checkbox" name="$name" value="$value"#if ($mustcheck) checked#end >

Of course you can use attributes from the object used for fill the template.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java JDK Download 7 76
commonTwo  challenge 63 122
My project did see openJDK that I installed. What could be the problem 7 123
endX challenge 2 63
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.

910 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

23 Experts available now in Live!

Get 1:1 Help Now