Hello
You are generating Select filed by

t.getBeanHandler().getFormBuilder().generateField(
     t,
     new ConstrainedProperty( "friendTypeId" ).inList( identifiers ),
                              null,
                              "" );

in printForm function.

When you regenerate the form if !friend.validate() , then generateForm(template, friend ),
regenerate all form fields. So the list is overwrites by this.

Followings are the 2 solutions may be adopted. I recommend second.


Solutions 1)
// is oke
printForm( friendTypeList, template );
print( template );

// select list not generated (i.e. empty)
if ( !friend.validate() ) {
   generateForm( template, friend );
   printForm( friendTypeList, template );
   print( template );
}

Solutions 2)

// is oke
String[]  identifiers = printForm( friendTypeList, template );
friend.addConstraint( new ConstrainedProperty( "friendTypeId" ).inList( identifiers ));
 generateForm( template, friend );
print( template );

// select list not generated (i.e. empty)
if ( !friend.validate() ) {
 String[]  identifiers =printForm( friendTypeList, template );
friend.addConstraint( new ConstrainedProperty( "friendTypeId" ).inList( identifiers ));
 generateForm( template, friend );
 print( template );
}

// 'cloned' from a Bamboo example (free source to read is great!!)
public String[]  printForm( List<FriendType> friendTypeList, Template t ) {
 String[] identifiers = new String[ friendTypeList.size() ];
 List<Object[]> labelList = new ArrayList<Object[]>();
 for( int i = 0; i < friendTypeList.size(); i++ ) {
   FriendType friendType = friendTypeList.get( i );
   String friendTypeId = String.valueOf( friendType.getId() );
   identifiers[ i ] = friendTypeId;
   labelList.add(new Object[] { "friendTypeId:" + friendTypeId,
friendType.getType() } );
 }
 final Object[][] resources = labelList.toArray( new Object[0][0] );
 t.addResourceBundle( new ListResourceBundle() {
     protected Object[][] getContents() {
       return resources;
     }
 });
return  identifiers ;
 }



Regards

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

Reply via email to