org.apache.myfaces.custom.convertboolean
public class: BooleanConverter [javadoc |
source]
java.lang.Object
org.apache.myfaces.custom.convertboolean.BooleanConverter
All Implemented Interfaces:
javax.faces.component.StateHolder, javax.faces.convert.Converter
Converter that translates between boolean values (true/false)
and alternate versions of those boolean values like
(yes/no), (1/0), and (way/no way).
To customize the representation of a boolean true and false,
use
#setTrueValue(String)
and
#setFalseValue(String)
respectively. If not configured with these setter methods,
it defaults to
true and
false.
The values are case sensitive.
| Field Summary |
|---|
| public static final String | CONVERTER_ID | |
| Method from org.apache.myfaces.custom.convertboolean.BooleanConverter Detail: |
public Object getAsObject(FacesContext facesContext,
UIComponent uiComponent,
String value) throws ConverterException {
if (facesContext == null)
{
throw new NullPointerException("facesContext");
}
if (uiComponent == null)
{
throw new NullPointerException("uiComponent");
}
if (value != null)
{
value = value.trim();
if (value.length() > 0)
{
try
{
return Boolean.valueOf(value.equals(trueValue));
}
catch (Exception e)
{
throw new ConverterException(e);
}
}
}
return null;
}
|
public String getAsString(FacesContext facesContext,
UIComponent uiComponent,
Object value) throws ConverterException {
if (facesContext == null)
{
throw new NullPointerException("facesContext");
}
if (uiComponent == null)
{
throw new NullPointerException("uiComponent");
}
if (value == null)
{
return "";
}
if (value instanceof String)
{
return (String) value;
}
try
{
return ((Boolean) value).booleanValue() ? trueValue : falseValue;
}
catch (Exception e)
{
throw new ConverterException(e);
}
}
|
public String getFalseValue() {
return falseValue;
}
|
public String getTrueValue() {
return trueValue;
}
|
public boolean isTransient() {
return this.isTransient;
}
|
public void restoreState(FacesContext context,
Object state) {
Object values[] = (Object[]) state;
this.trueValue = (String) values[0];
this.falseValue = (String) values[1];
}
|
public Object saveState(FacesContext context) {
Object[] values = new Object[2];
values[0] = this.trueValue;
values[1] = this.falseValue;
return values;
}
|
public void setFalseValue(String falseValue) {
this.falseValue = falseValue;
}
|
public void setTransient(boolean newTransientValue) {
this.isTransient = newTransientValue;
}
|
public void setTrueValue(String trueValue) {
this.trueValue = trueValue;
}
|