Example usage for org.apache.wicket.ajax AjaxRequestTarget add

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget add.

Prototype

void add(Component... components);

Source Link

Document

Adds components to the list of components to be rendered.

Usage

From source file:ca.travelagency.invoice.notes.NoteFormPanel.java

License:Apache License

public NoteFormPanel(final String id, InvoiceNote invoiceNote, final NotesPanel notesPanel) {
    super(id);//from   w ww. j a v  a  2s  .c o  m
    Validate.notNull(notesPanel);

    setOutputMarkupId(true);

    IModel<InvoiceNote> model = DaoEntityModelFactory.make(invoiceNote, InvoiceNote.class);

    final Form<InvoiceNote> noteForm = new Form<InvoiceNote>(FORM, model);
    noteForm.setOutputMarkupId(true);

    noteForm.add(new ComponentFeedbackPanel(FEEDBACK, noteForm));

    noteForm.add(new TextArea<String>(InvoiceNote.Properties.text.name()).setRequired(true)
            .setLabel(new ResourceModel("invoiceNote.note")).add(StringFieldHelper.maxLenAreaValidator())
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    noteForm.add(new CheckBox(InvoiceNote.Properties.privateNote.name())
            .setLabel(new ResourceModel("invoiceNote.private"))
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()));

    noteForm.add(new SavePanelDetail<InvoiceNote>(SAVE_BUTTON, noteForm) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<InvoiceNote> form) {
            notesPanel.update(target, form.getModelObject());
            IModel<InvoiceNote> model = DaoEntityModelFactory.make(InvoiceNote.class);
            form.setModel(model);
        }
    });

    noteForm.add(new ResetPanel<InvoiceNote>(RESET_BUTTON, noteForm)
            .setResetModel(!DaoEntityModelFactory.isPersisted(model.getObject())));

    noteForm.add(new CancelPanel(CANCEL_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            NoteRowPanel noteRowPanel = new NoteRowPanel(id, noteForm.getModel(), notesPanel);
            NoteFormPanel.this.replaceWith(noteRowPanel);
            target.add(noteRowPanel);
        }
    }.setVisible(invoiceNote != null));

    add(noteForm);
}

From source file:ca.travelagency.invoice.notes.NoteRowPanel.java

License:Apache License

public NoteRowPanel(final String id, IModel<InvoiceNote> model, final NotesPanel notesPanel) {
    super(id, model);
    setOutputMarkupId(true);/*from   w  ww  .j  av  a2  s  .  c  om*/

    add(new Label(InvoiceNote.Properties.text.name()).setEscapeModelStrings(false));
    add(new CheckMarkPanel(InvoiceNote.Properties.privateNote.name(), model.getObject().isPrivateNote()));
    add(DateLabel.forDateStyle(InvoiceNote.Properties.date.name(), DateUtils.DATE_STYLE));

    add(new DeletePanel<InvoiceNote>(DELETE_BUTTON, getInvoiceNote(), notesPanel) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            notesPanel.delete(target, getInvoiceNote());
        }
    }.setVisible(notesPanel.isEditable()));

    add(new EditPanel(EDIT_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            NoteFormPanel noteFormPanel = new NoteFormPanel(id, getInvoiceNote(), notesPanel);
            NoteRowPanel.this.replaceWith(noteFormPanel);
            target.add(noteFormPanel);
        }
    }.setVisible(notesPanel.isEditable()));

}

From source file:ca.travelagency.invoice.payments.PaymentFormPanel.java

License:Apache License

