Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:00:19+00:00 2026-05-29T07:00:19+00:00

Quite frequently, I’m using custom Wicket components to render model objects. Objects can sometimes

  • 0

Quite frequently, I’m using custom Wicket components to render model objects. Objects can sometimes be null, in that case a specific div is displayed. In the component HTML rendering code, I thus have two div’s, one for the “null” case, and one for the “non-null” case, with some other inner markup. One is displayed while the other is masked.

<div wicket:id="toDisplayWhenObjectIsNull">
    ...
</div>
<div wicket:id="toDisplayWhenObjectIsNotNull">
   <span wicket:id="label">...</span>
   <table wicket:id="table">...</table>
   ...
</div>

The problem I face is that Wicket force me to entirely build the two div, even if the model object is null. In all calls to sub-components building (labels, tables, etc…) I have to check for nullness, which is cumbersome and error-prone:

X myX = getModel().getModelObject();
Label label = new Label("label",
    myX == null ? null : formatY(myX.getY()));

The first solution to this would be to split the non-null part in a specific wicket sub-component, either as it’s own class or an inner class of the master component; and inserting this component in place of the “non-null” div. But that double the number of needed files (resources, HTML, java code). This is not ideal.

The second solution, generic, would be to create a “decorator” component to encapsulate any other component, and check for nullness on it’s model object. If the component is null, then it would display a standard div, and if not, it would rely on the decorated component. I tried to implement this using borders or composite panels, but I can’t manage to make it work. What I would like to achieve is something like this:

// Client code, Java
ViewXPanel xpanel = new ViewXPanel("xpanel", new Model<X>(x));
add(xpanel);

// HTML
<div wicket:id="xpanel"/>

OR, if necessary, make the client responsible of “nullability” of the displayed component, using something like this in the client code:

// Client code, Java
ViewXPanel xpanel = new NullableDecorator(?, ViewXPanel(...));
add(xpanel);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:00:19+00:00Added an answer on May 29, 2026 at 7:00 am

    Well, one workaround is effectively using fragments, as suggested by biziclop, so I’m describing it down here for reference, but not flagging it as an “answer”.

    ViewX.html:

    <wicket:panel ...>
      <div wicket:id="mainPanel"></div>
      <wicket:fragment wicket:id="nullFragment">
        ...markup for NULL case...
      </wicket:fragment>
      <wicket:fragment wicket:id="nonNullFragment">
        <h4><span wicket:id="theName"></span></h4>
        ...other markup for non-NULL case...
      </wicket:fragment>
    </wicket:panel
    

    ViewX.java:

    public class ViewX extends Panel {
      public ViewX(String id, IModel<X> xmodel) {
        if (x == null) {
          Fragment nullFragment = new Fragment("mainPanel", "nullFragment", null);
          ... eventual markup if needed ...
          add(nullFragment);
        } else {
          Fragment nonNullFragment = new Fragment("mainPanel", "nonNullFragment", null);
          nonNullFragment.add(new Label("theName", new PropertyModel(xmodel, "name")));
          ... other markup ...
          add(nonNullFragment);
    } } }
    

    I’m still looking for a really generic solution to this, either by composition, inheritance or decoration on a non-null-aware ViewX panel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The idea is that an existing project uses timeGetTime() (for windows targets) quite frequently.
I am using SQL Server 2005. I have a site that people can vote
I've a job in Quartz.Net which triggers quite frequently, and sometimes runs for long,
I'm using Google+ quite heavily and one thing I find myself doing extremely frequently
So, I have an application that communicates with a server quite frequently. I have
So I have a large table that I query (select only) quite frequently. The
I'm making use of an open source project that is changing quite frequently. It
It happens quite frequently, more times per day, that with Visual Studio 2010 ,
I've been using SQL Server profiler quite frequently to check for redundant or badly
We use Infopath at work, quite frequently for form design and then we integrate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.