Old approach:
XspInputText field = (XspInputText) StandardUtil.findComponent(facesContext .getViewRoot(), “countryName”);
The annoying thing about this approach: You never know exactly which class the component has, ie. a “read only” field is not XspInputText etc., and thus you cannot just use this approach really transparently.
New approach:
DominoDocument dominoDoc = StandardUtil.getDominoDocument();
dominoDoc.replaceItemValue(“editableField”, new Date().toString());
It works for editable/hidden/disabled/readOnly fields!!!
And the best thing is: you do not even need to know the fields xPage name anymore!
You only care about set in the binding property. This in effect speeds up development a lot, cause I do not need to check/modify field names in 2 places anymore.
addendum:
the getDominoDocument works like this:
DominoDocument dominoDoc = (DominoDocument) JSFConnector
.getVariableValue(“currentDocument”);
return dominoDoc;
and the JSFConnector you will find here (kudos to Karsten Lehmann)
You can make this even simpler using the DataObject methods on DominoDocument. Since it implements the DataObject interface, you can skip a lot of type-conversion works and just do…
dominoDoc.setValue("editableField", new Date());
Which means you can also just do…
dominoDoc.getValue("editableField");
Using these methods instead of replaceItemValue and getItemValueString/Integer/Double etc, you can future-proof your code so it doesn't matter whether you're using Domino as your datasource. You could change it to a REST service, XML, RDBMS, Couchbase, or anything else capable of implementing the com.ibm.xsp.model.DataObject interface, and you're all set.
Hi Nathan
Thanks for this great tip! Excellent… (tested it and it works.. heavenly…)
I know I don't know too much about all that stuff and I know I am not the only one out there having similar problems, that's why I try to tell about my experiences.
And if people like you give me feedback on my stuff that makes me feel very proud. It looks like my blog indeed has in the meantime reached a certain crowd.
Thanks a lot
Michael