Never mind folks.

I found a way to maintain my POJO autonomy and yet be able to add dynamicly generated constraints for my Select drop down.

In my PersonElement, I had to use Constrained interface:

((Constrained) person).addConstraint( new ConstrainedProperty ( "personId").inList( identifiers ) );

Apparently Constrained is another one of the interfaces available to your POJO through MetaData merging.

I find a more elegant way of doing this (adding dynamic content to drop-down list) using this component by Steven contribution to Wikki. (appreciate it much)

http://rifers.org/wiki/display/RIFE/Dynamic+select+using+dynamic+constraints

Sorry for the noise. Somehow I missed that posting in the Wikki.

j.


On 10/13/06, John Lukar <[EMAIL PROTECTED]> wrote:

Hi folks,

I am trying to generate the values of a Select drop down list dynamicaly in my Element by  using
 template.getBeanHandler().getFormBuilder().generateField()     and adding the inList() constraint.

It doesn't seem to work, unless I add the constraint to the Bean object which requires my bean to "extend Validation". 
I didn't want my POJO to do this.      I have read docs and combed the mailing list.   Below should work but doesn't.

example:

class Person {
     String name;  
     Integer roleId;  // Admin or Guess
}

class PersonElement extends Element {
public void initialize() {
        Datasource datasource = getPropertyTyped("datasource", Datasource.class);
        manager = new ContentQueryManager<Person>(datasource, Person.class );
        person= manager.restore( getInputInt("personid"));
        ......
        template = getHtmlTemplate(" person.edit");
}
public void processElement() {
         template.addResourceBundle(new ListResourceBundle() {
             public Object[][] getContents()
             {
                 return new Object[][] {
                         {"roleId:1", "ADMIN"},
                         {"roleId:2", "GUESS"}
                 };
             }});
         template.getBeanHandler ().getFormBuilder().generateField(
                 template,
                 new ConstrainedProperty ( "roleId").inList("1","2"),
                 null,
                 null);
         generateForm( template, person );
         print(template);
}

In my form.html I use the following:
            <r:v name="FORM:SELECT:roleId">id="roleId"</r:v>

This results in a empty Select drop down list.


If instead of using :

template.getBeanHandler().getFormBuilder().generateField(
                 template,
                 new ConstrainedProperty ( "roleId").inList("1","2"),
                 null,
                 null);

I use:

     person.addConstraint( new ConstrainedProperty ( "roleid").inList("1","2") );

then the dynamic Select drop-down list is properly populated. But that requires that person extend Validation.


What am I missing ?

TIA to all.
j.









_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to