Edit boolean checkbox in p:dataTable

Baderous Source

I have a datatable with row level editing. One of the columns is a <p:selectBooleanCheckbox>:

<p:dataTable id="players_table_id" var="player" value="#{playersBean.players}" rowKey="#{player.id}" paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15" emptyMessage="#{msgs.no_records}" sortBy="#{player.id}" sortOrder="ascending" rows="10" editable="true">

   <p:ajax event="rowEdit" listener="#{playersBean.onRowEdit}"/>
   <p:column headerText="#{msgs.active}" sortBy="#{player.active}" styleClass="centered-column">
         <f:facet name="output"><p:selectBooleanCheckbox value="#{optionsBean.booleanMap.get(player.active)}" disabled="true"/></f:facet>             
         <f:facet name="input"><p:selectBooleanCheckbox value="#{player.active}"/></f:facet>
   <p:column styleClass="datatable-row-editor">

The model for this table is a List, and DtoPlayer has a field "active" that is a String that keeps values retrieved from an Oracle DB ("S" and "N" for true and false). The datatable displays the values fetched correctly, because I map the strings to boolean values for output. But when I click on the pencil icon to start editing the row, the checkbox always gets unchecked (despite being checked or unchecked previously). I suppose this happens because the input facet is expecting a boolean value and instead it finds a String. I tried changing facet input to be just like the output:

<f:facet name="input"><p:selectBooleanCheckbox value="#{optionsBean.booleanMap.get(player.active)}"/></f:facet>

But another problem occured: the save icon (for saving the values edited) didn't respond to mouse click. Again I suppose this happens because now I have a boolean value in the input but my model is expecting a String.

How can I solve this problem? Do I have to change the model so that this "active" field becomes a boolean and I do the mapping boolean/String in my Java code and not in Facelets?



comments powered by Disqus