Example usage for org.apache.wicket.ajax.markup.html AjaxLink AjaxLink

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

Introduction

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

Prototype

public AjaxLink(final String id) 

Source Link

Document

Construct.

Usage

From source file:info.jtrac.wicket.ItemRelateRemovePage.java

License:Apache License

public ItemRelateRemovePage(long itemId, final ItemItem itemItem) {
    this.itemId = itemId;
    this.itemItem = itemItem;
    add(new ConfirmForm("form"));
    final String relatingRefId = itemItem.getItem().getRefId();
    final String relatedRefId = itemItem.getRelatedItem().getRefId();
    final YuiDialog relatingDialog = new YuiDialog("relatingDialog");
    final YuiDialog relatedDialog = new YuiDialog("relatedDialog");
    add(relatingDialog);/*from   www  .  j a  v a 2  s .c  o  m*/
    add(relatedDialog);
    AjaxLink relating = new AjaxLink("relating") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            Item relating = getJtrac().loadItem(itemItem.getItem().getId());
            relatingDialog.show(target, relatingRefId,
                    new ItemViewPanel(YuiDialog.CONTENT_ID, new Model(relating), true));
        }
    };
    relating.add(new Label("refId", relatingRefId));
    add(relating);

    // TODO refactor, duplicate code in ItemViewPanel
    String message = null;
    if (itemItem.getType() == DUPLICATE_OF) {
        message = localize("item_view.duplicateOf");
    } else if (itemItem.getType() == DEPENDS_ON) {
        message = localize("item_view.dependsOn");
    } else if (itemItem.getType() == RELATED) {
        message = localize("item_view.relatedTo");
    }
    add(new Label("message", message));

    AjaxLink related = new AjaxLink("related") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            Item related = getJtrac().loadItem(itemItem.getRelatedItem().getId());
            relatedDialog.show(target, relatedRefId,
                    new ItemViewPanel(YuiDialog.CONTENT_ID, new Model(related), true));
        }
    };
    related.add(new Label("refId", itemItem.getRelatedItem().getRefId()));
    add(related);

}

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

License:Apache License

/**
 * Construct.// w ww . j a v a  2  s.c  o  m
 */
