Example usage for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton AjaxFallbackButton

List of usage examples for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton AjaxFallbackButton

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton AjaxFallbackButton.

Prototype

public AjaxFallbackButton(String id, Form<?> form) 

Source Link

Document

Construct.

Usage

From source file:de.alpharogroup.wicket.components.beaneditor.BeanEditorPanel.java

License:Apache License

/**
 * Factory method for creating the Button. This method is invoked in the constructor from the
 * derived classes and can be overridden so users can provide their own version of a Button.
 *
 * @param id//from  ww w.jav  a 2s . co m
 *            the id
 * @param form
 *            the form
 * @return the Button
 */
protected Button newSubmitButton(final String id, final Form<?> form) {
    final Button button = new AjaxFallbackButton(id, form) {
        /**
         * The serialVersionUID
         */
        private static final long serialVersionUID = 1L;

        /**
         * {@inheritDoc}
         */
        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            BeanEditorPanel.this.onSubmit(target, form);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            BeanEditorPanel.this.onSubmit(target, form);
        }
    };
    return button;
}

From source file:de.alpharogroup.wicket.components.examples.fragment.replacewith.ReplaceWithPanel.java

License:Apache License

protected Component newEditPersonPanel(final String id, final IModel<PersonBean> model) {
    return new EditPersonPanel(id, model) {
        private static final long serialVersionUID = 1L;

        @Override//from  w ww. java2  s .  co m
        protected Component newSubmitButton(final String id, final Form<?> form) {
            return new AjaxFallbackButton(id, form) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onConfigure() {
                    super.onConfigure();
                    setVisibilityAllowed(false);
                };
            }.setOutputMarkupId(true);
        }
    };
}

From source file:de.widone.web.authentication.panel.newuser.NewUserPanel.java

License:Apache License

public NewUserPanel(String id) {
    super(id);//from   www.  j a  v a 2 s.  c o m
    add(new FeedbackPanel(feedback).setOutputMarkupId(true));

    TextField<String> usernameTextField = (TextField<String>) new TextField("username")
            .add(new StringValidator.LengthBetweenValidator(3, 12));
    PasswordTextField passwordTextField = new PasswordTextField("password");
    PasswordTextField passwordAgainTextField = new PasswordTextField("passwordAgain", Model.of(""));

    add(new Form<User>("newUserForm", new CompoundPropertyModel<User>(new User())).add(usernameTextField)
            .add(passwordTextField).add(passwordAgainTextField)
            .add(new FormComponentLabel("usernameLabel", usernameTextField))
            .add(new FormComponentLabel("passwordLabel", passwordTextField))
            .add(new FormComponentLabel("passwordAgainLabel", passwordAgainTextField))
            .add(new AjaxFallbackLink<Void>("cancel") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    send(getPage(), Broadcast.EXACT, new CancelEvent(target));
                }
            }).add(new AjaxFallbackButton("submit", (Form) get("newUserForm")) {
                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(NewUserPanel.this.get(feedback));
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    send(getPage(), Broadcast.EXACT,
                            new UserCreatedEvent(target, (User) form.getModelObject()));
                }
            }).add(new EqualPasswordInputValidator(passwordTextField, passwordAgainTextField)));
}

From source file:de.widone.web.panel.newtask.NewTaskPanel.java

License:Apache License

public NewTaskPanel(String id, final IModel<TaskList> selectedTaskList) {
    super(id, selectedTaskList);
    add(new FeedbackPanel(FEEDBACK).setOutputMarkupId(true));

    add(new Form<Task>(NEW_TASK_FORM, new CompoundPropertyModel<Task>(new Task()))
            .add(new TextField(DESCRIPTION).add(StringValidator.minimumLength(3)).setRequired(true))
            .add(new AjaxFallbackButton("submit", (Form) get(NEW_TASK_FORM)) {
                @Override/*from w  ww.j  a  v  a  2s  .c  o m*/
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(NewTaskPanel.this.get(FEEDBACK));
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    send(getPage(), Broadcast.EXACT, new NewTaskEvent(target, (Task) form.getModelObject()));
                }
            }));
}

