Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DynamicForm sending all fields on update

    I've found many form threads asking how to force all fields to be sent on an update rather than just changed fields, but I'm having the opposite problem. I have a databound DynamicForm and there are many fields in the datasource that have canEdit="false". They show up on the form as non-editable text fields as you would expect, but when the 'changes' are saved, the server side receives a SQL UPDATE statement that includes ALL fields, not just the primary key and changed fields. I thought the default behavior was to send only changed fields. Here is my code related to the form. I've checked the properties I'm setting and don't find any indication that any of these properties should affect the update behavior.
    Code:
    itemForm.setDataSource(ipItemMasterDS);
    itemForm.setUseAllDataSourceFields(true);
    itemForm.setShowDetailFields(true);
    itemForm.setWidth100();
    SubmitItem submit = new SubmitItem();
    submit.setTitle("Save Changes");
    itemForm.setFields(submit);
    itemForm.setSaveOnEnter(true);

    #2
    One way to handle this is to add DMI logic to modify the DSRequest before it's run, by removing any values that are the same between dsRequest.values and dsRequest.oldValues.

    Comment


      #3
      I need to do this in some way that will apply to all data sources as many of them will contain fields that will be editable via the UI and others that will not. The default behavior of including ALL fields on the UPDATE will wreak havoc with the application. The backend legacy DB is poorly designed and includes transactional fields in domain tables, like a product master table that includes sales totals. If a user happens to change a product description while sales are being posted the "old" sales number will be updated along with the description. Can you elaborate a bit on the DMI approach? Could I use this approach generically for ALL sql data sources. Is there some way to have DynamicForms work the same as ListGrids where only the fields that were actually changed are updated? Why was this done for ListGrids and not for DynamicForms?

      Also, it seems that it would be more efficient if the list of values to be updated was pruned on the client side rather than sending them all and having them pruned on the server side. Is there a way to do that?
      Last edited by jay.l.fisher; 27 Nov 2009, 11:31.

      Comment


        #4
        I've added the following code to a subclassed IDACall and it seems to do what I'm looking for, but I have one more question.
        Code:
        if (dsRequest.getOperation().endsWith("_update")) {
        	Map<?, ?> oldValues = dsRequest.getOldValues();
        	Map<?, ?> newValues = dsRequest.getValues();
        	newValues.entrySet().removeAll(oldValues.entrySet());
        	if (newValues.isEmpty()) {
        		// How do I 'cancel' the request?	
        	}
        }
        If it turns out that NONE of the fields were changed and they are all removed from the UPDATE it generates a SQL error because the generated UPDATE statement has no fields listed. How do I cancel the remainder of the process if the newValues Map is empty?

        Comment


          #5
          In that case you could just send a dsResponse where data is the same Map you are receiving. This tells the client the update "succeeded" which is fine for your purposes.

          Note that another place to put this would be in a custom DataSource class - this would avoid any possible interference with current or future framework DataSources.

          Comment

          Working...
          X