Checkbox In Oracle ADF Table: Not getting or setting data

GavinWoods picture GavinWoods · Jun 10, 2013 · Viewed 15.3k times · Source

I have an application written in Oracle ADF.

In it, I have a table by which I need to add a checkbox column which maps back to a VARCHAR column.

I created a transient boolean attribute in my View Object which properly sets the real attribute. This setup works perfectly in my Business Component Tester/Browser. However, in my JSPX, the table column which gets the checkbox based on the transient attribute, does not get or set data.

This setup is done exactly as shown in this blog: Adding Boolean Checkbox to Table Component in Oracle ADF . For instance, my real attribute (which is the varchar/string), called isCurrent. I created my transient column called isCurrentBoolean (Boolean data type), which respectively has the checkbox property set. I used the Row Implementation class to properly set both attributes - which works perfectly in the ADF Business Component Tester/Browser.

However, in my table on the JSPX page, the records whom have the checkbox enabled, don't show as checked. And when i try to set data, my commit process does not run period (no errors, it literally doesnt run).

Any ideas?

Thank you!

Update 01:

I have my transient boolean attribute properly getting data based on the string/varchar attribute, now its just the setting data part thats not working.

In the Row Implementation Class, I added a message to fire every time the setter runs for IsCurrentBoolean. It does not fire when the checkbox is checked. I have autosubmit set to true. I will see if there is anything else i can do, but i may just add a method in my appliction module and have it fired in the value change listener of the checkbox - as a workaround.

JSPX Code:

<af:column sortProperty="IsCurrentBoolean" sortable="false" 
    headerText="Current?" id="c2" width="50">
<af:selectBooleanCheckbox value="#{row.IsCurrentBoolean}" id="sbc1" 
    autoSubmit="true" />

Row Impl Code: This is my setter for the transient attribute (Which sets the real attribute):

    if (value) {
        this.setProvPracIsCurrent("Y");
        setAttributeInternal(ISCURRENTBOOLEAN, value);
    } else {
        this.setProvPracIsCurrent("N");
        setAttributeInternal(ISCURRENTBOOLEAN, value);
    }

Answer

GavinWoods picture GavinWoods · Jun 11, 2013

This guy is a savior: http://adfreusablecode.blogspot.com/2012/09/afselectbooleancheckbox-with-y-n-values.html

Basically, i got rid of the transient attribute and ADF Table column using the transient attribute.

Instead, I used the attribute which maps back to the database (String/VarChar).

Added the attribute onto my table, this created an input text box. Converted the input text to a checkbox. Deleted the validator tag nested in the converted checkbox.

Created a converted a converter to translate between Boolean and String. Create a class with the following code:

  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 YNConverter() {
        super();
    }
  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;
   }
}

In faces-config.xml, add the class and define it as a Converter. Named it YNConverter.

In the JSP page, my checkbox looks like the following:

   <af:selectBooleanCheckbox value="#{row.bindings.ProvPracIsCurrent.inputValue}"
                                                      label="#{bindings.Ppsqnd4UppUpViewView.hints.ProvPracIsCurrent.label}"
                                                      required="#{bindings.Ppsqnd4UppUpViewView.hints.ProvPracIsCurrent.mandatory}"
                                                      shortDesc="#{bindings.Ppsqnd4UppUpViewView.hints.ProvPracIsCurrent.tooltip}"
                                                      id="it12"
                                                      converter="YNConverter"/>

Boom. Done.