public BasePage() {
    if (((SecuritySession) getSession()).getAuth() != null
            && ((SecuritySession) getSession()).getAuth().isAuthenticated()) {
        isAuthenticated = true;
    }

    loggedInUser = ((SecuritySession) getSession()).getLoggedInUser();
    if (getWebRequestCycle().getWebRequest().getCookie(CookieUtil.LANGUAGE) != null) {
        getSession().setLocale(
                new Locale(getWebRequestCycle().getWebRequest().getCookie(CookieUtil.LANGUAGE).getValue()));
    } else {
        if (loggedInUser != null) {
            getWebRequestCycle().getWebResponse()
                    .addCookie(new Cookie(CookieUtil.LANGUAGE, loggedInUser.getLanguage().getLanguage()));
            getSession().setLocale(new Locale(loggedInUser.getLanguage().getLanguage()));
        }
    }

    // add(JavascriptPackageResource.getHeaderContribution(BASEPAGE_JS));
    add(CSSPackageResource.getHeaderContribution(STYLES_CSS));

    feedbackPanel = new FeedbackPanel("feedBackPanel");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);
    ResourceReference img = new ResourceReference(this.getClass(), "resources/images/logo-mela.png");
    add(new Image("logo", img));
    add(new AjaxLink<String>("goUserPage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserManagerPage.class)) {
                setResponsePage(UserManagerPage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserManagerPage.class)));
        }
        /*To Show a JS alert on protected area
         * @Override
        protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new AjaxCallDecorator() {
            private static final long serialVersionUID = 1L;
            public CharSequence decorateScript(CharSequence script) {
                if (!(getApplication().getSecuritySettings().getAuthorizationStrategy().isInstantiationAuthorized(UserManagerPage.class))) {
                    return "alert('" + new StringResourceModel("basePage.notLogged", getPage(), null).getString() + "'); " + script;
                }
                return script;
            }
        };
        }*/
    });

    add(new AjaxLink<String>("goUserProfilePage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserProfilePage.class)) {
                setResponsePage(UserProfilePage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserProfilePage.class)));
        }
    });

    add(new AjaxLink<String>("goSearchRistorantePage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserHomePage.class)) {
                setResponsePage(UserHomePage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserHomePage.class)));
        }
    });

    add(new AjaxLink<String>("goRistoranteAddNewPage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(RistoranteAddNewPage.class)) {
                setResponsePage(RistoranteAddNewPage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(RistoranteAddNewPage.class)));
        }
    });

    add(new AjaxLink<String>("goSearchFriendPage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(SearchFriendPage.class)) {
                setResponsePage(SearchFriendPage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(SearchFriendPage.class)));
        }
    });

    add(new AjaxLink<String>("goFriendPage") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(FriendsPage.class)) {
                setResponsePage(FriendsPage.class);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(FriendsPage.class)));
        }
    });

    Link<String> goItalian = new Link<String>("goItalian") {
        @Override
        public void onClick() {
            getSession().setLocale(Locales.ITALIAN);
            getWebRequestCycle().getWebResponse()
                    .addCookie(new Cookie(CookieUtil.LANGUAGE, Locales.ITALIAN.getLanguage()));
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (getSession().getLocale().getLanguage().equals(Locales.ITALIAN.getLanguage())) {
                tag.getAttributes().put("class", "selected");
            }
        }
    };
    add(goItalian);

    Link<String> goEnglish = new Link<String>("goEnglish") {
        @Override
        public void onClick() {
            getSession().setLocale(Locales.ENGLISH);
            getWebRequestCycle().getWebResponse()
                    .addCookie(new Cookie(CookieUtil.LANGUAGE, Locales.ENGLISH.getLanguage()));
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (getSession().getLocale().getLanguage().equals(Locales.ENGLISH.getLanguage())) {
                tag.getAttributes().put("class", "selected");
            }
        }
    };
    add(goEnglish);

    Link<String> goDutch = new Link<String>("goDutch") {
        @Override
        public void onClick() {
            getWebRequestCycle().getWebResponse()
                    .addCookie(new Cookie(CookieUtil.LANGUAGE, Locales.DUTCH.getLanguage()));
            getSession().setLocale(Locales.DUTCH);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (getSession().getLocale().getLanguage().equals(Locales.DUTCH.getLanguage())) {
                tag.getAttributes().put("class", "selected");
            }
        }
    };
    add(goDutch);

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

        @Override
        public void onClick() {
            setResponsePage(SignOut.class);
        }
    };

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

        @Override
        public void onClick() {
            setResponsePage(SignIn.class);
        }
    };

    goSignIn.setOutputMarkupId(true);
    goSignOut.setOutputMarkupId(true);

    if (isAuthenticated) {
        goSignIn.setVisible(false);
        goSignOut.setVisible(true);
    } else {
        goSignOut.setVisible(false);
        goSignIn.setVisible(true);
    }
    add(goSignOut);
    add(goSignIn);

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

        @Override
        public void onClick() {
            Eater eater = getLoggedInUser();
            if (eater != null) {
                PageParameters pp = new PageParameters(YoueatHttpParams.PARAM_YOUEAT_ID + "=" + eater.getId());
                setResponsePage(UserAccountPage.class, pp);
            }
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            setVisible((getApplication().getSecuritySettings().getAuthorizationStrategy()
                    .isInstantiationAuthorized(UserAccountPage.class)));
        }

        @Override
        protected boolean callOnBeforeRenderIfNotVisible() {
            return true;
        }
    };
    add(goAccount);

}

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

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 * //ww  w  .j a va2s .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.eatt.web.page.SignIn.java

License:Apache License

/**
 * Constructor/*from  w ww  .  j  a v a  2 s. co  m*/
 */
public SignIn() {
    add(CSSPackageResource.getHeaderContribution(STYLES_CSS));
    ResourceReference img = new ResourceReference(this.getClass(), "resources/images/logo-mela.png");
    add(new Image("logo", img));
    getSession().setLocale(new Locale("en", "US"));
    add(new AjaxLink<String>("signUp") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            setResponsePage(SignUpPage.class);
        }
    });
}

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 .  ja va2s. c om*/
 * @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));
}

