Example usage for org.apache.wicket Component getMarkupId

List of usage examples for org.apache.wicket Component getMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket Component getMarkupId.

Prototype

public String getMarkupId() 

Source Link

Document

Retrieves id by which this component is represented within the markup.

Usage

From source file:net.dontdrinkandroot.wicket.behavior.ajax.ScrollToBottomBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {

    super.renderHead(component, response);

    String componentSelector;//from   w w w .  j  a  v a  2  s  . c o  m
    if (component instanceof Page) {
        componentSelector = "window";
    } else {
        componentSelector = String.format("'#%s'", component.getMarkupId());
    }

    StringBuffer scriptBuffer = new StringBuffer();
    scriptBuffer.append(String.format("var %s = true;", this.getActiveVarName(component)));
    scriptBuffer.append(String.format("$(%s).scroll(function () {", componentSelector));
    scriptBuffer.append(
            String.format("if (%s && $(%s).scrollTop() >= $(document).height() - $(%s).height() - %d) {",
                    this.getActiveVarName(component), componentSelector, componentSelector, this.offset));
    scriptBuffer.append(String.format("%s = false;", this.getActiveVarName(component)));
    scriptBuffer.append(this.getCallbackScript());
    scriptBuffer.append("}");
    scriptBuffer.append("});");

    response.render(JavaScriptHeaderItem.forScript(scriptBuffer, "scrollToBottom"));
}

From source file:net.dontdrinkandroot.wicket.behavior.jqueryui.SortableBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {

    super.renderHead(component, response);

    CharSequence callbackFunction = this.getCallbackFunction(CallbackParameter.explicit("oldPosition"),
            CallbackParameter.explicit("newPosition"), CallbackParameter.explicit("out"),
            CallbackParameter.explicit("componentPath"));

    String containment = "";
    Component containmentComponent = this.getContainment();
    if (containmentComponent != null) {
        containment = "#" + containmentComponent.getMarkupId();
    }/*from   w  w w  . ja v  a  2  s .  c om*/

    PackageResourceReference sortableResourceReference = new PackageResourceReference(SortableBehavior.class,
            "sortable.js");

    final JavaScriptReferenceHeaderItem sortableHeaderItem = new JavaScriptReferenceHeaderItem(
            sortableResourceReference, null, "jqueryui.sortable", false, null, null) {

        @Override
        public Iterable<? extends HeaderItem> getDependencies() {

            return Collections.singletonList(new ExternalJQueryUiJsHeaderItem(false));
        }
    };

    OnDomReadyHeaderItem initHeaderItem = new OnDomReadyHeaderItem(String.format(
            "initSortable('%s', %s, '%s', '%s', '%s', '%s')", component.getMarkupId(), callbackFunction,
            component.getPageRelativePath(), this.itemSelector, this.getPlaceHolderClass(), containment)) {

        @Override
        public Iterable<? extends HeaderItem> getDependencies() {

            return Collections.singletonList(sortableHeaderItem);
        }
    };

    response.render(initHeaderItem);
}

From source file:net.dontdrinkandroot.wicket.behavior.PageHeightScalingBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {

    super.renderHead(component, response);

    StringBuffer scalingFunctionBuffer = new StringBuffer();
    scalingFunctionBuffer.append(String.format("var offset = $('#%s').offset();", component.getMarkupId()));
    scalingFunctionBuffer.append(// w  ww  .java  2 s .  c  om
            String.format("$('#%s').height($(window).height() - offset.top);", component.getMarkupId()));

    response.render(OnDomReadyHeaderItem.forScript(scalingFunctionBuffer.toString()));
    response.render(OnDomReadyHeaderItem
            .forScript("$(window).resize(function() {" + scalingFunctionBuffer.toString() + "})"));
}

From source file:net.dontdrinkandroot.wicket.bootstrap.component.button.ButtonLink.java

License:Apache License

/**
 * Appends any anchor to the url if the url is not null and the url does not already contain an
 * anchor (url.indexOf('#') != -1). This implementation looks whether an anchor component was
 * set, and if so, it will append the markup id of that component. That markup id is gotten by
 * either calling {@link Component#getMarkupId()} if {@link Component#getOutputMarkupId()}
 * returns true, or if the anchor component does not output it's id, this method will try to
 * retrieve the id from the markup directly. If neither is found, an
 * {@link WicketRuntimeException exception} is thrown. If no anchor component was set, but the
 * link component is attached to a &lt;a element, this method will append what is in the href
 * attribute <i>if</i> there is one, starts with a '#' and has more than one character.
 * <p>//  w  w  w .  j av a 2s. com
 * You can override this method, but it means that you have to take care of whatever is done
 * with any set anchor component yourself. You also have to manually append the '#' at the right
 * place.
 * </p>
 * 
 * @param tag
 *            The component tag
 * @param url
 *            The url to start with
 * @return The url, possibly with an anchor appended
 */
