Solved

Velocity with checkbox

Posted on 2009-04-15
4
2,536 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 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…
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.

758 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

21 Experts available now in Live!

Get 1:1 Help Now