Hi,
I’m trying to implement a functionality in CAF with which a user can add/remove rows in a table and on click of save button the action should get all the row values from the table and send it to a flow service.
So far I have a service which populates the row values in the table from the database. After the user adds a new row and enters values in the text boxes and clicks save the new row disappears. i.e the row is getting added on client side but the values are not sent to server side.
Here is the code that im using for save action.
public String saveUsers() {
selectedRWProperty = new java.util.ArrayList<java.lang.String>();
List<Object> selectedRows = this.resultProvider.getSelectedRows();
if (selectedRows != null && selectedRows.size() != 0) {
for (Iterator iterator = selectedRows.iterator(); iterator.hasNext();) {
com.webmethods.caf.is.wsclient.myPackage.cafservices.selectusers_caf.__results c = (
com.webmethods.caf.is.wsclient.myPackage.cafservices.selectusers_caf.__results) iterator.next();
//These are the different fields in each row
selectedRWProperty.add(c.getUSERNAME());
selectedRWProperty.add(c.getPLANTCODE());
selectedRWProperty.add(c.getGROUPING());
selectedRWProperty.add(c.getWRITE());
selectedRWProperty.add(c.getREAD());
}
}
resolveDataBinding(SAVEUSERS_PROPERTY_BINDINGS, this, "saveUsers.this", true, false);
return OUTCOME_OK;
}
After i click the save button, the newly added rows disappear and also the values are not sent to the server.
What might be the problem? Or is there any steps that I need to follow while implementing the add/remove row functionality?
You may have more luck directly updating the model (ie the data source the Content Provider is using) with the new row. It sucks, but CPs often can’t be trusted to do what they advertise they can do
Sorry, because this brings its own set of problems, particularly if you change the data model in IS later, but give it a shot. At least those problems can be solved with tedious amounts of Java mappings!
You must use an ‘updateable’ table content provider.
If there are validation or conversion errors in the submitted form, the request lifecycle will fail during the ‘validate’ phase and never make it to the ‘update model’ phase where the table rows are added to the backing content provider.
Is it possible to see a minimal CAF project where this works? A (selectable) updateable content provider on top of a document list, which makes a table, there’s a CAF Add Row Button on the table, and when the form the table’s in is submitted, the original document list is updated?
Sorry for a big ask, but I’ve never seen this working, and your post gave me hope!
Okay - this is the way I’ve found. Basically entirely thanks to Javier.
Includes obvious stuff. Parts only there to show what’s happening are in italics:
Have a document list in the CAF bindings that represents what the table will display/update (here called docList; document type caf.war.sampleProject.is.document.Sample_doc_listDoc)
Right click on the document list / create new content provider (selectable/updateable) (here called docListProvider)
Double click on docListProvider in bindings to open the following code: