Show TOC Start of Content Area

Procedure documentation Re-Initialization of Invalid Context Attributes

However, the solution is not perfect. If there were an additional validating Save action on this UI, the Save action would still not be executed, because there is still a validation error pending for the input field married since. Even worse, since the non-validating event handler disabled the input field, the end user cannot correct the invalid data. Imagine if the input field were not disabled but became invisible by navigation. In that case, the end user would be completely lost.

Therefore, the non-validating action event handler must re-initialize all context attributes that are no longer needed. The code for the changed event handler is as follows:

 

Re-initialization of invalid context attribute in view controller FormView.java

public void onActionIsMarriedChanged(  

  com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,

  java.lang.String isMarried )

{

  //@@begin onActionIsMarriedChanged(ServerEvent)

  if (isMarried.equals("IsNotMarried_Key")) {

    IWDValidationCheck checker = wdComponentAPI.getValidationCheck();

 

    if (!checker.isValidAttribute(

        wdContext.currentPersonElement(),

        wdContext.nodePerson().getNodeInfo().getAttribute(

          IPrivateFormView.IPersonElement.WEDDINGDAY))) {

        wdContext.currentPersonElement().setWEDDINGDAY(null);

      }

  }

 

  wdContext.currentContextElement()

    .setMarriedSinceEnabled(isMarried.equals("IsMarried_Key"));

  //@@end

}

 

The implementation of the action event handler must not only change the state of the input field, but it should also check the validation state of the context attribute that is bound to the value property of the input field that will become disabled. If the context attribute is not valid, it should be reset to a valid value. By resetting the context attribute, the validation error is removed and thus a subsequent validating action event handler like Save will be executed.

Next Section:

Golden Rules for Validating and Non-Validating Actions

 

End of Content Area