if you have a column in table that contain values like Y,N or 0,1
and want to display it to user in selectBooleanCheckBox
then you can do it in a simple way like what i will explain
first of all we will do that by using converter Class ,
it will play the role to Convert Y --> true and N-->false and vice versa
create Converter Class like the following
the second step is to add this Converter in faces-config.xml:
the Final step is to use this converter in the Component
and want to display it to user in selectBooleanCheckBox
then you can do it in a simple way like what i will explain
first of all we will do that by using converter Class ,
it will play the role to Convert Y --> true and N-->false and vice versa
create Converter Class like the following
package youPackage.converters;import java.util.Collection;import java.util.Collections;import javax.faces.component.UIComponent;import javax.faces.context.FacesContext;import javax.faces.convert.Converter;import org.apache.myfaces.trinidad.convert.ClientConverter;public class YNConverter implements Converter, ClientConverter{ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) { return "true".equals(value) ? "Y" : "N"; } public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) { return "Y".equals(value) ? "true" : "false"; } public String getClientLibrarySource(FacesContext facesContext) { return null; } public Collection<String> getClientImportNames() { return Collections.emptySet(); } public String getClientScript(FacesContext facesContext, UIComponent uiComponent) { return null; } public String getClientConversion(FacesContext facesContext, UIComponent uiComponent) { return null; }}the second step is to add this Converter in faces-config.xml:
<converter> <converter-id>YNConverter</converter-id> <converter-class>youPackage.converters.YNConverter</converter-class></converter>the Final step is to use this converter in the Component
<af:selectBooleanCheckbox value="#{row.bindings.Disabled.inputValue}" label="#{bindings.VipUserVO.hints.Disabled.label}" converter="YNConverter" id="sbc1"/>
No comments:
Post a Comment