Re: Components and nullable data
Thanks - that's very neat. It also made me spend some time looking at that area of the framework, which will be useful in the future. With that strategey and annotation, handling nullable data is a non-issue when a component uses a model for all its data requirements. There are obviously complications if a component requires secondary construction data related to the nullable, but I need to reflect on whether this is ever really an issue. Igor Vaynberg wrote: instead of creating a lot of subclasses you can use the iauthorizationstrategy to do this: onaction(component, action) { if (action==component.render) { if (component.hasannotation(@HideIfModelIsNull)) { return false; } } return true; } you get this behavior for any component via a simple annot. -igor On Fri, Jul 31, 2009 at 6:39 AM, Iain Reddick wrote: Thanks for the reply - I think I'm perhaps trying to bend the framework rather than work with it. I suppose I'm really wondering about the following kind of thing, and whether it's worth trying to build similar re-usable components: public class NullableLabel extends Label { private boolean visibleWhenNull = true; ... public boolean isVisible() { if ( getModelObject() != null ) { return true; } else { return visibleWhenNull; } } public void setVisibleWhenNull(...) { ... } } This adds simple, configurable null-aware behaviour to a label. Is this kind of thinking worth pursuing? add(new Link("editgroup", user) { onclick() { ... } isvisible() { return user.getgroup()!=null; } } ? -igor 2009/7/30 Iain Reddick : Hi all, One of the difficulties I am finding with wicket is the best practice when displaying/using data that is potentially null. Example: I have a "user" object which has a nullable "group" property. I want to show a link to the group details page when the "group" property is not null, but show nothing otherwise (let's keep this simple). My issue is that either way, I have to construct the link component and add it to the page, whether I want it is visible or not. This is tricky at the best of times, as I must always carry out a lot of "is null" logic. The construction issue becomes multiplied if I want the same behaviour on a stateful page (i.e. the link, etc. can be appropriate for linking to the group, or be null and not visible and can switch between the two states). My question is - am I missing something, or do I just need to have a better strategy for this type of situation? If the answer is the latter, does anyone have any tips and/or components that would cut down on the extra coding? 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 - 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 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Components and nullable data
instead of creating a lot of subclasses you can use the iauthorizationstrategy to do this: onaction(component, action) { if (action==component.render) { if (component.hasannotation(@HideIfModelIsNull)) { return false; } } return true; } you get this behavior for any component via a simple annot. -igor On Fri, Jul 31, 2009 at 6:39 AM, Iain Reddick wrote: > Thanks for the reply - I think I'm perhaps trying to bend the framework > rather than work with it. > > I suppose I'm really wondering about the following kind of thing, and > whether it's worth trying to build similar re-usable components: > > public class NullableLabel extends Label { > private boolean visibleWhenNull = true; > ... > public boolean isVisible() { > if ( getModelObject() != null ) { > return true; > } else { > return visibleWhenNull; > } > } > > public void setVisibleWhenNull(...) { > ... > } > } > This adds simple, configurable null-aware behaviour to a label. > > Is this kind of thinking worth pursuing? > >> >> add(new Link("editgroup", user) { >> onclick() { >> ... >> } >> >> isvisible() { >> return user.getgroup()!=null; >> } >> } >> >> ? >> >> -igor >> >> 2009/7/30 Iain Reddick : > >> > Hi all, >> > >> > One of the difficulties I am finding with wicket is the best practice >> > when >> > displaying/using data that is potentially null. >> > >> > Example: >> > >> > I have a "user" object which has a nullable "group" property. I want to >> > show >> > a link to the group details page when the "group" property is not null, >> > but >> > show nothing otherwise (let's keep this simple). >> > >> > My issue is that either way, I have to construct the link component and >> > add >> > it to the page, whether I want it is visible or not. This is tricky at >> > the >> > best of times, as I must always carry out a lot of "is null" logic. >> > >> > The construction issue becomes multiplied if I want the same behaviour >> > on a >> > stateful page (i.e. the link, etc. can be appropriate for linking to the >> > group, or be null and not visible and can switch between the two >> > states). >> > >> > My question is - am I missing something, or do I just need to have a >> > better >> > strategy for this type of situation? >> > >> > If the answer is the latter, does anyone have any tips and/or components >> > that would cut down on the extra coding? >> > >> > 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 > > > - > 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: Components and nullable data
Absolutely. It's one of wickets many strong points. Regards, Antony Stubbs website: sharca.com On 1/08/2009, at 1:39 AM, Iain Reddick wrote: Thanks for the reply - I think I'm perhaps trying to bend the framework rather than work with it. I suppose I'm really wondering about the following kind of thing, and whether it's worth trying to build similar re-usable components: public class NullableLabel extends Label { private boolean visibleWhenNull = true; ... public boolean isVisible() { if ( getModelObject() != null ) { return true; } else { return visibleWhenNull; } } public void setVisibleWhenNull(...) { ... } } This adds simple, configurable null-aware behaviour to a label. Is this kind of thinking worth pursuing? add(new Link("editgroup", user) { onclick() { ... } isvisible() { return user.getgroup()!=null; } } ? -igor 2009/7/30 Iain Reddick : > Hi all, > > One of the difficulties I am finding with wicket is the best practice when > displaying/using data that is potentially null. > > Example: > > I have a "user" object which has a nullable "group" property. I want to show > a link to the group details page when the "group" property is not null, but > show nothing otherwise (let's keep this simple). > > My issue is that either way, I have to construct the link component and add > it to the page, whether I want it is visible or not. This is tricky at the > best of times, as I must always carry out a lot of "is null" logic. > > The construction issue becomes multiplied if I want the same behaviour on a > stateful page (i.e. the link, etc. can be appropriate for linking to the > group, or be null and not visible and can switch between the two states). > > My question is - am I missing something, or do I just need to have a better > strategy for this type of situation? > > If the answer is the latter, does anyone have any tips and/or components > that would cut down on the extra coding? > > 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 - 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
Components and nullable data
Thanks for the reply - I think I'm perhaps trying to bend the framework rather than work with it. I suppose I'm really wondering about the following kind of thing, and whether it's worth trying to build similar re-usable components: public class NullableLabel extends Label { private boolean visibleWhenNull = true; ... public boolean isVisible() { if ( getModelObject() != null ) { return true; } else { return visibleWhenNull; } } public void setVisibleWhenNull(...) { ... } } This adds simple, configurable null-aware behaviour to a label. Is this kind of thinking worth pursuing? add(new Link("editgroup", user) { onclick() { ... } isvisible() { return user.getgroup()!=null; } } ? -igor 2009/7/30 Iain Reddick : > Hi all, > > One of the difficulties I am finding with wicket is the best practice when > displaying/using data that is potentially null. > > Example: > > I have a "user" object which has a nullable "group" property. I want to show > a link to the group details page when the "group" property is not null, but > show nothing otherwise (let's keep this simple). > > My issue is that either way, I have to construct the link component and add > it to the page, whether I want it is visible or not. This is tricky at the > best of times, as I must always carry out a lot of "is null" logic. > > The construction issue becomes multiplied if I want the same behaviour on a > stateful page (i.e. the link, etc. can be appropriate for linking to the > group, or be null and not visible and can switch between the two states). > > My question is - am I missing something, or do I just need to have a better > strategy for this type of situation? > > If the answer is the latter, does anyone have any tips and/or components > that would cut down on the extra coding? > > 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 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Components and nullable data
add(new Link("editgroup", user) { onclick() { ... } isvisible() { return user.getgroup()!=null; } } ? -igor 2009/7/30 Iain Reddick : > Hi all, > > One of the difficulties I am finding with wicket is the best practice when > displaying/using data that is potentially null. > > Example: > > I have a "user" object which has a nullable "group" property. I want to show > a link to the group details page when the "group" property is not null, but > show nothing otherwise (let's keep this simple). > > My issue is that either way, I have to construct the link component and add > it to the page, whether I want it is visible or not. This is tricky at the > best of times, as I must always carry out a lot of "is null" logic. > > The construction issue becomes multiplied if I want the same behaviour on a > stateful page (i.e. the link, etc. can be appropriate for linking to the > group, or be null and not visible and can switch between the two states). > > My question is - am I missing something, or do I just need to have a better > strategy for this type of situation? > > If the answer is the latter, does anyone have any tips and/or components > that would cut down on the extra coding? > > 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
Components and nullable data
Hi all, One of the difficulties I am finding with wicket is the best practice when displaying/using data that is potentially null. Example: I have a "user" object which has a nullable "group" property. I want to show a link to the group details page when the "group" property is not null, but show nothing otherwise (let's keep this simple). My issue is that either way, I have to construct the link component and add it to the page, whether I want it is visible or not. This is tricky at the best of times, as I must always carry out a lot of "is null" logic. The construction issue becomes multiplied if I want the same behaviour on a stateful page (i.e. the link, etc. can be appropriate for linking to the group, or be null and not visible and can switch between the two states). My question is - am I missing something, or do I just need to have a better strategy for this type of situation? If the answer is the latter, does anyone have any tips and/or components that would cut down on the extra coding? Thanks - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org