Monday 4 November 2013

ADF - Attribute Binding dynamically created with validations

I needed to dynamically implement an attribute binding on PageDef of my fragment.
After that I could dynamically create also the item (a RichInputText) on the fragment with its validator.
There are 2 cases:
Case A) the items are created in a Table,
Case B) the items are created in a PanelFormLayout.

As has been created in the table (CASE A):


DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
JUCtrlHierBinding treeData = (JUCtrlHierBinding)dcBindings.getControlBinding(MyView);
JUCtrlHierNodeBinding nodeBind = treeData.getRootNodeBinding();
/* EDIT - Causes errors in column sorting
* Correction below
* String[] names = nodeBind.getAttributeNames();
int nItem = names.length;
String[] newNames = new String[nItem + 1];
System.arraycopy(names, 0, newNames, 0, nItem);
newNames[nItem] = "MyNewField";
nodeBind.setAttributeNames(newNames);
*/
//EDIT - Correction:
ViewObjectImpl vo = (ViewObjectImpl )treeData.getViewObject();
AttributeDef[] adfs = nodeBind.getAttributeDefs();
int nItem = adfs.length;
AttributeDef[] newAdfs = new AttributeDef[nItem + 1];
System.arraycopy(adfs, 0, newAdfs, 0, nItem);
int newAttrIndex = vo.getAttributeIndexOf(""MyNewField");
newAdfs[nItem] = vo.getAttributeDef(newAttrIndex);
nodeBind.setAttributes(newAdfs);
treeData.setAttributes(newAdfs);

Then I create the RichInputText in a RichColumn in a RichTable with its validator:

ValidatorTag.BindingValidator vb = new ValidatorTag.BindingValidator(null,JSFUtils.getValueExpression("#{row.bindings.MyNewField.validator}"));
((UIXEditableValue)
newRichInputText).addValidator(vb);

It's works!

As has been created in form (CASE B):


DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding it = ADFUtils.findIterator("MyViewIterator");
JUCtrlAttrsBinding nb = JUCtrlAttrsBinding.createAttributeBinding((JUFormBinding)dcBindings,null, "MyView", null, "MyViewIterator", "MyNewField");
dcBindings.addControlBinding("MyNewField", nb);


Then I create the RichInputText in a PanelFormLayout with its validator:

ValidatorTag.BindingValidator vb = new ValidatorTag.BindingValidator(null,JSFUtils.getValueExpression("#{bindings.MyNewField.validator}"));
((UIXEditableValue)newRichInputText).addValidator(vb);



It's  don't works!


The problem is on the validator.
I see the new InputText in my page and the value is right, but when I submit the field I see this error:

"Unable to resolve a Validator instance using either validatorId '' or binding '#{bindings.MyNewField.validator}'."


My team has published the question on Oracle Forum without any replies:

https://forums.oracle.com/thread/2513671

How I solved it?


I have dealt the case B as the case A, creating the attribute binding in the same way.

The difference was in creating the item on the page.

Is no longer been inserted in panelFormLayout but inside an Iterator in this way:

UIXIterator iter = new UIXIterator();

iter.setVar("row");
iter.setRows(1);
iter.setValueExpression("value",JSFUtils.getValueExpression("#{bindings.MyView.collectionModel}"));
iter.setValueExpression("first",JSFUtils.getValueExpression("#{bindings.MyView.currentRowIndex}"));
myPanelForm.getChildren().add(iter);

Yes, this is a workaround but now.. It's works.


No comments:

Post a Comment