I am writing a small sample application to learn how
to validate a PropertySelection in a table. I am using
an html table and a ForEach component.

Each row represents a Person object, with name as a
TextField component and favorite color as a
PropertySelection component. I am using a list inside
Home.java hold a list of three Person objects.  It is
populated the first time that Home.java is activated.
Upon submit, each person in the 
list is being update properly.  
 
In my submit method I loop through the list of Persons
to validate that the favoriteColor is not the choice
"Red". If it is, then I want to mark the corresponding
propertySelection field with a "**" to the right of
the PropertySelection drop down.

In the submit method, I loop through the list of
persons. I check if a person.getColor().equals("Red").
The problem is that I don't know how to mark the field

as illegal because I can't call getComponent. The
rendered components have names like color, color$0,
color$1. Therefore, I can't call delegate.record. When
I call getComponent("color$1"), the system says,
component not found.
<pre>
   public void save(IRequestCycle c) {
      IValidationDelegate delegate =
(IValidationDelegate) getBeans().getBean("delegate");

      Iterator iter = getPersons().iterator();
      while(iter.hasNext()) {
         Person p = (Person) iter.next();

         if (p.getColor().equals("Red")) {
            System.out.println("error detected");
            
            // this doesn't work
            IFormComponent comp = (IFormComponent)
getComponent("color"); 
            delegate.setFormComponent(comp);
            delegate.record("can't be red",
ValidationConstraint.PATTERN_MISMATCH);
            
         } else {
            System.out.println("NO error detected");  
         
         }
      }
   }

<form jwcid="@Form">
<table>
   <tr>
      <th>name</th>
      <th>color</th>      
   </tr>
   <tr jwcid="@Foreach" source="ognl:persons"
value="ognl:person" element="tr">
         
      <td><select jwcid="[EMAIL PROTECTED]"
model="ognl:colors"
value="ognl:person.color"></select></td>      

      <td><span jwcid="[EMAIL PROTECTED]"
value="ognl:person.name"/></td>
   </tr>
</table>
<input type="image" jwcid="@Submit"
listener="ognl:listeners.save""/>
</form>
</pre>


I hope the formatting above came through ok and that I
explained the problem well enough.

Thanks,
Larry Sherrill





                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to