You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by HHB <hu...@yahoo.ca> on 2009/05/06 09:16:25 UTC

How to manipulate values in a data table?

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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to manipulate values in a data table?

Posted by Linda van der Pal <lv...@heritageagenturen.nl>.
Turn it into an object with that status as an integer and a name as 
String? Then the toString should return the name. You could possibly 
even use an enum.

Linda

HHB wrote:
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.325 / Virus Database: 270.12.18/2096 - Release Date: 05/04/09 17:51:00
>
>   


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


Re: How to manipulate values in a data table?

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


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


Re: How to manipulate values in a data table?

Posted by Mathias Nilsson <wi...@gmail.com>.
If it only can hold one value then an enum would be ok.

public interface Translatable{
   public String getResourceKey();
}

public enum Status implements Translatable{
   
    NOT_SENT( 0, "resource.notsent" ),
    SENT( 1, "resource.sent" );

    private int status;
    private String resourceKey;

    Status( int status, String resourceKey ){
       this.status = status;
       this.resourceKey = resourceKey;
    }
 

    public int getStatus(){
      return status;
    }


    public String getResourceKey(){
      return resourceKey;
    }
}

If you use this in an DropDownChoice or want to use it in a label the
resourcekey should do the trick if the application is multilanguage
-- 
View this message in context: http://www.nabble.com/How-to-manipulate-values-in-a-data-table--tp23401292p23412644.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: How to manipulate values in a data table?

Posted by Steve Flasby <st...@flasby.org>.
Use a class to represent this and then add a customized ConverterLocator to your Application.
I find the ConverterLocator very powerful, you get consistent rendering across the entire
application without having to do anything special.


Hope this helps.

Cheers - Steve



HHB wrote:
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 

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