Wicket: Submit the form in panels from another panel

I have a page with two panels (panel a and panel b). I am using one of these panels (panel b) to display some data in a table. I've added a form and some checkboxes to this table. My second panel (panal a) is used to display buttons. I want to submit the shape of panel b by clicking the panel a button so I can do something with the checked ones.

I searched a bit and I think I need to use ajax submit link. But I am not getting how I get my checked lines.

Page layout:

<wicket:extend xmlns:wicket="http://wicket.apache.org">
   <div style="margin-top: 60px">
       <h2><span wicket:id="header"></span></h2>
       <div wicket:id="categoryButtonPanel"></div>
       <div wicket:id="categoryTablePanel"></div>
   </div>
</wicket:extend>

      

this is how i add my checkboxes in panel b ( categoryTablePanel

):

Form form = new Form("form");
final List<Category> selectedCategorys = new ArrayList<Category>(); //my list where my selected rows are in
CheckGroup group = new CheckGroup("group", selectedCategorys);

DataView dv = new DataView("categoryList", dataProvider) {

      @Override
      protected void populateItem(Item item) {
          final Category category = (Category) item.getModelObject();
          final CompoundPropertyModel<Category> categoryModel = new CompoundPropertyModel<Category>(category);

          item.add(new Check("checkBox", item.getModel()));
          // some more binded rows
 }
};

      

Markup:

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<form wicket:id="form">
<span wicket:id="group">
<div class="table table-striped table-hover table-condensed" style="overflow: auto !important;" wicket:id="categoryTable">
        <table class="table table-striped">
            <thead>
                <th><input type="checkbox" wicket:id="selector">check/uncheck all</input></th>
            </thead>
            <tbody>
                <tr wicket:id="categoryList">
                    <td>
                        <input type="checkbox" wicket:id="checkBox" />
                    </td>
                </tr>
            </tbody>
        </table>
        <div wicket:id="paginator"></div>
    </div>
    </span>
</form>
</wicket:panel>

      

I can check each line, and if I create a normal button inside the form, I can use a list box selectedCategorys

to do some things with the data.

Now I want to add one or two buttons in my second panel ( categoryButtonPanel

) to do some things with my data. But how?

+3


source to share


2 answers


Just creating AjaxSubmitLink

using this constructor should work:

AjaxSubmitLink(String id, Form<?> form)



So you need to pass the form to another panel somehow in order to add it to the submitlink. Personally, I would add both panels to a larger form.

+2


source


For communication you can see kalitkovye events, IEventSink

and IEvent<T>

. You can do something like this panel 1:

public void panel1methodCalledOnSubmit(Category payload) {
     send(getPage(), Broadcast.BREADTH, payload);
}

      

You can answer this in panel 2 as follows:



@Override
public void onEvent(IEvent<?> event) {
    if (event.getPayload() instanceof Category) {
        // Do something
    }
}

      

It can be a little tricky when doing ajax things if you don't know how it works. Check out this page for more information on events.

An easier setup is RobAu's suggestion . You can replace your panels with objects FormComponent<T>

to improve the generalization of your form.

+2


source







All Articles