I would do something like this, because it's very reusable:

Change your model from this:
new PropertyModel(this, "ipLocationInfo.country")

to:
new NotNullModel(new PropertyModel(this, "ipLocationInfo.country"), new
StringResourceModel("nullValue", null))

Then add nullValue=FOO BAR to your properties (you get the idea)

Here's that implementation:

public class NotNullModel implements IModel {

    private static final long serialVersionUID = 1L;

    private final IModel mNestedModel;
    private final IModel mNullObjectModel;

    public NotNullModel(IModel model, IModel nullValueModel) {
        if (model == null || nullValueModel == null) {
            throw new IllegalArgumentException("nested model must be
non-null");
        }
        mNestedModel = model;
        mNullObjectModel = nullValueModel;
    }

    public Object getObject() {
        Object obj = mNestedModel.getObject();
        return obj == null ? mNullObjectModel.getObject() : obj;
    }

    public void setObject(Object object) {
        mNestedModel.setObject(object);
    }

    public void detach() {
        mNestedModel.detach();
    }

}


Jeremy Thomerson
http://www.wickettraining.com


On Mon, May 5, 2008 at 9:30 AM, AlexTM <[EMAIL PROTECTED]> wrote:

>
> Hi!
>
> I'm quite new to Wicket and help with something easy, i guess.
>
> I'm displaying some info on my page:
>
> add(new Label("country", new PropertyModel(this,
> "ipLocationInfo.country")));
>
> The country information is sometimes null and then i would like to display
> "unknown" instead. Is this easily managed or do i have to change the
> country
> value of the ipLocationInfo object?
>
> Regards Alex
> --
> View this message in context:
> http://www.nabble.com/Display-a-String-when-null-tp17062912p17062912.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to