Nullable resource link
Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Nullable resource link
i don't understand the problem can't you check the resource before link is rendered? You can create a new resource object empty in the case of null bytesand setVisible(false) or extend link to do this automatically on empty resource... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Nullable resource link
I'm fishing for best practice in this type of situation - do I use the solution you outlined, or do I add a simple invisible dummy link instead of the the resource link, or is there a better solution that I'm missing? Luca Provenzani wrote: i don't understand the problem can't you check the resource before link is rendered? You can create a new resource object empty in the case of null bytesand setVisible(false) or extend link to do this automatically on empty resource... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Nullable resource link
I think my best solution is to use a lightweight container like this: public class NullableContainer extends WebMarkupContainer { public NullableContainer(String id) { super(id); } public NullableContainer(String id, IModel model) { super(id, model); } @Override protected void onBeforeRender() { super.onBeforeRender(); onPopulate(); } /** * Convenience method for lazy-adding of children */ protected void onPopulate() { } @Override public boolean isVisible() { return getModelObject() != null; } } I then can override onPopulate() and add my children that depend on the nullable for construction. It's basically the logic equivalent of if model is not null, add children. Iain Reddick wrote: I'm fishing for best practice in this type of situation - do I use the solution you outlined, or do I add a simple invisible dummy link instead of the the resource link, or is there a better solution that I'm missing? Luca Provenzani wrote: i don't understand the problem can't you check the resource before link is rendered? You can create a new resource object empty in the case of null bytesand setVisible(false) or extend link to do this automatically on empty resource... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - 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
Re: Nullable resource link
why not something more directly like: *public class ProvaLink extends ResourceLink { ResourceReference resourceReference; @Override public boolean isVisible() { if(resourceReference==null)return false; else return true; } } *hope to help... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com I think my best solution is to use a lightweight container like this: public class NullableContainer extends WebMarkupContainer { public NullableContainer(String id) { super(id); } public NullableContainer(String id, IModel model) { super(id, model); } @Override protected void onBeforeRender() { super.onBeforeRender(); onPopulate(); } /** * Convenience method for lazy-adding of children */ protected void onPopulate() { } @Override public boolean isVisible() { return getModelObject() != null; } } I then can override onPopulate() and add my children that depend on the nullable for construction. It's basically the logic equivalent of if model is not null, add children. Iain Reddick wrote: I'm fishing for best practice in this type of situation - do I use the solution you outlined, or do I add a simple invisible dummy link instead of the the resource link, or is there a better solution that I'm missing? Luca Provenzani wrote: i don't understand the problem can't you check the resource before link is rendered? You can create a new resource object empty in the case of null bytesand setVisible(false) or extend link to do this automatically on empty resource... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - 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
Re: Nullable resource link
I don't want to keep a reference to to the resources byte array in the link - I'd rather it was retrieved dynamically when requested. I also don't really like constructing a bunch of stuff that's never going to be used (and to be null - which is often a headache). If I use the container component I outlined earlier, I can make the model object be the object that holds the resource data (a hibernate entity in my case). This means I can use getModelObject().getBytes(), etc. in the wrapped link construction. An additional plus point with this solution is that it is properly dynamic. I think this works pretty well for this type of situation - there is no extra null checking required (as it's all in the wrapper) and the logic of it seems quite clear. iainr Luca Provenzani wrote: why not something more directly like: *public class ProvaLink extends ResourceLink { ResourceReference resourceReference; @Override public boolean isVisible() { if(resourceReference==null)return false; else return true; } } *hope to help... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com I think my best solution is to use a lightweight container like this: public class NullableContainer extends WebMarkupContainer { public NullableContainer(String id) { super(id); } public NullableContainer(String id, IModel model) { super(id, model); } @Override protected void onBeforeRender() { super.onBeforeRender(); onPopulate(); } /** * Convenience method for lazy-adding of children */ protected void onPopulate() { } @Override public boolean isVisible() { return getModelObject() != null; } } I then can override onPopulate() and add my children that depend on the nullable for construction. It's basically the logic equivalent of if model is not null, add children. Iain Reddick wrote: I'm fishing for best practice in this type of situation - do I use the solution you outlined, or do I add a simple invisible dummy link instead of the the resource link, or is there a better solution that I'm missing? Luca Provenzani wrote: i don't understand the problem can't you check the resource before link is rendered? You can create a new resource object empty in the case of null bytesand setVisible(false) or extend link to do this automatically on empty resource... Luca 2009/10/14 Iain Reddick iain.redd...@beatsystems.com Hi, I need to display a resource link conditionally, based on whether a resource exists, or is null. The resource itself is bytes in a database and should not be anchored to a component. How should I handle this, with regard to the resource being nullable? Thanks. iainr - 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