From source file:jp.gihyo.wicket.page.ajax.AjaxTimeline.java

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);/*from   w w w . java2s.  c  o  m*/

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() {
        @Override
        protected List<Status> load() {
            try {
                Twitter twitter = AppSession.get().getTwitterSession();
                return twitter.getFriendsTimeline(new Paging(currentPageNumber, ITEMS_PER_PAGE));
            } catch (TwitterException ex) {
                AjaxTimeline.this.error(getString("canNotRetrieveFriendTimeline"));
                return Collections.emptyList();
            }
        }
    };

    ListView<Status> timeline = new ListView<Status>("statusView", statusModel) {
        @Override
        protected void populateItem(final ListItem<Status> item) {
            final Status status = item.getModelObject();
            String userUrl = "http://twitter.com/" + status.getUser().getScreenName();
            ExternalLink imageLink = new ExternalLink("imageLink", userUrl);

            //ImageR|?[lg?A<img>^Osrc??X`?X
            WebMarkupContainer userImage = new WebMarkupContainer("userImage");
            userImage.add(new SimpleAttributeModifier("src", status.getUser().getProfileImageURL().toString()));

            imageLink.add(userImage);
            item.add(imageLink);

            ExternalLink screenNameLink = new ExternalLink("screenName", userUrl,
                    status.getUser().getScreenName());
            item.add(screenNameLink);

            Label content = new Label("tweetContent", status.getText());
            item.add(content);

            ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null);
            item.add(tweetLink);

            Label time = new Label("tweetTime",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt()));
            tweetLink.add(time);

            Label clientName = new Label("clientName", status.getSource());
            item.add(clientName.setEscapeModelStrings(false));

            /*
             * YXe?[^XCo^\xNX?B
             * ?\bh?A??[JNX`?B
             * ??[JNX?ANXOstatus?ANZX?B
             */
            class FavorateLabel extends Label {
                private static final long serialVersionUID = -2194580825236126312L;
                private Status targetStatus;
                private boolean needRefresh;

                public FavorateLabel(String id) {
                    super(id);
                    this.targetStatus = status;

                    setDefaultModel(new AbstractReadOnlyModel<String>() {
                        @Override
                        public String getObject() {
                            try {
                                if (needRefresh) {
                                    targetStatus = getCurrentStatus(status.getId());
                                    needRefresh = false;
                                }
                                return targetStatus == null ? "" : targetStatus.isFavorited() ? "unfav" : "fav";
                            } catch (TwitterException ex) {
                                LOGGER.error("Can not fetch current status for status id = " + status.getId(),
                                        ex);
                                return "error";
                            }
                        }
                    });
                }

                public void setNeedRefresh(boolean needRefresh) {
                    this.needRefresh = needRefresh;
                }
            }

            //CNx
            final FavorateLabel favName = new FavorateLabel("favName");
            favName.setOutputMarkupId(true);

            /*
             * AjaxCN?B
             * Xe?[^XCo^o^?Ao^???s?B
             * o^???AAjaxg?Ay?[WS?ACo^Xe?[^X
             * Nx??B
             */
            AjaxLink<Void> favLink = new AjaxLink<Void>("favLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    try {
                        Status currentStatus = getCurrentStatus(status.getId());
                        Twitter twitterSession = AppSession.get().getTwitterSession();
                        if (currentStatus.isFavorited()) {
                            twitterSession.destroyFavorite(currentStatus.getId());
                            info(getString("favorateRemoved"));
                        } else {
                            twitterSession.createFavorite(currentStatus.getId());
                            info(getString("favorateRegistered"));
                        }
                        favName.setNeedRefresh(true);
                        target.addComponent(feedback); //o^?bZ?[W\?AtB?[hobNpl?X?V?B
                        target.addComponent(favName);
                    } catch (TwitterException ex) {
                        String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode();
                        error(message);
                        LOGGER.error(message, ex);
                    }
                }
            };
            item.add(favLink);
            favLink.add(favName);

            //AJAX LINK
            item.add(new AjaxLink<Void>("replyLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    String targetScreenName = status.getUser().getScreenName();
                    form.insertText(target, "@" + targetScreenName + " ");
                }
            });

            //Q?l?AreplyLinkJavaScriptp
            //                item.add(new Link<Void>("replyLink") {
            //                    @Override
            //                    public void onClick() {
            //                    }
            //
            //                    @Override
            //                    protected CharSequence getOnClickScript(CharSequence url) {
            //                        return "getElementById('" + form.getTextAreaId() + "').value = '@" + status.getUser().getScreenName() + " ';" +
            //                               "getElementById('" + form.getTextAreaId() + "').focus(); return false;";
            //                    }
            //                });
        }
    };

    //ListView\e?s????BreuseItemsv?peB??A
    //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B
    //twitterey?[We?X??AXg????AXge?
    //Xe?[^Xu?A??dv?B
    timeline.setReuseItems(true);
    add(timeline);

    /*
     * y?[WO?EirQ?[^
     */
    add(new PagingLink("paging", AjaxTimeline.class, new AbstractReadOnlyModel<Integer>() {
        @Override
        public Integer getObject() {
            return getCurrentPage();
        }
    }));
}