From source file:de.widone.web.panel.newtasklist.NewTaskListPanel.java

License:Apache License

public NewTaskListPanel(String id, IModel<TaskList> choice, IModel<List<TaskList>> choices) {
    super(id);// www. j  a va2 s. c o  m
    add(new FeedbackPanel(FEEDBACK).setOutputMarkupId(true));
    add(new TaskListDropDown(TASK_LIST, choice, choices));

    add(new Form<TaskList>(NEW_TASK_LIST_FORM, new CompoundPropertyModel<TaskList>(new TaskList()))
            .add(new TextField(DESCRIPTION).add(StringValidator.minimumLength(3)).setRequired(true))
            .add(new AjaxFallbackButton("submit", (Form) get(NEW_TASK_LIST_FORM)) {
                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(NewTaskListPanel.this.get(FEEDBACK));
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    send(getPage(), Broadcast.EXACT,
                            new NewTaskListEvent(target, (TaskList) form.getModelObject()));
                }
            }));

}

From source file:de.widone.web.panel.userdetails.UserDetailsPanel.java

License:Apache License

public UserDetailsPanel(String id, IModel<User> model) {
    super(id, model);
    add(new FeedbackPanel("feedback").setOutputMarkupId(true));

    TextField<String> firstnameTextField = new TextField("firstname");
    TextField<String> lastnameTextField = new TextField("lastname");
    TextField<String> emailTextField = new EmailTextField("email");
    TextField<Date> birthdayTextField = (TextField<Date>) new DateTextField("birthday").add(new DatePicker());
    PasswordTextField passwordTextField = (PasswordTextField) new PasswordTextField("passwordUpdate",
            Model.of("aaaaaa")).setResetPassword(false).setRequired(false);
    PasswordTextField passwordAgainTextField = (PasswordTextField) new PasswordTextField("passwordAgain",
            Model.of("")).setRequired(false);

    add(new Form<User>("userDetailsForm", new CompoundPropertyModel<User>(model)).add(firstnameTextField)
            .add(lastnameTextField).add(emailTextField).add(birthdayTextField).add(passwordTextField)
            .add(passwordAgainTextField).add(new FormComponentLabel("firstnameLabel", firstnameTextField))
            .add(new FormComponentLabel("lastnameLabel", lastnameTextField))
            .add(new FormComponentLabel("emailLabel", emailTextField))
            .add(new FormComponentLabel("birthdayLabel", birthdayTextField))
            .add(new FormComponentLabel("passwordLabel", passwordTextField))
            .add(new FormComponentLabel("passwordAgainLabel", passwordAgainTextField))
            .add(new AjaxFallbackButton("submit", (Form) get("userDetailsForm")) {
                @Override/*from  ww w .j a v a 2 s .c  om*/
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(UserDetailsPanel.this.get("feedback"));
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    send(getPage(), Broadcast.EXACT, new UserUpdatedEvent(target, (User) form.getModelObject(),
                            passwordChanged ? passwordUpdate : null));
                }
            }).add(new AjaxFallbackLink<Void>("cancel") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    send(getPage(), Broadcast.BREADTH, new CancelEvent(target));
                }
            }));
}

From source file:it.av.eatt.web.page.RistoranteEditDataPage.java

License:Apache License

/**
 * //  ww  w.  ja v a 2s  . com
 * @param parameters
 * @throws JackWicketException
 */
