Example usage for org.apache.wicket.extensions.markup.html.basic SmartLinkLabel SmartLinkLabel

List of usage examples for org.apache.wicket.extensions.markup.html.basic SmartLinkLabel SmartLinkLabel

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.basic SmartLinkLabel SmartLinkLabel.

Prototype

public SmartLinkLabel(final String name) 

Source Link

Usage

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

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 * /*w ww.j  a  va 2  s. c  o 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.RistoranteViewPage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 * //from w  w  w.java2 s.c  o  m
 * @throws YoueatException
 */
public RistoranteViewPage(PageParameters parameters) throws YoueatException {
    actualDescriptionLanguage = getInitialLanguage();
    String ristoranteId = parameters.get(YoueatHttpParams.RISTORANTE_ID).toString("");
    if (StringUtils.isNotBlank(ristoranteId)) {
        this.ristorante = ristoranteService.getByID(ristoranteId);
    } else {
        throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
    }
    appendToPageTile(" " + ristorante.getName() + ", " + ristorante.getCity().getName());
    ristorante = ristorante.addDescLangIfNotPresent(actualDescriptionLanguage);
    ristorante = ristorante.addBlackboardLangIfNotPresent(actualDescriptionLanguage);
    formRisto = new Form<Ristorante>("ristoranteForm", new CompoundPropertyModel<Ristorante>(ristorante));
    add(formRisto);
    formRisto.setOutputMarkupId(true);
    formRisto.add(new Label(Ristorante.NAME));

    formRisto.add(new SmartLinkLabel(Ristorante.WWW));
    formRisto.add(new SmartLinkLabel(Ristorante.EMAIL));
    formRisto.add(new ListView<Tag>(Ristorante.TAGS) {

        @Override
        protected void populateItem(ListItem<Tag> item) {
            StringBuffer tag = new StringBuffer(item.getModelObject().getTag());
            if (item.getIndex() < ristorante.getTags().size() - 1) {
                tag.append(",");
            }
            item.add(new Label("tagItem", tag.toString()));
        }
    });
    descriptionLinksContainer = new WebMarkupContainer("descriptionLinksContainer");
    descriptionLinksContainer.setOutputMarkupId(true);
    formRisto.add(descriptionLinksContainer);
    ListView<Language> descriptionsLinks = new ListView<Language>("descriptionLinks",
            languageService.getAll()) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
        };

        @Override
        protected void populateItem(final ListItem<Language> item) {
            if (actualDescriptionLanguage.getCountry().equals(item.getModelObject().getCountry())) {
                item.add(new AttributeAppender("class", new Model<String>("ui-tabs-selected ui-state-active"),
                        " "));
            }
            item.add(new AjaxFallbackButton("descriptionLink", formRisto) {

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    boolean langpresent = ristorante.checkDesctiption(item.getModelObject());
                    HashMap<String, String> tagAttrs = new HashMap<String, String>();
                    if (!langpresent) {
                        tagAttrs.put("title", getString("descriptionNotAvailableLang"));
                        tagAttrs.put("class", "descriptionNotAvailableLang");
                    }
                    tag.getAttributes().putAll(tagAttrs);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    actualDescriptionLanguage = item.getModelObject();
                    ristorante = ristorante.addDescLangIfNotPresent(actualDescriptionLanguage);
                    formRisto.setModelObject(ristorante);
                    descriptions.removeAll();
                    if (target != null) {
                        target.addComponent(descriptionsContainer);
                        target.addComponent(descriptionLinksContainer);
                        target.addComponent(restaurateurBlackboardsContainer);
                    }
                }

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    // TODO 1.5 Auto-generated method stub

                }
            }.add(new Label("linkName", getString(item.getModelObject().getCountry()))));
        }
    };
    descriptionLinksContainer.add(descriptionsLinks);
    descriptionsContainer = new WebMarkupContainer("descriptionsContainer");
    descriptionsContainer.setOutputMarkupId(true);
    formRisto.add(descriptionsContainer);
    descriptions = new ListView<RistoranteDescriptionI18n>("descriptions", new DescriptionsModel()) {
        @Override
        protected void populateItem(ListItem<RistoranteDescriptionI18n> item) {
            boolean visible = actualDescriptionLanguage.equals(item.getModelObject().getLanguage());
            if (item.getModelObject().getDescription() == null
                    || StringUtils.isBlank(item.getModelObject().getDescription())) {
                item.add(new Label(RistoranteDescriptionI18n.DESCRIPTION,
                        getString("descriptionNotAvailableLang")).setVisible(visible)
                                .setOutputMarkupPlaceholderTag(true));
            } else {
                item.add(new MultiLineLabel(RistoranteDescriptionI18n.DESCRIPTION,
                        new PropertyModel<String>(item.getModelObject(), RistoranteDescriptionI18n.DESCRIPTION))
                                .setVisible(visible).setOutputMarkupPlaceholderTag(true));
            }
        }
    };
    descriptionsContainer.add(descriptions);

    restaurateurBlackboardsContainer = new WebMarkupContainer("restaurateurBlackboardsContainer");
    restaurateurBlackboardsContainer.setOutputMarkupId(true);
    restaurateurBlackboards = new ListView<RestaurateurBlackboardI18n>("restaurateurBlackboards",
            new BlackBoardsModel()) {
        @Override
        protected void populateItem(ListItem<RestaurateurBlackboardI18n> item) {
            boolean visible = actualDescriptionLanguage.equals(item.getModelObject().getLanguage());
            if (item.getModelObject().getBlackboard() == null
                    || StringUtils.isBlank(item.getModelObject().getBlackboard())) {
                item.add(new Label("restaurateurBlackboard", "").setVisible(false)
                        .setOutputMarkupPlaceholderTag(true));
            } else {
                item.add(new MultiLineLabel("restaurateurBlackboard",
                        new PropertyModel<String>(item.getModelObject(), RestaurateurBlackboardI18n.BLACKBOARD))
                                .setVisible(visible).setOutputMarkupPlaceholderTag(true)
                                .add(new AttributeAppender("class",
                                        new Model("blackboard_" + getInitialLanguage().getLanguage()), " ")));
            }
        }
    };
    restaurateurBlackboardsContainer.add(restaurateurBlackboards);
    formRisto.add(restaurateurBlackboardsContainer);

    formRisto.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) {
            setHasVoted(Boolean.TRUE);
            ristoranteService.addRate(getRistorante(), getLoggedInUser(), rating);
            ristorante = ristoranteService.getByID(ristorante.getId());
            info(getString("info.ratingSaved"));
            if (target != null) {
                target.addComponent(getFeedbackPanel());
            }
        }
    });
    BookmarkablePageLink editAddressRistorante = new BookmarkablePageLink("editAddressRistorante",
            RistoranteEditAddressPage.class,
            new PageParameters(YoueatHttpParams.RISTORANTE_ID + "=" + ristorante.getId()));
    editAddressRistorante.setOutputMarkupId(true);
    add(editAddressRistorante);

    if (getApplication().getSecuritySettings().getAuthorizationStrategy()
            .isInstantiationAuthorized(RistoranteEditAddressPage.class)) {
        editAddressRistorante.setVisible(true);
    } else {
        editAddressRistorante.setVisible(false);
    }
    add(editAddressRistorante);

    BookmarkablePageLink editDataRistorante = new BookmarkablePageLink("editDataRistorante",
            RistoranteEditDataPage.class,
            new PageParameters(YoueatHttpParams.RISTORANTE_ID + "=" + ristorante.getId()));
    editDataRistorante.setOutputMarkupId(true);
    add(editDataRistorante);

    BookmarkablePageLink editPictures = new BookmarkablePageLink("editPictures",
            RistoranteEditPicturePage.class,
            new PageParameters(YoueatHttpParams.RISTORANTE_ID + "=" + ristorante.getId()));
    editPictures.setOutputMarkupId(true);
    add(editPictures);

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

        @Override
        protected void populateItem(final ListItem<RistorantePicture> item) {
            Link<RistorantePicture> imageLink = new Link<RistorantePicture>("pictureLink", item.getModel()) {
                @Override
                public void onClick() {
                    setResponsePage(new ImageViewPage(getModelObject().getPicture()));
                }
            };
            imageLink.add(ImageRisto.getThumbnailImage("picture", item.getModelObject().getPicture(), true));
            item.add(imageLink);
        }
    };
    formRisto.add(picturesList);

    add(revisionModal = new ModalWindow("revisionsPanel"));
    //revisionModal.setWidthUnit("%");
    //revisionModal.setInitialHeight(40);
    //revisionModal.setInitialWidth(90);
    revisionModal.setResizable(false);
    RistoranteRevisionsPanel revisionsPanel = new RistoranteRevisionsPanel(revisionModal.getContentId(),
            getFeedbackPanel());
    revisionsPanel.refreshRevisionsList(ristorante, actualDescriptionLanguage);
    revisionModal.setContent(revisionsPanel);
    revisionModal.setTitle("Revisions list");
    revisionModal.setCookieName("SC-revisionLists");
    //JQUERY LAYOUT
    //revisionModal.setCssClassName("ui-widget ui-widget-content ui-corner-all");
    revisionModal.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

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

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

        }
    });

    add(new AjaxLink("showsAllRevisions") {
        public void onClick(AjaxRequestTarget target) {
            revisionModal.show(target);
        }
    });

    add(new AjaxLink<String>("tried") {
        public void onClick(AjaxRequestTarget target) {
            if (getLoggedInUser() != null) {
                activityService.addTriedRisto(getLoggedInUser(), ristorante);
                info(getString("info.IateHere", new Model<Ristorante>(ristorante)));
            } else {
                info(getString("action.notlogged"));
            }
            target.addComponent(getFeedbackPanel());
        }
    });

    AjaxFallbackLink<String> asfavourite = new AjaxFallbackLink<String>("asfavourite") {
        public void onClick(AjaxRequestTarget target) {
            if (getLoggedInUser() != null) {
                if (activityService.isFavouriteRisto(getLoggedInUser(), ristorante)) {
                    activityService.addRistoAsFavorite(getLoggedInUser(), ristorante);
                    info(getString("action.removedAsFavourite", new Model<Ristorante>(ristorante)));
                    asfavouriteLabel.setDefaultModelObject(getString("button.addAsFavourite"));
                } else {
                    activityService.save(new ActivityRistorante(getLoggedInUser(), ristorante,
                            ActivityRistorante.TYPE_ADDED_AS_FAVOURITE));
                    info(getString("action.addedAsFavourite", new Model<Ristorante>(ristorante)));
                    asfavouriteLabel.setDefaultModelObject(getString("button.removeAsFavourite"));
                }
            } else {
                info(getString("action.notlogged"));
            }
            if (target != null) {
                target.addComponent(asfavouriteLabel);
                target.addComponent(getFeedbackPanel());
            }
        }
    };
    add(asfavourite);

    formComment = new Form<Comment>("formComment", new CompoundPropertyModel<Comment>(new Comment()));
    formComment.setOutputMarkupId(true);
    add(formComment);
    final TextField<String> newCommentTitle = new TextField<String>(Comment.TITLE_FIELD);
    newCommentTitle.setVisible(false);
    newCommentTitle.add(StringValidator.maximumLength(Comment.TITLE_MAX_LENGTH));
    newCommentTitle.setOutputMarkupPlaceholderTag(true);
    formComment.add(newCommentTitle);
    final TextArea<String> newCommentBody = new TextArea<String>(Comment.BODY_FIELD);
    newCommentBody.setRequired(true);
    newCommentBody.add(StringValidator.maximumLength(Comment.BODY_MAX_LENGTH));
    newCommentBody.setVisible(false);
    newCommentBody.setOutputMarkupPlaceholderTag(true);
    formComment.add(newCommentBody);
    final Label newCommentTitleLabel = new Label("newCommentTitleLabel", getString("label.newCommentTitle"));
    newCommentTitleLabel.setOutputMarkupPlaceholderTag(true);
    newCommentTitleLabel.setVisible(false);
    formComment.add(newCommentTitleLabel);
    final AjaxFallbackButton submitNewComment = new AjaxFallbackButton("submitNewComment", formComment) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (getLoggedInUser() != null) {
                Comment comment = (Comment) getForm().getModelObject();
                comment.setAuthor(getLoggedInUser());
                comment.setCreationTime(DateUtil.getTimestamp());
                ristorante.addComment(comment);
                try {
                    ristoranteService.updateNoRevision(ristorante);
                    activityService.save(new ActivityRistorante(getLoggedInUser(), ristorante,
                            ActivityRistorante.TYPE_NEW_COMMENT));
                    // reset the new comment formRisto
                    formComment.setModelObject(new Comment());
                    newCommentBody.setVisible(false);
                    newCommentTitle.setVisible(false);
                    newCommentTitleLabel.setVisible(false);
                    this.setVisible(false);
                    newCommentTitleLabel.setVisible(false);
                    Comment commeTitleToShow = new Comment();
                    commeTitleToShow.setTitle(comment.getTitle() != null ? "'" + comment.getTitle() + "'" : "");
                    info(getString("message.newCommentAdded", new Model<Comment>(commeTitleToShow)));
                    if (target != null) {
                        target.addComponent(formComment);
                    }
                } catch (YoueatException e) {
                    getFeedbackPanel().error(getString("genericErrorMessage"));
                }
                if (target != null) {
                    target.addComponent(getFeedbackPanel());
                }
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            if (target != null) {
                target.addComponent(getFeedbackPanel());
            }
        }
    };
    submitNewComment.setOutputMarkupPlaceholderTag(true);
    submitNewComment.setVisible(false);
    formComment.add(submitNewComment);
    commentsList = new ListView<Comment>("commentsList", new CommentsModel()) {

        @Override
        protected void populateItem(final ListItem<Comment> item) {
            item.add(new Label(Comment.AUTHOR_FIELD, item.getModelObject().getAuthor().getFirstname() + " "
                    + item.getModelObject().getAuthor().getLastname()));
            item.add(new Label(Comment.TITLE_FIELD, item.getModelObject().getTitle()));
            item.add(new Label(Comment.CREATIONTIME_FIELD,
                    DateUtil.SDF2SHOW.print(item.getModelObject().getCreationTime().getTime())));
            item.add(new MultiLineLabel(Comment.BODY_FIELD, item.getModelObject().getBody()));
        }
    };
    formComment.add(commentsList);
    add(new NewCommentButton("newComment", newCommentBody, submitNewComment, newCommentTitleLabel,
            newCommentTitle));
    add(new NewCommentButton("newCommentBottom", newCommentBody, submitNewComment, newCommentTitleLabel,
            newCommentTitle));
    asfavouriteLabel = new Label("asfavouriteLabel", getString("button.addAsFavourite"));
    if (activityService.isFavouriteRisto(getLoggedInUser(), ristorante)) {
        asfavouriteLabel.setDefaultModelObject(getString("button.removeAsFavourite"));
    }
    asfavouriteLabel.setOutputMarkupId(true);
    asfavourite.add(asfavouriteLabel);

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

    // position on the map
    final GMap2 bottomMap = new GMap2("map",
            new GMapHeaderContributor(((YoueatApplication) this.getApplication()).getGmapKey()));
    bottomMap.setOutputMarkupId(true);
    bottomMap.setMapType(GMapType.G_NORMAL_MAP);
    bottomMap.addControl(GControl.GSmallMapControl);
    bottomMap.addControl(GControl.GMapTypeControl);
    bottomMap.setZoom(16);
    if (ristorante.getLatitude() != 0 && ristorante.getLongitude() != 0) {
        GLatLng gLatLng = new GLatLng(ristorante.getLatitude(), ristorante.getLongitude());
        GMarkerOptions markerOptions = new GMarkerOptions(ristorante.getName());
        markerOptions = markerOptions.draggable(true);
        GMarker marker = new GMarker(gLatLng, markerOptions) {
            @Override
            protected void updateOnAjaxCall(AjaxRequestTarget target, GEvent overlayEvent) {
                super.updateOnAjaxCall(target, overlayEvent);
                if (getLoggedInUser() != null) {
                    ristorante.setLatitude(this.getLatLng().getLat());
                    ristorante.setLongitude(this.getLatLng().getLng());
                    ristorante = ristoranteService.updateLatitudeLongitude(ristorante);
                }
            }
        };
        marker.addListener(GEvent.dragend, new GEventHandler() {

            @Override
            public void onEvent(AjaxRequestTarget target) {
                //attach the ajax code to handle the event 
            }
        });
        bottomMap.addOverlay(marker);
        bottomMap.setCenter(gLatLng);
    } else {
        bottomMap.setVisible(false);
    }
    add(bottomMap);
    // users that already tried infos
    List<ActivityRistorante> friendThatAlreadyEat = new ArrayList<ActivityRistorante>(0);
    int numberUsersThatAlreadyEat = 0;

    if (getLoggedInUser() != null) {
        friendThatAlreadyEat = activityService.findByFriendWithActivitiesOnRistorante(getLoggedInUser(),
                ristorante, ActivityRistorante.TYPE_TRIED);
        numberUsersThatAlreadyEat = activityService.countByRistoAndType(ristorante,
                ActivityRistorante.TYPE_TRIED);
    }
    add(new Label("friendEaterListTitle",
            getString("numberOfUsersAlreadyEatAt",
                    new Model<NumberBean>(new NumberBean(numberUsersThatAlreadyEat))))
                            .setVisible(numberUsersThatAlreadyEat > 0));
    add(new FriendEaterListView("friendEaterList", friendThatAlreadyEat)
            .setVisible(friendThatAlreadyEat.size() > 0));

    // contribution infos
    List<ActivityRistorante> friendContributions = new ArrayList<ActivityRistorante>(0);
    int numberOfContributions = 0;

    if (getLoggedInUser() != null) {
        friendContributions = activityService.findByFriendContributionsOnRistorante(getLoggedInUser(),
                ristorante);
        numberOfContributions = activityService.countContributionsOnRistorante(ristorante);
    }
    add(new Label("numberOfContributions",
            getString("numberOfContributions", new Model<NumberBean>(new NumberBean(numberOfContributions))))
                    .setVisible(numberOfContributions > 0));
    add(new FriendEaterListView("friendContributionsList", friendContributions)
            .setVisible(friendContributions.size() > 0));
}