From source file:jp.go.nict.langrid.management.web.view.page.error.ErrorInternalPage.java

License:Open Source License

/**
 * //  w w  w  .  ja  v  a  2 s . c  o  m
 * 
 */
public ErrorInternalPage(ServiceManagerException e) {
    e.printStackTrace();
    Label title = new Label("errorTitle", e.getErrorCode() + " : "
            + MessageManager.getMessage("message.error." + e.getErrorCode(), getLocale()));
    add(title);
    Label message = new Label("errorMessage",
            MessageManager.getMessage("message.error." + e.getErrorCode() + ".Navigation", getLocale()));
    message.setEscapeModelStrings(false);
    add(message);
    AjaxLink link = new AjaxLink("stackTraceTitle") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            container.setVisible(!container.isVisible());
            target.addComponent(container);
        }

        @Override
        protected boolean getStatelessHint() {
            return true;
        }
    };
    link.add(new Label("linkLabel", "Error description - " + e.getRaisedDate()));
    add(link);
    Throwable th = e;
    RepeatingView repeater = new RepeatingView("repeat");
    do {
        StringBuffer errorSb = new StringBuffer();
        //         if(th instanceof LangridException){
        //            LangridException le = (LangridException)th;
        //            errorSb.append("-");
        //            errorSb.append(le.getClass().getName());
        //            errorSb.append(": ");
        //            errorSb.append(le.getErrorString() == null ? "" : le.getErrorString());
        //            errorSb.append(" [");
        //            errorSb.append(le.getServiceUrl());
        //            errorSb.append("#");
        //            errorSb.append(le.getOperationName());
        //            errorSb.append("]");
        //         }else{
        errorSb.append("-");
        errorSb.append(th.getClass().getName());
        errorSb.append(": ");
        errorSb.append(th.getMessage() == null ? "" : th.getMessage());
        //         }
        errorSb.append("<br/>");
        for (StackTraceElement trace : th.getStackTrace()) {
            errorSb.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            errorSb.append(trace.getClassName());
            errorSb.append("(");
            errorSb.append(trace.getMethodName());
            errorSb.append(":");
            errorSb.append(trace.getLineNumber());
            errorSb.append(")");
            errorSb.append("<br/>");
        }
        Label stacktrace = new Label(repeater.newChildId(), new Model<String>(errorSb.toString()));
        repeater.add(stacktrace.setEscapeModelStrings(false));
    } while ((th = th.getCause()) != null);
    container = new WebMarkupContainer("stacktrace");
    container.setOutputMarkupId(true);
    container.setOutputMarkupPlaceholderTag(true);
    container.setVisible(false);
    container.add(repeater);
    add(container);
}

From source file:jp.go.nict.langrid.management.web.view.page.error.PopupErrorInternalPage.java

License:Open Source License

/**
 * /*  www. j  a v  a 2  s . c  o m*/
 * 
 */