public RistoranteEditDataPage(PageParameters parameters) throws JackWicketException {

    String ristoranteId = parameters.getString("ristoranteId", "");
    if (StringUtils.isNotBlank(ristoranteId)) {
        this.ristorante = ristoranteService.getByID(ristoranteId);
    } else {
        setRedirect(true);
        setResponsePage(getApplication().getHomePage());
    }
    actualDescriptionLanguage = getInitialLanguage();
    form = new Form<Ristorante>("ristoranteForm", new CompoundPropertyModel<Ristorante>(ristorante));
    form.setOutputMarkupId(true);
    form.add(new RequiredTextField<String>(Ristorante.NAME));

    form.add(new TextField<String>(Ristorante.WWW).setOutputMarkupId(true));
    form.add(new TagBox(new Model<String>(""), "tagBox", ristorante));

    form.add(new CheckBox("types.ristorante"));
    form.add(new CheckBox("types.pizzeria"));
    form.add(new CheckBox("types.bar"));

    form.add(new ListView<Tag>(Ristorante.TAGS) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Tag> item) {
            item.add(new Label("tagItem", item.getModelObject().getTag()));
            item.add(new AjaxFallbackLink<String>("buttonTagItemRemove") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    getList().remove(getParent().getDefaultModelObject());
                    if (target != null) {
                        target.addComponent(form);
                    }
                }
            });
        }
    });
    descriptionLinksContainer = new WebMarkupContainer("descriptionLinksContainer");
    descriptionLinksContainer.setOutputMarkupId(true);
    form.add(descriptionLinksContainer);
    ListView<Language> descriptionsLinks = new ListView<Language>("descriptionLinks",
            languageService.getAll()) {
        @Override
        protected void populateItem(final ListItem<Language> item) {
            item.add(new AjaxFallbackButton("descriptionLink", form) {

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    if (actualDescriptionLanguage.getCountry().equals(item.getModelObject().getCountry())) {
                        tag.getAttributes().put("class", "descriptionLink descriptionLinkActive");
                    }
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    List<RistoranteDescriptionI18n> descs = ristorante.getDescriptions();
                    boolean langpresent = false;
                    for (RistoranteDescriptionI18n ristoranteDescriptionI18n : descs) {
                        if (ristoranteDescriptionI18n.getLanguage().equals(item.getModelObject())) {
                            langpresent = true;
                        }
                    }
                    if (!(langpresent)) {
                        ristorante.addDescriptions(new RistoranteDescriptionI18n(item.getModelObject()));
                    }
                    actualDescriptionLanguage = item.getModelObject();
                    descriptions.removeAll();
                    if (target != null) {
                        target.addComponent(descriptionsContainer);
                        target.addComponent(descriptionLinksContainer);
                    }
                }
            }.add(new Label("linkName", getString(item.getModelObject().getCountry()))));
        }
    };
    descriptionLinksContainer.add(descriptionsLinks);
    descriptionsContainer = new WebMarkupContainer("descriptionsContainer");
    descriptionsContainer.setOutputMarkupId(true);
    form.add(descriptionsContainer);
    descriptions = new ListView<RistoranteDescriptionI18n>("descriptions") {
        @Override
        protected void populateItem(ListItem<RistoranteDescriptionI18n> item) {
            boolean visible = actualDescriptionLanguage.equals(item.getModelObject().getLanguage());
            item.add(new TextArea<String>(RistoranteDescriptionI18n.DESCRIPTION,
                    new PropertyModel<String>(item.getModelObject(), RistoranteDescriptionI18n.DESCRIPTION))
                            .setVisible(visible));
        }
    };
    descriptions.setReuseItems(true);
    descriptions.setOutputMarkupId(true);
    descriptionsContainer.add(descriptions);
    // form.add(new DropDownChoice<EaterProfile>("userProfile", new
    // ArrayList<EaterProfile>(userProfileService.getAll()), new UserProfilesList()).setOutputMarkupId(true));

    form.add(new AjaxFallbackButton("addTag", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            String tagValue = ((TagBox) form.get("tagBox")).getModelObject();
            if (StringUtils.isNotBlank(tagValue)) {
                Ristorante risto = ((Ristorante) form.getModelObject());
                try {
                    risto.getTags().add(tagService.insert(tagValue));
                    form.setModelObject(risto);
                    if (target != null) {
                        target.addComponent(form);
                    }
                } catch (JackWicketException e) {
                    error("ERROR: " + e.getMessage());
                    if (target != null) {
                        target.addComponent(getFeedbackPanel());
                    }
                }
            }
            // after clean up the tagBox
            ((TagBox) form.get("tagBox")).setModelObject(null);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            if (target != null) {
                target.addComponent(getFeedbackPanel());
            }
        }
    });

    form.add(new AjaxFallbackLink<Ristorante>("buttonClearForm", new Model<Ristorante>(ristorante)) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            form.setModelObject(new Ristorante());
            if (target != null) {
                target.addComponent(form);
            }
        }
    });
    form.add(new SubmitButton("submitRestaurant", form));
    add(form);
    add(new SubmitButton("submitRestaurantRight", form));
}

