1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.widget;
9
10 import com.tirsen.angkor.RenderContext;
11 import com.tirsen.angkor.Component;
12
13 import java.io.IOException;
14
15 /***
16 * @author $Author: tirsen $
17 * @version $Revision: 1.5 $
18 * <BR>
19 * $Id: CheckboxInput.java,v 1.5 2002/10/13 19:59:23 tirsen Exp $
20 */
21 public class CheckboxInput extends Component
22 {
23 private ValueModel model;
24 private TextLabel prompt;
25
26 public CheckboxInput(String id)
27 {
28 super(id);
29 }
30
31 public CheckboxInput()
32 {
33 }
34
35 public CheckboxInput(String prompt, ValueModel model)
36 {
37 setPrompt(prompt);
38 this.model = model;
39 }
40
41 /***
42 * @param model a ValueModel that return values of type Boolean.
43 */
44 public void setModel(ValueModel model)
45 {
46 this.model = model;
47 }
48
49 public void setPrompt(TextLabel prompt)
50 {
51 this.prompt = prompt;
52 }
53
54 public void setPrompt(String promptText)
55 {
56 prompt = new TextLabel();
57 prompt.setLabel(promptText);
58 }
59
60 public void setVisible(boolean visible)
61 {
62 super.setVisible(visible);
63 prompt.setVisible(visible);
64 }
65
66 public boolean isParsing()
67 {
68 return true;
69 }
70
71 public void parse(RenderContext context)
72 {
73 super.parse(context);
74 if (isVisible() && model != null && !model.isReadOnly())
75 {
76 boolean value = "on".equals(context.getRequestParameter(getId()));
77 model.setValue(new Boolean(value));
78 }
79 }
80
81 public void render(RenderContext context) throws IOException
82 {
83 if (isVisible())
84 {
85 String checked = "";
86 if (model != null && ((Boolean) model.getValue()).booleanValue())
87 {
88 checked = " checked ";
89 }
90 context.startTag("INPUT type=\"checkbox\" name=\"" + uniqueId(context) + "\"" + checked);
91 if (prompt != null) prompt.render(context);
92 context.registerParsingComponent(this);
93 }
94 }
95 }
This page was automatically generated by Maven