wicket how to update the header of modal<T>

T. Braz

I'm making a page using wicket. The main page consists of a table displaying invoice information. In the last column of the table has a link for each one of the invoices displaying the full information for that invoice, by opening a modal. I'm using de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal

My goal is when I open the modal, the header of the modal shows the invoice number of that invoice that was opened.

I'm able to get it only after refreshing the page, and if I open the modal of another invoice the header is not updated, it shows the number of the previous invoice. I have to refresh again the page.

I don't know how to open a modal that shows in the header the number of the respective invoice without refreshing the page.

below the markup of the main page.

<wicket:extend>
        <div class="page-header">
            <h2>
                <wicket:message key="invoices-welcome">[Welcome message]</wicket:message>
            </h2>
        </div>
        <div>
            <span wicket:id="navigator">[dataview navigator]</span>
        </div>
        <div>
            <table cellspacing="0" class="table table-condensed">
                <tr>
                    <th>Status</th>
                    <th>Invoice number</th>
                    <th>Supplier</th>
                    <th>Customer</th>
                    <th>Amount</th>
                    <th>Actions</th>
                </tr>
                <tr wicket:id="rows">
                    <td><span wicket:id="status">[status]</span></td>
                    <td><span wicket:id="invoiceN">[invoiceN]</span></td>
                    <td><span wicket:id="supplier">[supplier]</span></td>
                    <td><span wicket:id="customer">[customer]</span></td>
                    <td><span wicket:id="amount">[amount]</span></td>
                    <td><a wicket:id="showModal">View</a></td> 
                </tr>
            </table>
        </div>
        <div wicket:id="modal"></div>
    </wicket:extend>

Java code of the main page

package nl.riskco.liberobc.web.pages.invoices;

import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import nl.riskco.liberobc.client.business.model.InvoiceDomain;
import nl.riskco.liberobc.client.business.services.IInvoiceService;
import nl.riskco.liberobc.client.business.services.InvoiceServiceMocked;
import nl.riskco.liberobc.web.pages.BasePage;

//@AuthorizeInstantiation("VIEWER")
public class InvoicesPage extends BasePage {
   private static final long serialVersionUID = 1L;
   private InvoiceModalAgile modal2;

   public InvoicesPage(PageParameters parameters) {
    super(parameters);

    IInvoiceService service = new InvoiceServiceMocked();
    List<InvoiceDomain> invoicesToTest2;
    invoicesToTest2 =service.getInvoices(1, 30);

    modal2 = new InvoiceModalAgile("modal", Model.of(new InvoiceDomain()));
    modal2.addCloseButton();
    modal2.setOutputMarkupId(true);
    add(modal2);

    DataView<InvoiceDomain> dataview = new DataView<InvoiceDomain>("rows",
            new ListDataProvider<InvoiceDomain>(invoicesToTest2)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(Item<InvoiceDomain> item) {

            // TODO Auto-generated method stub
            InvoiceDomain invoice = item.getModelObject();

            item.add(new Label("status", invoice.getStatus()));
            item.add(new Label("invoiceN", String.valueOf(invoice.getInvoiceGUID())));
            item.add(new Label("supplier", invoice.getSupplier()));
            item.add(new Label("customer", invoice.getCustomer()));
            item.add(new Label("amount", String.valueOf(invoice.getAmount())));

            item.add(new AjaxLink("showModal") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    modal2.setInvoiceModel(Model.of(invoice), target);
                    modal2.show(target);
                }
            }); 
        }
    };

    dataview.setItemsPerPage(10L);
    add(dataview);
    add(new PagingNavigator("navigator", dataview));
}

@Override
protected void onDetach() {
    // TODO Auto-generated method stub
    super.onDetach();
}

}

Markup of the modal

