Hello,

The easy way is to create a custom column and use that to convert the value.

i.e. extend ProperyColumn and override the protected IModel<?> createLabelModel(IModel<T> rowModel) method such that it converts the inner value (0 or 1) into the string value you want.


   @SuppressWarnings("unchecked")
   protected IModel<?> createLabelModel(IModel<T> rowModel)
   {
// here we use a wrapping model that will convert the integer value returned from the property model. return new IntegerToStringModel (PropertyModel(rowModel, propertyExpression), new String[] {"Sent", "Not Sent"});
   }


// this class converts the integer to one of the defined options.
public class IntegerToStringModel extends AbstractReadOnlyModel<String> {

   private final IModel<Integer>    integerModel;
   private final String[]            options;

   /**
    *
    */
public IntegerToStringModel(IModel<Integer> integerModel, String[] options) {

       this.integerModel = integerModel;
       this.options = options;

       // TODO Auto-generated constructor stub
   }

   /*
    * (non-Javadoc)
    *
    * @see org.apache.wicket.model.AbstractReadOnlyModel#getObject()
    */
   @Override
   public Object getObject() {

       int value = this.integerModel.getObject();

       switch (value) {
       case 0:
           return options[0];
       case 1:
           return options[1];
       default:
           return "undefined";

       }
   }
}

Regards,

Mike


Hey,
I have a message class that has a status (which it is an integer)
 to indicate whether the message has been sent successfully.
Inside a data table, how to handle this integer values so instead
 of displaying 0 or 1, it displays "Sent" or "Not Sent"?
Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to