public PopupErrorInternalPage(ServiceManagerException e) {
    add(new Label("ServiceManagerCopyright", MessageUtil.getServiceManagerCopyright())
            .setEscapeModelStrings(false));
    Label title = new Label("errorTitle", e.getErrorCode() + " : "
            + MessageManager.getMessage("message.error." + e.getErrorCode(), getLocale()));
    add(title);
    // ?
    Label message = new Label("errorMessage",
            MessageManager.getMessage("message.error." + e.getErrorCode() + ".Navigation", getLocale()));
    message.setEscapeModelStrings(false);
    add(message);
    AjaxLink link = new AjaxLink("stackTraceTitle") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            container.setVisible(!container.isVisible());
            target.addComponent(container);
        }

        private static final long serialVersionUID = 1L;
    };
    link.add(new Label("linkLabel", "Error description - " + e.getRaisedDate()));
    add(link);

    Throwable th = e;
    RepeatingView repeater = new RepeatingView("repeat");
    do {
        StringBuffer errorSb = new StringBuffer();
        //         if(th instanceof LangridException){
        //            LangridException le = (LangridException)th;
        //            errorSb.append("-");
        //            errorSb.append(le.getClass().getName());
        //            errorSb.append(": ");
        //            errorSb.append(le.getErrorString() == null ? "" : le.getErrorString());
        //            errorSb.append(" [");
        //            errorSb.append(le.getServiceUrl());
        //            errorSb.append("#");
        //            errorSb.append(le.getOperationName());
        //            errorSb.append("]");
        //         }else{
        errorSb.append("-");
        errorSb.append(th.getClass().getName());
        errorSb.append(": ");
        errorSb.append(th.getMessage() == null ? "" : th.getMessage());
        //         }
        errorSb.append("<br/>");
        for (StackTraceElement trace : th.getStackTrace()) {
            errorSb.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            errorSb.append(trace.getClassName());
            errorSb.append("(");
            errorSb.append(trace.getMethodName());
            errorSb.append(":");
            errorSb.append(trace.getLineNumber());
            errorSb.append(")");
            errorSb.append("<br/>");
        }
        Label stacktrace = new Label(repeater.newChildId(), new Model<String>(errorSb.toString()));
        repeater.add(stacktrace.setEscapeModelStrings(false));
    } while ((th = th.getCause()) != null);
    container = new WebMarkupContainer("stacktrace");
    container.setOutputMarkupId(true);
    container.setOutputMarkupPlaceholderTag(true);
    container.setVisible(false);
    container.add(repeater);
    add(container);
}

From source file:jp.javelindev.snippet.ExpireAjaxPage.java

License:Apache License

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

    LOGGER.debug("PAGE CREATION.");

    final Label contentLabel = new Label("contentLabel", new PropertyModel<String>(this, "content"));
    contentLabel.setOutputMarkupId(true);
    add(contentLabel);//  www.  j  a v  a 2  s.com

    add(new AjaxLink<Void>("ajaxButton") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            LOGGER.debug("CLICKED.");
            content = "??";
            target.addComponent(contentLabel);
        }
    });
}

From source file:jp.javelindev.wicket.ajaxlist.AjaxListPage.java

License:Apache License

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

    final RepeatingView view = new RepeatingView("item");
    add(view);/*from   w w  w.j  a  v  a 2 s .co  m*/

    Label defaultLabel = new Label(view.newChildId(), "test");
    defaultLabel.setOutputMarkupId(true);
    view.add(defaultLabel);

    add(new AjaxLink<Void>("addNew") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Label newLabel = new Label(view.newChildId(), new SimpleDateFormat("HH:mm:ss").format(new Date()));
            newLabel.setOutputMarkupId(true);
            view.add(newLabel);

            Response bodyResonse = new StringResponse();
            Response originalResponse = getResponse();

            getRequestCycle().setResponse(bodyResonse);
            newLabel.render();
            String componentString = bodyResonse.toString();
            LOGGER.info("label: {}", componentString);
            getRequestCycle().setResponse(originalResponse);

            target.appendJavaScript("$('#viewContainer').append('" + componentString + "')");
        }
    });

    add(new HeaderResponseFilteredResponseContainer("footerJS", "footerJS"));
}