<wicket:extend>
<div class="panel panel-default">
  <div class="panel-heading">Invoice details</div>
     <div class="panel-body">
        <table class="table table-bordered">
            <tr>
                <th><wicket:message key="invoice-id">[invoice-id]</wicket:message></th>
                <td><div wicket:id="invoiceN"></div></td>
            </tr>
            <tr>
                <th><wicket:message key="invoice-status">[invoice-status]</wicket:message></th>
                <td><div wicket:id="status"></div></td>
            </tr> 
            <tr>
                <th><wicket:message key="invoice-customer">[invoice-customer]</wicket:message></th>
                <td><div wicket:id="customer"></div></td>               
            </tr>
            <tr>
                <th><wicket:message key="invoice-supplier">[invoice-supplier]</wicket:message></th>
                <td><div wicket:id="supplier"></div></td>
            </tr>
            <tr>
                <th><wicket:message key="invoice-ibanSupplier">[invoice-ibanSupplier]</wicket:message></th>
                <td><div wicket:id="iban"></div></td>
            </tr>
            <tr>
                <th><wicket:message key="invoice-amount">[invoice-amount]</wicket:message></th>
                <td><div wicket:id="amount"></div></td>
            </tr>
            <tr>
                <th>Approved</th>
                <td><form wicket:id="form"><input type="checkbox"  wicket:id="checkbox1"></form></td>
            </tr>
            <tr>
                <th>Early payment</th>
                <td><form wicket:id="form2"><input type="checkbox"  wicket:id="checkbox2"></form></td>
            </tr>
            <tr>
                <th>Paid (by customer)</th>
                <td><form wicket:id="form3"><input type="checkbox"  wicket:id="checkbox3"></form></td>
            </tr>
        </table>
   </div>
 </div>
</wicket:extend>

Java code of the modal

package nl.riskco.liberobc.web.pages.invoices;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;

import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.BootstrapResourcesBehavior;
import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
import nl.riskco.liberobc.client.business.model.InvoiceDomain;


public class InvoiceModalAgile extends Modal<InvoiceDomain>{

private static final long serialVersionUID = 1L;
private Label labelGuid;
private Label status;
private Label customer;
private Label iban;
private Label amountLabel;
private Label supplierLabel;
private CheckBox approved;
private CheckBox earlyPayment;
private CheckBox customerPaid;
private Form form;
private Form form2;
private Form form3;
private WebMarkupContainer header;
private WebMarkupContainer footer;

public InvoiceModalAgile(String id , IModel<InvoiceDomain> model) {
    super(id, model);

    add(form = new Form<>("form"));
    add(form2 = new Form<>("form2"));
    add(form3 = new Form<>("form3"));

    status = (new Label("status",model.getObject().getStatus()));
    status.setOutputMarkupId(true);
    add(status);

    supplierLabel = (new Label("supplier",model.getObject().getSupplier()));
    supplierLabel.setOutputMarkupId(true);
    add(supplierLabel);


    labelGuid = new Label("invoiceN",model.getObject().getInvoiceGUID());
    labelGuid.setOutputMarkupId(true);
    add(labelGuid);

    customer = (new Label("customer",model.getObject().getCustomer()));
    customer.setOutputMarkupId(true);
    add(customer);

    iban = new Label("iban",model.getObject().getIBANsupplier());
    iban.setOutputMarkupId(true);
    add(iban);

    amountLabel = new Label("amount",model.getObject().getAmount());
    amountLabel.setOutputMarkupId(true);
    add(amountLabel);

    approved = new CheckBox("checkbox1");
    approved.setOutputMarkupId(true);
    approved.setEnabled(false);
    add(approved);
    form.setOutputMarkupId(true);
    add(form);
    form.add(approved);

    earlyPayment = new CheckBox("checkbox2");
    earlyPayment.setOutputMarkupId(true);
    earlyPayment.setEnabled(false);
    add(earlyPayment);
    form2.setOutputMarkupId(true);
    add(form2);
    form2.add(earlyPayment);

    customerPaid = new CheckBox("checkbox3");
    customerPaid.setOutputMarkupId(true);
    customerPaid.setEnabled(false);
    add(customerPaid);
    form3.setOutputMarkupId(true);
    add(form3);
    form3.add(customerPaid);

    BootstrapResourcesBehavior.addTo(this);
}


public void setInvoiceModel(IModel<InvoiceDomain> invoice, AjaxRequestTarget target){


this.labelGuid.setDefaultModel(Model.of(invoice.getObject().getInvoiceGUID()));
target.add(labelGuid);

this.amountLabel.setDefaultModel(Model.of(invoice.getObject().getAmount()));
target.add(amountLabel);

this.status.setDefaultModel(Model.of(invoice.getObject().getStatus()));
target.add(status);

this.customer.setDefaultModel(Model.of(invoice.getObject().getCustomer()));
target.add(customer);

this.supplierLabel.setDefaultModel(Model.of(invoice.getObject().getSupplier()));
target.add(supplierLabel);

this.iban.setDefaultModel(Model.of(invoice.getObject().getIBANsupplier()));
target.add(iban);

this.approved.setDefaultModel(Model.of(invoice.getObject().getApprovedFlag()));
target.add(approved);
this.earlyPayment.setDefaultModel(Model.of(invoice.getObject().getOptForEarlyPaymentFlag()));
target.add(earlyPayment);
this.customerPaid.setDefaultModel(Model.of(invoice.getObject().getHasCustomerPaidFlag()));
target.add(customerPaid);

this.header(Model.of(String.valueOf(invoice.getObject().getInvoiceGUID())));
}

@Override
protected void onDetach() {
   // TODO Auto-generated method stub
   super.onDetach();
}

}
martin-g