From source file:it.av.eatt.web.page.RistoranteEditPicturePage.java

License:Apache License

/**
 * @param parameters//from  w ww. j  a  v a2  s.  co  m
 * @throws JackWicketException
 */
public RistoranteEditPicturePage(PageParameters parameters) throws JackWicketException {

    String ristoranteId = parameters.getString("ristoranteId", "");
    if (StringUtils.isNotBlank(ristoranteId)) {
        this.ristorante = ristoranteService.getByID(ristoranteId);
    } else {
        setRedirect(true);
        setResponsePage(getApplication().getHomePage());
    }

    form = new Form<Ristorante>("ristorantePicturesForm");
    add(form);
    form.setOutputMarkupId(true);
    form.setMultiPart(true);
    form.setMaxSize(Bytes.megabytes(1));
    uploadField = new FileUploadField("uploadField");
    form.add(uploadField);
    form.add(new UploadProgressBar("progressBar", form));
    form.add(new SubmitButton("submitForm", form));

    picturesList = new ListView<RistorantePicture>("picturesList", ristorante.getPictures()) {
        @Override
        protected void populateItem(final ListItem<RistorantePicture> item) {
            //Button disabled, because the getPicture is not yet implemented
            item.add(new AjaxFallbackButton("publish-unpublish", form) {
                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    item.getModelObject().setActive(!item.getModelObject().isActive());
                    try {
                        ristorantePictureService.save(item.getModelObject());
                        ristorante = ristoranteService.getByID(ristorante.getId());
                    } catch (JackWicketException e) {
                        error(getString("genericErrorMessage"));
                    }
                    if (target != null) {
                        target.addComponent(getFeedbackPanel());
                        target.addComponent(form);
                    }
                }

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    if (item.getModelObject().isActive()) {
                        tag.getAttributes().put("title", getString("button.unpublish"));
                        tag.getAttributes().put("class", "unpublishPictureButton");
                    } else {
                        tag.getAttributes().put("title", getString("button.publish"));
                        tag.getAttributes().put("class", "publishPictureButton");
                    }
                }
            }.setVisible(false));
            item.add(new AjaxFallbackButton("remove", form) {
                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    try {
                        RistorantePicture picture = item.getModelObject();
                        ristorante.getPictures().remove(picture);
                        ristoranteService.updateNoRevision(ristorante);
                        ristorantePictureService.remove(picture);
                        ristorante = ristoranteService.getByID(ristorante.getId());
                    } catch (JackWicketException e) {
                        error(getString("genericErrorMessage"));
                    }
                    if (target != null) {
                        target.addComponent(getFeedbackPanel());
                        target.addComponent(form);
                    }
                }
            });
            item.add(new Image("picture", new DynamicImageResource() {
                @Override
                protected byte[] getImageData() {
                    return item.getModelObject().getPicture();
                }
            }));
        }
    };
    picturesList.setOutputMarkupId(true);
    picturesList.setReuseItems(true);
    form.add(picturesList);

}

From source file:it.av.eatt.web.page.RistoranteViewPage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 * /*from   w  w w .  ja v a  2  s .  co  m*/
 * @throws JackWicketException
 */