protected CharSequence appendAnchor(final ComponentTag tag, CharSequence url) {

    if (url != null) {
        Component anchor = this.getAnchor();
        if (anchor != null) {
            if (url.toString().indexOf('#') == -1) {
                String id;
                if (anchor.getOutputMarkupId()) {
                    id = anchor.getMarkupId();
                } else {
                    id = anchor.getMarkupAttributes().getString("id");
                }

                if (id != null) {
                    url = url + "#" + anchor.getMarkupId();
                } else {
                    throw new WicketRuntimeException("an achor component was set on " + this
                            + " but it neither has outputMarkupId set to true "
                            + "nor has a id set explicitly");
                }
            }
        } else {
            if (tag.getName().equalsIgnoreCase("a")) {
                if (url.toString().indexOf('#') == -1) {
                    String href = tag.getAttributes().getString("href");
                    if (href != null && href.length() > 1 && href.charAt(0) == '#') {
                        url = url + href;
                    }
                }
            }
        }
    }
    return url;
}

From source file:net.dontdrinkandroot.wicket.component.repeater.AppendingDataView.java

License:Apache License

public void appendNewItems(AjaxRequestTarget target, Component parent) {

    Iterator<IModel<T>> models = this.getItemModels();
    Iterator<Item<T>> items = this.getItemReuseStrategy().getItems(this.newItemFactory(), models,
            this.getItems());

    int index = (int) this.getFirstItemOffset();
    while (items.hasNext()) {

        Item<T> item = items.next();
        item.setOutputMarkupId(true);/*w w  w .  j  av  a  2  s .c o  m*/
        item.setIndex(index);
        this.add(item);
        ++index;

        target.prependJavaScript(String.format(
                "var item = document.createElement('%s'); item.id = '%s'; Wicket.$('%s').appendChild(item);",
                this.itemTagName, item.getMarkupId(), parent.getMarkupId()));
        target.add(item);
    }
}

From source file:net.dontdrinkandroot.wicket.javascript.JQueryScript.java

License:Apache License

/**
 * Create a new JQuery Script using the components markupid as a selector. This will fail if the
 * markupid is not set, so always use {@link Component#setMarkupId(String)}.
 * /*from w w w  .  j av  a2 s . c o m*/
 * @param component
 *            The component to be selected.
 */
public JQueryScript(final Component component) {

    this.scriptBuffer = new StringBuffer("$('#" + component.getMarkupId() + "')");
}

From source file:net.kornr.swit.site.jquery.colorpicker.ColorPicker.java

License:Apache License

public static void renderHead(IHeaderResponse response, TextField<String> field, Component sample) {
    field.setOutputMarkupId(true);//from  w ww .j a va  2  s .c  o m
    String id = field.getMarkupId();

    String options = null;
    if (sample == null)
        options = "color: '#0000ff', onBeforeShow: function () { $(this).ColorPickerSetColor(this.value);}, onShow: function (colpkr) { $(colpkr).fadeIn(50); return false; },"
                + "onHide: function (colpkr) { $(colpkr).fadeOut(50); return false; },"
                + "onChange: function (hsb, hex, rgb) { $('#" + id + "').val(hex); $('#" + id
                + " ~ span.colorpickersample').css('backgroundColor', '#' + hex); $('#" + id
                + " ~ .colorpickersample').css('backgroundColor', '#' + hex); }";
    else
        options = "color: '#0000ff', onBeforeShow: function () { $(this).ColorPickerSetColor(this.value);}, onShow: function (colpkr) { $(colpkr).fadeIn(50); return false; },"
                + "onHide: function (colpkr) { $(colpkr).fadeOut(50); return false; },"
                + "onChange: function (hsb, hex, rgb) { $('#" + id + "').val(hex); $('#" + sample.getMarkupId()
                + "').css('backgroundColor', '#' + hex); }";

    response.renderJavascriptReference(JQuery.getReference());
    response.renderJavascriptReference(ColorPicker.getReference());
    response.renderCSSReference(new ResourceReference(ColorPicker.class, "css/colorpicker.css"));
    //      response.renderCSSReference(new ResourceReference(ColorPicker.class, "css/layout.css"));
    response.renderJavascript(JQuery.getOnReadyScript("$('#" + id + "').ColorPicker({ " + options + "});"),
            null);
}