The problem is that you use the model object of the empty model that you pass at Modal construction. You need to use dynamic models for the properties.

Static/simple model:

label = new Label("staticValue", personModel.getObject().getName());

Here the label will use the name of the current person for each rendering.

Dynamic model:

label = new Label("staticValue", new AbstractReadOnlyModel<String>() {

   @Override public String getObject() { 
      return personModel.getObject().getName());
   }
}

You see that the dynamic version reads personModel's name lazily and it is called at each rendering of the Label. This way it will read the name of the person even if you put a new Person into the Label's Model.

In your case you need something like:

status = new Label("status", new PropertyModel(this, "model.object.status"));

For more information read: https://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to show modal window with image in Wicket

From Dev

How to validate a form in a bootstrap modal window in wicket?

From Dev

how to update a wicket AjaxEditableMultiLineLabel model on an ajax call

From Dev

how can we remove the draggable property from modal window in wicket

From Dev

How to update the header on the fly

From Dev

How to update the contents of a Bootstrap modal?

From Dev

How to get a unique modal header for each stock?

From Dev

How to handle changes in a form with a model-update using Wicket and AJAX

From Dev

Wicket wicket:id inheritance - how to?

From Dev

render whole Wicket Header in Body

From Dev

Extjs 6: Adding modal window doesn't mask tbar and header

From Dev

How to update Parent form from a Modal

From Dev

How to update $scope outside the modal bootstrap in AngularJS?

From Dev

How to update inputs based on a modal selection

From Dev

Open an external link in a wicket modal window

From Dev

Open an external link in a wicket modal window

From Dev

Wicket Problems about the textfield in the modal window

From Dev

How do I change the font weight for a Bootstrap 4 modal header?

From Dev

How to update default header in PDF report (qWeb)?

From Dev

Angular: Can't update model on submit before close of modal

From Dev

AngularJS UI Modal and select doesn't update the scope values

From Dev

Angular: Can't update model on submit before close of modal

From Dev

How to close IFeedback in Wicket?

From Dev

How to close IFeedback in Wicket?

From Dev

Update one Wicket Panel from clicking an item in another Wicket Panel

From Dev

Wicket jQuery doesn't work

From Dev

How do you update an existing Bootstrap modal data-target?

From Dev

How to update widget with pjax in modal window in yii2

From Dev

Wicket ajax controls update bahaviours are overlapped

Related Related

  1. 1

    How to show modal window with image in Wicket

  2. 2

    How to validate a form in a bootstrap modal window in wicket?

  3. 3

    how to update a wicket AjaxEditableMultiLineLabel model on an ajax call

  4. 4

    how can we remove the draggable property from modal window in wicket

  5. 5

    How to update the header on the fly

  6. 6

    How to update the contents of a Bootstrap modal?

  7. 7

    How to get a unique modal header for each stock?

  8. 8

    How to handle changes in a form with a model-update using Wicket and AJAX

  9. 9

    Wicket wicket:id inheritance - how to?

  10. 10

    render whole Wicket Header in Body

  11. 11

    Extjs 6: Adding modal window doesn't mask tbar and header

  12. 12

    How to update Parent form from a Modal

  13. 13

    How to update $scope outside the modal bootstrap in AngularJS?

  14. 14

    How to update inputs based on a modal selection

  15. 15

    Open an external link in a wicket modal window

  16. 16

    Open an external link in a wicket modal window

  17. 17

    Wicket Problems about the textfield in the modal window

  18. 18

    How do I change the font weight for a Bootstrap 4 modal header?

  19. 19

    How to update default header in PDF report (qWeb)?

  20. 20

    Angular: Can't update model on submit before close of modal

  21. 21

    AngularJS UI Modal and select doesn't update the scope values

  22. 22

    Angular: Can't update model on submit before close of modal

  23. 23

    How to close IFeedback in Wicket?

  24. 24

    How to close IFeedback in Wicket?

  25. 25

    Update one Wicket Panel from clicking an item in another Wicket Panel

  26. 26

    Wicket jQuery doesn't work

  27. 27

    How do you update an existing Bootstrap modal data-target?

  28. 28

    How to update widget with pjax in modal window in yii2

  29. 29

    Wicket ajax controls update bahaviours are overlapped

HotTag

Archive