Announcement

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

    Can't save Empty value in a foreign key field

    Hi,

    I've a table USER with a field called DEVICE_FK which is a foreign key reference on the table DEVICE. The field DEVICE_FK is not a mandatory and can be NULL.

    I've a BoundForm which has the USER datasource as its datasource and a SelectItem with the DEVICE datasource set as OptionDataSource for the field DEVICE_FK so that a drop down box is shown to the user. The setAllowEmptyValue is set true on SelectItem so that a user can also choose an empty value from the drop down box.

    This is all fine and works correctly but when the user selects the empty value from the drop down list and saves, nothing is sent to the server for the DEVICE_FK. I would have expected that a NULL value would be saved in the DEVICE_FK field for the user has CHANGED the value.
    The user has now no way to remove his selection from the database.

    I would appreciate your help.

    #2
    Since no one could help me and since I found a solution, I would like to share it here so that some one may find some help.

    Code:
    final FormItem frmItem = boundForm.getField("DEVICE_FK");
    frmItem.addChangeHandler(new ChangeHandler(){
    	public void onChange(ChangeEvent event) {
    		if(event.getOldValue() != null && event.getValue() == null){
    			frmItem.setValue((Integer)null);
    		}												
    	}
    });

    Comment

    Working...
    X