22 Sept 2012

Dynamic iterator binding and method action call

In my previous post I mentioned that we can use dynamic binding approach in an effort to get the VO instance name evaluated dynamically at run-time. So, in the PageDef file we can have the following definition:


<iterator Binds="#{someViewObjectName}" RangeSize="25"   
               DataControl="AgileDataModelServiceDataControl"  
               id="VAgileIterator"/>



And EL #{someViewObjectName} is going to be evaluated as a name of some view object instance in the AgileDataModelService application module. And let's assume that any VO instance, which name is evaluated by the EL expression, inherits some parent view object VAgile. And its implementation class VAgileImpl contains some public method returning a String:

    public String getSomeString() {
        return ...;
    }


We're going to publish this method in VO's client interface and make it invokable from the UI via  binding layer. So, we're going to define a methodAction in the PageDef file in order to invoke the method for the particular VO instance, which name is going to be evaluated by the #{someViewObjectName} EL expression:

<methodAction id="getSomeString" RequiresUpdateModel="true"
              Action="invokeMethod" MethodName="getSomeString"
              IsViewObjectMethod="true"
              DataControl="AgileMetaDataModelServiceDataControl"
              InstanceName="???"
              ReturnName="data.AgileMetaDataModelServiceDataControl.methodResults.getSomeString_AgileMetaDataModelServiceDataControl_VAgile_getSomeString_result"/>

But a methodAction definition has an InstanceName attribute, supposed to contain a name of the particular VO instance. Since we're using the dynamic iterator binding approach, we don't know the instance name, it's going to be evaluated at run time by the EL expression. Unfortunately we can't use EL expressions in the Instance attribute. The workaround is to use an iterator bindings VAgileIterator to get the instance of the VO. So we can do the following:

<methodAction id="getSomeString" RequiresUpdateModel="true"
              Action="invokeMethod" MethodName="getSomeString"
              IsViewObjectMethod="false"
              DataControl="AgileMetaDataModelServiceDataControl"
              InstanceName="bindings.VAgileIterator.viewObject"
              ReturnName="data.AgileMetaDataModelServiceDataControl.methodResults.getSomeString_AgileMetaDataModelServiceDataControl_VAgile_getSomeString_result"/>

Have a note, that we used bindings.VAgileIterator.viewObject in the InstanceName attribute and the IsViewObjectMethod attribute is false. Actually, that's it. It works.

No comments:

Post a Comment

Post Comment