*
*/
public Button() {
+ setValue(new Boolean(false));
setSwitchMode(false);
}
* the Button caption.
*/
public Button(String caption) {
+ this();
setCaption(caption);
- setSwitchMode(false);
}
/**
if (isSwitchMode()) {
target.addAttribute("type", "switch");
}
- boolean state;
- try {
- state = ((Boolean) getValue()).booleanValue();
- } catch (final NullPointerException e) {
- state = false;
- }
- target.addVariable(this, "state", state);
-
+ target.addVariable(this, "state", booleanValue());
}
/**
this.switchMode = switchMode;
if (!switchMode) {
setImmediate(true);
- setValue(new Boolean(false));
+ if (booleanValue()) {
+ setValue(new Boolean(false));
+ }
}
}
* @return True iff the button is pressed down or checked.
*/
public boolean booleanValue() {
- return ((Boolean) getValue()).booleanValue();
+ boolean state;
+ try {
+ state = ((Boolean) getValue()).booleanValue();
+ } catch (final NullPointerException e) {
+ state = false;
+ }
+ return state;
}
/**
* the initial state of the switch button
*/
public CheckBox(String caption, boolean initialState) {
- setCaption(caption);
- setValue(new Boolean(initialState));
- setSwitchMode(true);
+ super(caption, initialState);
}
/**
* the click listener
*/
public CheckBox(String caption, ClickListener listener) {
- setCaption(caption);
- addListener(listener);
+ super(caption, listener);
setSwitchMode(true);
}
* click events.
*/
public CheckBox(String caption, Object target, String methodName) {
- setCaption(caption);
- addListener(ClickEvent.class, target, methodName);
+ super(caption, target, methodName);
setSwitchMode(true);
}
* @param dataSource
*/
public CheckBox(String caption, Property dataSource) {
- setCaption(caption);
- setPropertyDataSource(dataSource);
+ super(caption, dataSource);
setSwitchMode(true);
}
*/
public CheckBox(String caption) {
- setCaption(caption);
- setSwitchMode(true);
+ super(caption, false);
}
public void setSwitchMode(boolean switchMode)
throw new UnsupportedOperationException(
"CheckBox is always in switch mode (consider using a Button)");
}
- this.switchMode = true;
+ super.setSwitchMode(true);
}
}