Tuesday, November 24, 2009

Setting value programmatically on required field.

It is common requirement when you set a value in one field to also set a value to a second field.

This we usually do on setter of view object of the first field or the valueChangeListener also by adding a partialTrigger on the second field.

Yet if the second field is required and the previous value is null then nor the setter nor the valueChangeListener are invoked because of validation error.

This is because the partialTrigger is trying to refresh the second field before even submitting the first field.

Is this a bug or intended behavior?

The workaround we found is to remove partial trigger from second field and on valueChangeListener of the first field to use addPartialTarget

In the test case when you select department we want to set manager also, so in the setter of department id there is:
public void setDepartmentId(Number value) {
setAttributeInternal(DEPARTMENTID, value);
this.setManagerId(new Number(100));

Also managerId field is set required=true

Test case:

No comments:

Post a Comment