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

  • SEARCH
  • Home
  • 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 3979944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:55+00:00 2026-05-20T05:13:55+00:00

I am in trouble with getModelObject. It is returning null. Actually the model concept

  • 0

I am in trouble with getModelObject. It is returning null. Actually the model concept is not clear to me. The code is:

public class SpaceCheckListWindow extends WebPage {
private SpaceCheckListForm spaceCheckListForm;
private Page parentPage;
private ModalWindow modalWindow;

public SpaceCheckListWindow(Page parentPage, final ModalWindow modalWindow) {
    this.parentPage = parentPage;
    this.modalWindow = modalWindow;

    String[] labels = new String[] {
            "a", 
            "b",
            "c",
            "d",
            "e",
            "f"
    };

    List<ListMemeber> list = new ArrayList<ListMemeber>();

    for(String label : labels) {
        list.add(new ListMemeber(label));
    }

    addComponent(list);
}   

private void addComponent(List<ListMemeber> list) {
    spaceCheckListForm = new SpaceCheckListForm("form", list);
    add(spaceCheckListForm);
}

private class SpaceCheckListForm extends Form {

    private static final long serialVersionUID = 1L;

    public SpaceCheckListForm(String id, final List<ListMemeber> list) {
        super(id);

        ListView listView = new ListView("listView", list) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem listItem) {
                ListMemeber member = (ListMemeber) listItem.getModelObject();
                listItem.add(new Label("label", member.getLabel()));
                listItem.add(new CheckBox("checkbox", new PropertyModel(member, "selected")));
            }
        };

        listView.setReuseItems(true);
        add(listView);

        AjaxButton submitBtn = new AjaxButton("submitBtn", this) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form form) {
                System.out.println(spaceCheckListForm.getModelObject());
                modalWindow.close(target);
            }
        };

        add(submitBtn);
    }

}

private class ListMemeber implements Serializable {
    private String label;
    private Boolean selected = Boolean.FALSE;

    public ListMemeber(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    @Override
    public String toString() {
        return label + Boolean.toString(selected);
    }
}

}

Now onClick the AjaxButton it is returning null. I want to get the labels and corresponding checkbox values. What should I do to get it? Any information will be very helpful to me. Thank you.

  • 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-20T05:13:56+00:00Added an answer on May 20, 2026 at 5:13 am

    Your component hierarchy looks like this:

    SpaceCheckListWindow  
     SpaceCheckListForm (id: form)
      ListView (id: listView)
       ListItem (id: <generated by wicket>)
        Label (id: label)
        CheckBox (id: checkbox)
      AjaxButton (id: submitBtn)
    

    In Wicket, each component may have a model, which stores data it displays/manipulates. This model is usually passed to the component in the constructor. If this doesn’t happen, the component is initialised with an empty model (which is not an error in itself). But in your code, your form is created with an empty model and there’s nothing to update the model either, so getModelObject() will always return null. This again is not an error, your form doesn’t have to have a model object itself.

    The only component which has a non-trivial model here is CheckBox, which reads/updates the selected field of ListMemeber, as it should. (Update: Of course your Label has a non-empty model too, but labels only read their model, never update it.)

    So to sum it up: there’s nothing fundamentally wrong with this code, you’re just looking for the result in the wrong place: instead of logging out the model object of the form, list the selected fields of all the list members to see what’s changing when you submit your form.

    Some additional reading about Wicket models: Working with Wicket models

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

Sidebar

Related Questions

Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm having trouble getting ThinkingSphinx to recognize my conditions. My Discussion model includes the
The trouble I'm having is with using... [DllImport(user32)] public static extern IntPtr SendMessage(IntPtr hWnd,
trouble loading html file from plist to webView using following code in FAQDetailViewController.m: -
Having trouble with this code, wondering if I'm trying to achieve something impossible. I'm
Having trouble with the db.alter command when changing a date field from null=True and
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
Having trouble getting one portion of my code to work. Building a rudimentary linked
Having trouble here and not quite sure how to do it. I've attempted jQuery
Having trouble inheriting from a template class. Looks something like this: template<typename type> class

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.