public PaymentFormPanel(final String id, InvoicePayment invoicePayment, final PaymentsPanel paymentsPanel) {
    super(id);/*from   ww  w  . jav a2s  .  co m*/
    Validate.notNull(paymentsPanel);

    setOutputMarkupId(true);

    IModel<InvoicePayment> model = DaoEntityModelFactory.make(invoicePayment, InvoicePayment.class);
    final Form<InvoicePayment> paymentForm = new Form<InvoicePayment>(FORM, model);
    paymentForm.setOutputMarkupId(true);

    paymentForm.add(new ComponentFeedbackPanel(FEEDBACK, paymentForm));

    paymentForm.add(new RequiredTextField<BigDecimal>(InvoicePayment.Properties.amount.name())
            .setLabel(new ResourceModel("invoice.paymentAmount"))
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    paymentForm.add(new CheckBox(InvoicePayment.Properties.reconciled.name())
            .setLabel(new ResourceModel("invoice.paymentReconciled"))
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()).setVisible(hasRole(Role.ADMIN)));
    paymentForm.add(new DropDownChoice<PaymentType>(InvoicePayment.Properties.paymentType.name(),
            Arrays.asList(PaymentType.values())).setRequired(true)
                    .setLabel(new ResourceModel("invoice.paymentType"))
                    .add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    paymentForm.add(new DateField(InvoicePayment.Properties.date.name()).setRequired(true)
            .setLabel(new ResourceModel("invoice.paymentDate"))
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()));

    paymentForm.add(new SavePanelDetail<InvoicePayment>(SAVE_BUTTON, paymentForm) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<InvoicePayment> form) {
            paymentsPanel.update(target, form.getModelObject());
            IModel<InvoicePayment> model = DaoEntityModelFactory.make(InvoicePayment.class);
            form.setModel(model);
        }
    });

    paymentForm.add(new ResetPanel<InvoicePayment>(RESET_BUTTON, paymentForm)
            .setResetModel(!DaoEntityModelFactory.isPersisted(model.getObject())));

    paymentForm.add(new CancelPanel(CANCEL_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            PaymentRowPanel paymentRowPanel = new PaymentRowPanel(id, paymentForm.getModel(), paymentsPanel);
            PaymentFormPanel.this.replaceWith(paymentRowPanel);
            target.add(paymentRowPanel);
        }
    }.setVisible(invoicePayment != null));

    add(paymentForm);
}

From source file:ca.travelagency.invoice.payments.PaymentRowPanel.java

License:Apache License

public PaymentRowPanel(final String id, IModel<InvoicePayment> model, final PaymentsPanel paymentsPanel) {
    super(id, model);
    setOutputMarkupId(true);/*from   www . j  av  a 2 s  .  co  m*/

    add(DateLabel.forDateStyle(InvoicePayment.Properties.date.name(), DateUtils.DATE_STYLE));
    add(new Label(InvoicePayment.Properties.amountAsString.name()));
    add(new CheckMarkPanel(InvoicePayment.Properties.reconciled.name(), model.getObject().isReconciled()));
    add(new Label(InvoicePayment.Properties.paymentType.name()));

    add(new DeletePanel<InvoicePayment>(DELETE_BUTTON, getInvoicePayment(), paymentsPanel) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            paymentsPanel.delete(target, getInvoicePayment());
        }
    }.setVisible(isVisible(model, paymentsPanel)));

    add(new EditPanel(EDIT_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            PaymentFormPanel paymentFormPanel = new PaymentFormPanel(id, getInvoicePayment(), paymentsPanel);
            PaymentRowPanel.this.replaceWith(paymentFormPanel);
            target.add(paymentFormPanel);
        }
    }.setVisible(isVisible(model, paymentsPanel)));

}

From source file:ca.travelagency.invoice.travelers.TravelerFormPanel.java

License:Apache License

