You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Greg Johnson <gr...@saltaire.com.au> on 2004/09/14 09:50:28 UTC

How to get the target class/property of an ognl expression

hi guys,
in the style of "... j2ee development without ejb", that suggests getting back 
to richer domain objects, i am looking at a generic domain object based 
validator (eg using domain objects that include isValidProperty() in addition 
to getProperty() & setProperty()).

what would be the best way to get from an ExpressionBinding to the target 
class/property in order to call the appropriate isValidProperty() method?

hope the following gives a bit of an idea as to what i'm trying to achieve.

many thanks,
greg johnson

Example:
using the following .jwc snippet:
<component-specification class="..." 
 <property-specification name="phone" type="com.example.Phone"/>
 ...
 <component id="phoneNumber" type="ValidField">
     <binding name="value" expression='phone.number'/>
     <binding name="validator" expression="beans.domainValidator"/>
  ...
 </component>

and class DomainValidator that might include something like this:
 class DomainValidator implements IValidator {

 public Object toObject(IFormComponent field, String s) 
  throws ValidatorException {
  if (s == null)
   return null;
  IBinding b = field.getBinding("value");
  <magic bit>
  ...
  target = ...
  propertyName = ...
  </magic bit>
      method = target.getClass().getMethod("isValid"+propertyName, ...);
      method.invoke(target, ...);
  ...
what might the <magic bit> look like?

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org