public RistoranteViewPage(PageParameters parameters) throws JackWicketException {
    actualDescriptionLanguage = getInitialLanguage();
    String ristoranteId = parameters.getString("ristoranteId", "");
    if (StringUtils.isNotBlank(ristoranteId)) {
        this.ristorante = ristoranteService.getByID(ristoranteId);
    } else {

        setRedirect(true);
        setResponsePage(getApplication().getHomePage());
    }

    form = new Form<Ristorante>("ristoranteForm", new CompoundPropertyModel<Ristorante>(ristorante));
    add(form);
    form.setOutputMarkupId(true);
    form.add(new Label(Ristorante.NAME));

    Label typeRistoranteLabel = new Label("typeRistoranteLabel", getString("type.Ristorante"));
    typeRistoranteLabel.setVisible(ristorante.getTypes().isRistorante());
    form.add(typeRistoranteLabel);
    Label typePizzeriaLabel = new Label("typePizzeriaLabel", getString("type.Pizzeria"));
    typePizzeriaLabel.setVisible(ristorante.getTypes().isPizzeria());
    form.add(typePizzeriaLabel);
    Label typeBarLabel = new Label("typeBarLabel", getString("type.Bar"));
    typeBarLabel.setVisible(ristorante.getTypes().isBar());
    form.add(typeBarLabel);

    form.add(new SmartLinkLabel(Ristorante.WWW));
    form.add(new ListView<Tag>(Ristorante.TAGS) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Tag> item) {
            item.add(new Label("tagItem", item.getModelObject().getTag()));
        }
    });
    descriptionLinksContainer = new WebMarkupContainer("descriptionLinksContainer");
    descriptionLinksContainer.setOutputMarkupId(true);
    form.add(descriptionLinksContainer);
    ListView<Language> descriptionsLinks = new ListView<Language>("descriptionLinks",
            languageService.getAll()) {
        @Override
        protected void populateItem(final ListItem<Language> item) {
            item.add(new AjaxFallbackButton("descriptionLink", form) {

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    boolean langpresent = isDescriptionPresentOnTheGivenLanguage(ristorante,
                            item.getModelObject());
                    HashMap<String, String> tagAttrs = new HashMap<String, String>();
                    if (!langpresent) {
                        tagAttrs.put("title", getString("descriptionNotAvailableLang"));
                        tagAttrs.put("class", "descriptionNotAvailableLang");
                    }
                    if (actualDescriptionLanguage.getCountry().equals(item.getModelObject().getCountry())) {
                        if (tagAttrs.containsKey("class")) {
                            tagAttrs.put("class",
                                    tagAttrs.get("class").concat(" descriptionLink descriptionLinkActive"));
                        } else {
                            tagAttrs.put("class", "descriptionLink descriptionLinkActive");
                        }
                    }
                    tag.getAttributes().putAll(tagAttrs);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    List<RistoranteDescriptionI18n> descs = ristorante.getDescriptions();
                    boolean langpresent = isDescriptionPresentOnTheGivenLanguage(ristorante,
                            item.getModelObject());
                    for (RistoranteDescriptionI18n ristoranteDescriptionI18n : descs) {
                        if (ristoranteDescriptionI18n.getLanguage().equals(item.getModelObject())) {
                            langpresent = true;
                        }
                    }
                    if (!(langpresent)) {
                        ristorante.addDescriptions(new RistoranteDescriptionI18n(item.getModelObject()));
                    }
                    actualDescriptionLanguage = item.getModelObject();
                    descriptions.removeAll();
                    if (target != null) {
                        target.addComponent(descriptionsContainer);
                        target.addComponent(descriptionLinksContainer);
                    }
                }
            }.add(new Label("linkName", getString(item.getModelObject().getCountry()))));
        }
    };
    descriptionLinksContainer.add(descriptionsLinks);
    descriptionsContainer = new WebMarkupContainer("descriptionsContainer");
    descriptionsContainer.setOutputMarkupId(true);
    form.add(descriptionsContainer);
    descriptions = new ListView<RistoranteDescriptionI18n>("descriptions") {
        @Override
        protected void populateItem(ListItem<RistoranteDescriptionI18n> item) {
            boolean visible = actualDescriptionLanguage.equals(item.getModelObject().getLanguage());
            if (item.getModelObject().getDescription() == null
                    || item.getModelObject().getDescription().isEmpty()) {
                item.add(new Label(RistoranteDescriptionI18n.DESCRIPTION,
                        getString("descriptionNotAvailableLang")).setVisible(visible));
            } else {
                item.add(new MultiLineLabel(RistoranteDescriptionI18n.DESCRIPTION,
                        new PropertyModel<String>(item.getModelObject(), RistoranteDescriptionI18n.DESCRIPTION))
                                .setVisible(visible));
            }
        }
    };
    descriptionsContainer.add(descriptions);
    // form.add(new DropDownChoice<EaterProfile>("userProfile", new
    // ArrayList<EaterProfile>(userProfileService.getAll()), new UserProfilesList()).setOutputMarkupId(true));
    form.add(new Label("revisionNumber"));

    Form<Ristorante> formAddress = new Form<Ristorante>("ristoranteAddressForm",
            new CompoundPropertyModel<Ristorante>(ristorante));
    add(formAddress);
    formAddress.add(new Label(Ristorante.ADDRESS));
    formAddress.add(new Label(Ristorante.CITY));
    formAddress.add(new Label(Ristorante.PROVINCE));
    formAddress.add(new Label(Ristorante.POSTALCODE));
    formAddress.add(new Label(Ristorante.COUNTRY));
    formAddress.add(new Label(Ristorante.MOBILE_PHONE_NUMBER));
    formAddress.add(new Label(Ristorante.PHONE_NUMBER));
    formAddress.add(new Label(Ristorante.FAX_NUMBER));
    formAddress.add(new RatingPanel("rating1", new PropertyModel<Integer>(getRistorante(), "rating"),
            new Model<Integer>(5), new PropertyModel<Integer>(getRistorante(), "rates.size"),
            new PropertyModel<Boolean>(this, "hasVoted"), true) {
        @Override
        protected boolean onIsStarActive(int star) {
            return star < ((int) (getRistorante().getRating() + 0.5));
        }

        @Override
        protected void onRated(int rating, AjaxRequestTarget target) {
            try {
                setHasVoted(Boolean.TRUE);
                ristoranteService.addRate(getRistorante(), getLoggedInUser(), rating);
            } catch (JackWicketException e) {
                error(e);
            }
        }
    });

    AjaxFallbackLink<String> editRistorante = new AjaxFallbackLink<String>("editRistorante") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                setResponsePage(new RistoranteEditAddressPage(getRistorante()));
            } catch (JackWicketException e) {
                error(new StringResourceModel("genericErrorMessage", this, null).getString());
            }
        }
    };
    editRistorante.setOutputMarkupId(true);
    if (getApplication().getSecuritySettings().getAuthorizationStrategy()
            .isInstantiationAuthorized(RistoranteEditAddressPage.class)) {
        editRistorante.setVisible(true);
    } else {
        editRistorante.setVisible(false);
    }
    add(editRistorante);

    AjaxFallbackLink<String> editDataRistorante = new AjaxFallbackLink<String>("editDataRistorante") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                setResponsePage(new RistoranteEditDataPage(getRistorante()));
            } catch (JackWicketException e) {
                error(new StringResourceModel("genericErrorMessage", this, null).getString());
            }
        }
    };
    editDataRistorante.setOutputMarkupId(true);
    add(editDataRistorante);

    AjaxFallbackLink<String> editPictures = new AjaxFallbackLink<String>("editPictures") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                setResponsePage(new RistoranteEditPicturePage(getRistorante()));
            } catch (JackWicketException e) {
                error(new StringResourceModel("genericErrorMessage", this, null).getString());
            }
        }
    };
    editPictures.setOutputMarkupId(true);
    add(editPictures);

    picturesList = new ListView<RistorantePicture>("picturesList", ristorante.getActivePictures()) {

        @Override
        protected void populateItem(final ListItem<RistorantePicture> item) {
            item.add(new Image("picture", new DynamicImageResource() {
                @Override
                protected byte[] getImageData() {
                    return item.getModelObject().getPicture();
                }
            }));
        }
    };
    form.add(picturesList);
    add(revisionsPanel = new ModalWindow("revisionsPanel"));
    revisionsPanel.setWidthUnit("%");
    revisionsPanel.setInitialHeight(450);
    revisionsPanel.setInitialWidth(100);
    revisionsPanel.setResizable(false);
    revisionsPanel.setContent(new RistoranteRevisionsPanel(revisionsPanel.getContentId(), getFeedbackPanel()));
    revisionsPanel.setTitle("Revisions list");
    revisionsPanel.setCookieName("SC-revisionLists");

    revisionsPanel.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            return true;
        }
    });

    revisionsPanel.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        public void onClose(AjaxRequestTarget target) {

        }
    });

    add(new AjaxLink("showsAllRevisions") {
        public void onClick(AjaxRequestTarget target) {
            ((RistoranteRevisionsPanel) revisionsPanel.get(revisionsPanel.getContentId()))
                    .refreshRevisionsList(ristorante);
            revisionsPanel.show(target);
        }
    });

    setHasVoted(ristoranteService.hasUsersAlreadyRated(getRistorante(), getLoggedInUser())
            || getLoggedInUser() == null);

}