public TravelerFormPanel(final String id, InvoiceTraveler invoiceTraveler,
        final TravelersPanel travelersPanel) {
    super(id);//from   w ww.j a v a  2 s  .  co  m
    Validate.notNull(travelersPanel);

    setOutputMarkupId(true);

    IModel<InvoiceTraveler> model = DaoEntityModelFactory.make(invoiceTraveler, InvoiceTraveler.class);
    initialize(model.getObject());

    final Form<InvoiceTraveler> travelerForm = new Form<InvoiceTraveler>(FORM, model);
    travelerForm.setOutputMarkupId(true);

    travelerForm.add(new ComponentFeedbackPanel(FEEDBACK, travelerForm));

    travelerForm.add(new SalutationField(InvoiceTraveler.Properties.salutation.name())
            .setLabel(new ResourceModel("travelerFormPanel.salutation"))
            .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    travelerForm.add(new LastNameField(InvoiceTraveler.Properties.lastName.name())
            .setLabel(new ResourceModel("travelerFormPanel.lastName")).setRequired(true)
            .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    travelerForm.add(new FirstNameField(InvoiceTraveler.Properties.firstName.name())
            .setLabel(new ResourceModel("travelerFormPanel.firstName")).setRequired(true)
            .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    travelerForm.add(new TravelDocumentField(InvoiceTraveler.Properties.documentType.name())
            .setLabel(new ResourceModel("travelerFormPanel.document"))
            .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    travelerForm.add(new TextField<String>(InvoiceTraveler.Properties.documentNumber.name())
            .setLabel(new ResourceModel("travelerFormPanel.documentNumber"))
            .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior()));
    travelerForm.add(new BirthDateField(InvoiceTraveler.Properties.dateOfBirth.name())
            .setLabel(new ResourceModel("travelerFormPanel.dateOfBirth"))
            .add(new FieldDecorator(), new AjaxOnBlurBehavior()));

    travelerForm.add(new SavePanelDetail<InvoiceTraveler>(SAVE_BUTTON, travelerForm) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<InvoiceTraveler> form) {
            InvoiceTraveler travelerItem = form.getModelObject();
            travelersPanel.update(target, travelerItem);
            IModel<InvoiceTraveler> model = DaoEntityModelFactory.make(InvoiceTraveler.class);
            form.setModel(model);
            initialize(model.getObject());
        }
    });

    travelerForm.add(new ResetPanel<InvoiceTraveler>(RESET_BUTTON, travelerForm) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<InvoiceTraveler> form) {
            initialize(form.getModelObject());
        }
    }.setResetModel(!DaoEntityModelFactory.isPersisted(model.getObject())));

    travelerForm.add(new CancelPanel(CANCEL_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            TravelerRowPanel travelerRowPanel = new TravelerRowPanel(id, travelerForm.getModel(),
                    travelersPanel);
            TravelerFormPanel.this.replaceWith(travelerRowPanel);
            target.add(travelerRowPanel);
        }
    }.setVisible(invoiceTraveler != null));

    travelerForm.add(new TravelerLookupLink(LOOKUP_TRAVELERS, travelerForm));

    add(travelerForm);
}

From source file:ca.travelagency.invoice.travelers.TravelerRowPanel.java

License:Apache License

public TravelerRowPanel(final String id, IModel<InvoiceTraveler> model, final TravelersPanel travelersPanel) {
    super(id, model);
    setOutputMarkupId(true);/*from ww w. j  av a  2  s. c om*/

    add(new Label(DaoEntity.PROPERTY_NAME));
    add(new Label(InvoiceTraveler.Properties.documentType.name()));
    add(new Label(InvoiceTraveler.Properties.documentNumber.name()));
    add(DateLabel.forDateStyle(InvoiceTraveler.Properties.dateOfBirth.name(), DateUtils.DATE_STYLE));

    add(new DeletePanel<InvoiceTraveler>(DELETE_BUTTON, getInvoiceTraveler(), travelersPanel) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            travelersPanel.delete(target, getInvoiceTraveler());
        }
    }.setVisible(travelersPanel.isEditable()));

    add(new EditPanel(EDIT_BUTTON) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            TravelerFormPanel travelerFormPanel = new TravelerFormPanel(id, getInvoiceTraveler(),
                    travelersPanel);
            TravelerRowPanel.this.replaceWith(travelerFormPanel);
            target.add(travelerFormPanel);
        }
    }.setVisible(travelersPanel.isEditable()));

}

