I've come across similar scenarios fairly often - i.e. where a the construction of component is impossible if its model object is null, or some other construction parameter is null.

I'm still not sure what the best approach is in this situation.

One of the methods I've used is to late-bind the "optional" component in the onBeforeRender() of a special wrapper container (e.g. if the model object != null, add the component, make the wrapper visible. If model object == null, don't add the component and make the wrapper non-visible). This seems like a blatant hack, however.

see these threads:
http://apache-wicket.1842946.n4.nabble.com/Nullable-resource-link-td1886391.html#a1886395
http://apache-wicket.1842946.n4.nabble.com/Components-and-nullable-data-td1888023.html#none

Abid K wrote:
Thanks Josh and Daniel - both methods have worked. I have gone with checking
if the object is null or not like so...

  public class SomePanel extends Panel {
    public SomePanel(String id) {
      super(id);

      if ( data == null ) {
        return;
      }

      Label label = new Label("someLabel", String.valueOf(data.getId()));
      add(label);
    }
  }

I have decided to do this because I am not sure how I can format a date
without doing this...
      SimpleDateFormat dateFormat = new SimpleDateFormat( "dd/MM/yyyy" );
      Label dateLabel = new Label( "date", dateFormat.format( data.getDate(
) ) );

Thanks.



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

Reply via email to