Solved

Velocity with checkbox

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
starter POM and spring-boot-starter,  spring-boot-web 2 56
github account with ecipse 1 48
netstat -ano | find "8000" and taskkill /f /pid 2984 3 57
jsp login check 12 32
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…
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.

809 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