I am trying to persist checkbox of a datatable item.
In simple terms, I need to persist this checkbox. Once it is checked, it needs to stay checked until it is unchecked via GUI.
<p:column width="20">
<p:selectBooleanCheckbox value="#{datas.data_checkbox}" onchange="selectme(#{indexvar});">
<p:ajax event="change"
async="true"
process="@form"
global="true"
update="data_tab"
listener="#{datasBean.updateDataProcess}">
<f:setPropertyActionListener value="#{datas}" target="#{datasBean.selectedData}"/>
</p:ajax>
</p:selectBooleanCheckbox>
</p:column>
public void updateDataProcess() {
try {
System.out.println("Update process is in progress...");
if (selectedData.getData_process() == "true") {
System.out.println("Process value is true");
dataAccessObject.updateDataProcess(selectedData.getData_pk(),"1" );
}
if (selectedData.getData_process() == "false") {
System.out.println("Process value is true");
dataAccessObject.updateDataProcess(selectedData.getData_pk(),"0" );
}
}
catch (SocketTimeoutException ex) {
ex.printStackTrace();
}
}
public Integer updateDataProcess(String data_pk, String data_process) throws SocketTimeoutException {
try {
//&setDataStatus=true&dataPk=2&dataStatus=2
String updateDataProcessUrl = urlconstants.data_api_url + "/data.jsp?mrs_rest=true"
+ "&setDataProcess=true"
+ "&dataPk=" + data_pk
+ "&dataProcess=" + data_process;
System.out.println("json_call=" + updateDataProcessUrl);
return Integer.parseInt(tools.getJSON(updateDataProcessUrl, 5000).trim());
} catch (JsonSyntaxException ex) {
ex.printStackTrace();
return null;
}
}
I have a JSON utility which can write integer to a data column in the database as well.
I am not sure if the checkbox callback is expecting boolean or not.
If it is, do I need to convert the boolean to integer and vice versa?
I do not seem to be able to persist this type of data.
Aucun commentaire:
Enregistrer un commentaire