From source file:ca.travelagency.reconciliation.CommissionStatusForm.java

License:Apache License

public CommissionStatusForm(String id, InvoiceItem invoiceItem) {
    super(id);//from  ww w  .jav a 2  s .  co m

    final Form<InvoiceItem> form = new Form<InvoiceItem>(FORM, DaoEntityModelFactory.make(invoiceItem));
    form.setOutputMarkupId(true);
    add(form);

    form.add(new DropDownChoice<CommissionStatus>(InvoiceItem.Properties.commissionStatus.name(),
            Lists.newArrayList(CommissionStatus.values()))
                    .setLabel(new ResourceModel("commissionStatusForm.label"))
                    .add(FieldDecorator.doNotDisplayLabel())
                    .add(new AjaxFormComponentUpdatingBehavior("onchange") {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void onUpdate(AjaxRequestTarget target) {
                            InvoiceItem invoiceItem = form.getModelObject();
                            invoiceItem.getInvoice().closeInvoice();
                            daoSupport.persist(invoiceItem);
                            target.add(form);
                        }

                        @Override
                        protected void onError(AjaxRequestTarget target, RuntimeException e) {
                            target.add(form);
                        }
                    }));
}

From source file:ca.travelagency.reconciliation.ReconciledForm.java

License:Apache License

public ReconciledForm(String id, InvoicePayment invoicePayment) {
    super(id);//from   w  ww.  j av  a  2  s .c  o m

    final Form<InvoicePayment> form = new Form<InvoicePayment>(FORM,
            DaoEntityModelFactory.make(invoicePayment));
    form.setOutputMarkupId(true);
    add(form);

    form.add(new CheckBox(InvoicePayment.Properties.reconciled.name())
            .setLabel(new ResourceModel("reconciledForm.label")).add(FieldDecorator.doNotDisplayLabel())
            .add(new AjaxFormComponentUpdatingBehavior("onchange") {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    InvoicePayment invoicePayment = form.getModelObject();
                    daoSupport.persist(invoicePayment);
                    target.add(form);
                }

                @Override
                protected void onError(AjaxRequestTarget target, RuntimeException e) {
                    target.add(form);
                }
            }));
}

From source file:ca.travelagency.traveler.SelectPanel.java

License:Apache License

public SelectPanel(String id, final IModel<Traveler> model, final Form<InvoiceTraveler> travelerForm,
        final ModalWindow modalWindow) {
    super(id);//from  ww  w.  j a  v  a 2  s .c om

    AjaxLink<Void> link = new AjaxLink<Void>(LINK) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            travelerForm.getModelObject().copy(model.getObject());
            target.add(travelerForm);
            modalWindow.close(target);
            target.appendJavaScript(JSUtils.INITIALIZE);
        }
    };
    link.add(new Label(LABEL, Model.of(model.getObject().getName())));
    add(link);
}

From source file:ch.bd.qv.quiz.panels.AdminPanel.java

License:Apache License

public AdminPanel(String id) {
    super(id);//from  w  ww. j  a  v  a2  s  .c  om
    add(new FeedbackPanel("feedback"));
    Form form = new Form("form");
    form.setMultiPart(true);
    form.add(fup = new FileUploadField("fileupload", new Model()));
    fup.setRequired(true);
    form.add(new AjaxSubmitLink("submit") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            List<FileUpload> uploads = fup.getConvertedInput();
            try {
                uploadBean.purgeAndUpload(uploads.get(0).getBytes());
            } catch (Exception e) {
                AdminPanel.this.get("feedback").error(Throwables.getStackTraceAsString(e));
            }
            target.add(findParent(AdminPanel.class));
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(findParent(AdminPanel.class));
        }
    });
    add(form);
}