From source file:it.av.youeat.web.page.MessagePage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 * /*from   w w  w. j a  v a  2s. co  m*/
 * @throws YoueatException
 */
public MessagePage(PageParameters parameters) throws YoueatException {
    super();
    final String dialogId = parameters.get(YoueatHttpParams.DIALOG_ID).toString("");
    if (StringUtils.isBlank(dialogId)) {
        throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
    }

    add(getFeedbackPanel());

    dialog = dialogService.readDiscussion(dialogId, getLoggedInUser());

    final WebMarkupContainer messageListContainer = new WebMarkupContainer("messagesListContainer");
    messageListContainer.setOutputMarkupId(true);
    add(messageListContainer);
    messageList = new PropertyListView<Message>("messagesList", new MessagesModel()) {

        @Override
        protected void populateItem(final ListItem<Message> item) {
            item.add(new BookmarkablePageLink("linkToUser", EaterViewPage.class,
                    new PageParameters(
                            YoueatHttpParams.YOUEAT_ID + "=" + item.getModelObject().getSender().getId()))
                                    .add(new Label(Message.SENDER_FIELD)));
            item.add(new Label(Message.SENTTIME_FIELD));
            String body = templateUtil.resolveTemplateEater(item.getModelObject(), true, null, getWebPage());
            item.add(new Label(Message.BODY_FIELD, body).setEscapeModelStrings(false));
            item.add(new Label(Message.TITLE_FIELD));
            item.add(ImagesAvatar.getAvatar("avatar", item.getModelObject().getSender(), this.getPage(), true));
        }
    };
    messageListContainer.add(messageList);

    final Form<Message> sendMessageForm = new Form<Message>("sendMessageForm",
            new CompoundPropertyModel<Message>(getNewMessage()));
    sendMessageForm.setOutputMarkupId(true);
    add(sendMessageForm);
    sendMessageForm.add(new TextArea<String>("body").setRequired(true)
            .add(StringValidator.maximumLength(Message.BODY_MAX_LENGTH)));
    sendMessageForm.add(new AjaxFallbackButton("submit", sendMessageForm) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Message msgToSend = (Message) form.getModelObject();
            dialogService.reply(msgToSend, dialog, dialog.checkCounterpart(getLoggedInUser()), getWebPage());
            dialog = dialogService.readDiscussion(dialogId, getLoggedInUser());
            sendMessageForm.setModelObject(getNewMessage());
            if (target != null) {
                target.addComponent(getFeedbackPanel());
                target.addComponent(sendMessageForm);
                target.addComponent(messageListContainer);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            // for the moment I don't want show the error message
            target.addComponent(getFeedbackPanel());
        }
    });

    add(new BookmarkablePageLink("goSearchFriendPage", SearchFriendPage.class));
}