From source file:nl.mpi.lamus.web.components.AutoHideDisablingAjaxButton.java

License:Open Source License

/**
 * @see IndicatingAjaxButton#updateAjaxAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes)
 *//*from w  ww  .j a v  a  2 s.c  om*/
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

    super.updateAjaxAttributes(attributes);

    attributes.getAjaxCallListeners().add(new IAjaxCallListener() {

        @Override
        public CharSequence getBeforeHandler(Component cmpnt) {
            return "$(\"#" + cmpnt.getMarkupId() + "\").hide()";
        }

        @Override
        public CharSequence getPrecondition(Component cmpnt) {
            return "";
        }

        @Override
        public CharSequence getBeforeSendHandler(Component cmpnt) {
            return "";
        }

        @Override
        public CharSequence getAfterHandler(Component cmpnt) {
            return "";
        }

        @Override
        public CharSequence getSuccessHandler(Component cmpnt) {
            return "";
        }

        @Override
        public CharSequence getFailureHandler(Component cmpnt) {
            return "";
        }

        @Override
        public CharSequence getCompleteHandler(Component cmpnt) {
            return "";
        }
    });
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void playCardFromHand(final AjaxRequestTarget target, final PlayCardFromHandCometChannel event) {
    final MagicCard mc = event.getMagicCard();

    Component me;

    if (event.getPlayerName().equals(this.session.getPlayer().getName())) {
        me = this.parentPlaceholder;
    } else {/*from ww  w  . j a  va2  s .c  om*/
        me = this.opponentParentPlaceholder;
    }

    me.add(new DisplayNoneBehavior());
    target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(500, notify);");

    BattlefieldService.updateCardsAndRestoreStateInBattlefield(target, this.persistenceService,
            event.getGameId(), mc, true);
    target.appendJavaScript(BattlefieldService.REACTIVATE_BATTLEFIELD_JAVASCRIPT);
    target.appendJavaScript(
            "jQuery('#" + me.getMarkupId() + "').fadeIn(500); jQuery('#cardInBattlefieldContextMenu"
                    + mc.getUuidObject().toString().replace("-", "_")
                    + "').popmenu({ 'background': 'black', 'focusColor': '#BBBBBB' }); ");
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void reorderCardsInBattlefield(final AjaxRequestTarget target, final ReorderCardCometChannel event) {
    HomePage.LOGGER.info("reorderCardsInBattlefield");

    final List<MagicCard> allCardsAndTokensInBattlefieldForAGameAndAPlayer = this.persistenceService
            .getAllCardsAndTokensInBattlefieldForAGameAndAPlayer(event.getGameId(), event.getPlayerId(),
                    event.getDeckId());//from   w w  w  .ja  va2 s  .co m

    HomePage.LOGGER.info("requesting side: " + event.getPlayerSide() + ", this side: "
            + this.session.getPlayer().getSide().getSideName());

    Component me;

    if (event.getPlayerSide().equals(this.session.getPlayer().getSide().getSideName())) {
        final WebMarkupContainer listViewForSide1 = this
                .generateCardListViewForSide1(allCardsAndTokensInBattlefieldForAGameAndAPlayer);
        me = this.parentPlaceholder;
        me.add(new DisplayNoneBehavior());
        target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(250, notify);");
        target.add(listViewForSide1);
    } else {
        final WebMarkupContainer listViewForSide2 = this
                .generateCardListViewForSide2(allCardsAndTokensInBattlefieldForAGameAndAPlayer);
        me = this.opponentParentPlaceholder;
        me.add(new DisplayNoneBehavior());
        target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(250, notify);");
        target.add(listViewForSide2);
    }

    BattlefieldService.updateCardsAndRestoreStateInBattlefield(target, this.persistenceService,
            event.getGameId(), null, false);

    target.appendJavaScript("jQuery('#" + me.getMarkupId()
            + "').fadeIn(250); jQuery('.cardInBattlefieldContextMenu').each(function(index, value) { jQuery(this).popmenu({ 'background': 'black', 'focusColor': '#BBBBBB' }); }); ");
}