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:jp.xet.uncommons.wicket.behavior.FocusOnLoadBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {
    component.setOutputMarkupId(true);//from   ww  w.  ja va 2s. com

    // last semicolon is not required
    String js = String.format("document.getElementById('%s').focus()", component.getMarkupId());
    response.renderOnLoadJavaScript(js);
}

From source file:main.java.info.jtrac.wicket.ItemSearchFormPanel.java

License:Apache License

private void addComponents() {
    final Form form = new Form("form");
    add(form);/*w  w w.ja va 2 s. c o m*/
    form.add(new FeedbackPanel("feedback"));
    form.setModel(new CompoundPropertyModel(itemSearch));
    List<Integer> sizes = Arrays.asList(new Integer[] { 5, 10, 15, 25, 50, 100, -1 });
    DropDownChoice pageSizeChoice = new DropDownChoice("pageSize", sizes, new IChoiceRenderer() {
        public Object getDisplayValue(Object o) {
            return ((Integer) o) == -1 ? localize("item_search_form.noLimit") : o.toString();
        }

        public String getIdValue(Object o, int i) {
            return o.toString();
        }
    });
    form.add(pageSizeChoice);
    form.add(new CheckBox("showHistory"));
    form.add(new Button("search") {
        @Override
        public void onSubmit() {
            String refId = itemSearch.getRefId();
            if (refId != null) {
                if (getCurrentSpace() != null) {
                    // user can save typing by entering the refId number without the space prefixCode
                    try {
                        long id = Long.parseLong(refId);
                        refId = getCurrentSpace().getPrefixCode() + "-" + id;
                    } catch (Exception e) {
                        // oops that didn't work, continue
                    }
                }
                try {
                    new ItemRefId(refId);
                } catch (InvalidRefIdException e) {
                    form.error(localize("item_search_form.error.refId.invalid"));
                    return;
                }
                Item item = getJtrac().loadItemByRefId(refId);
                if (item == null) {
                    form.error(localize("item_search_form.error.refId.notFound"));
                    return;
                }
                setCurrentItemSearch(itemSearch);
                setResponsePage(ItemViewPage.class, new PageParameters("0=" + item.getRefId()));
                return;
            }
            String searchText = itemSearch.getSearchText();
            if (searchText != null) {
                if (!getJtrac().validateTextSearchQuery(searchText)) {
                    form.error(localize("item_search_form.error.summary.invalid"));
                    return;
                }
            }
            setCurrentItemSearch(itemSearch);
            setResponsePage(ItemListPage.class);
        }
    });
    form.add(new Link("expandAll") {
        public void onClick() {
            expandAll = true;
        }

        @Override
        public boolean isVisible() {
            return !expandAll;
        }
    });
    form.add(new ListView("columns", itemSearch.getColumnHeadings()) {
        protected void populateItem(final ListItem listItem) {
            final ColumnHeading ch = (ColumnHeading) listItem.getModelObject();
            String label = ch.isField() ? ch.getLabel() : localize("item_list." + ch.getName());
            listItem.add(new Label("columnName", label));
            listItem.add(new CheckBox("visible", new PropertyModel(ch, "visible")));
            List<Expression> validExpressions = ch.getValidFilterExpressions();
            DropDownChoice expressionChoice = new IndicatingDropDownChoice("expression", validExpressions,
                    new IChoiceRenderer() {
                        public Object getDisplayValue(Object o) {
                            String key = ((Expression) o).getKey();
                            return localize("item_filter." + key);
                        }

                        public String getIdValue(Object o, int i) {
                            return ((Expression) o).getKey();
                        }
                    });
            if (ch.getName().equals(ColumnHeading.ID)) {
                ch.getFilterCriteria().setExpression(Expression.EQ);
            }
            Component fragParent = null;
            if (expandAll) {
                ch.getFilterCriteria().setExpression(validExpressions.get(0));
                fragParent = ch.getFilterUiFragment(ItemSearchFormPanel.this);
            } else {
                fragParent = getFilterUiFragment(ch);
            }
            fragParent.setOutputMarkupId(true);
            listItem.add(fragParent);
            expressionChoice.setModel(new PropertyModel(ch.getFilterCriteria(), "expression"));
            expressionChoice.setNullValid(true);
            listItem.add(expressionChoice);
            expressionChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
                protected void onUpdate(AjaxRequestTarget target) {
                    if (!ch.getFilterCriteria().requiresUiFragmentUpdate()) {
                        return;
                    }
                    Component fragment = getFilterUiFragment(ch);
                    fragment.setOutputMarkupId(true);
                    listItem.replace(fragment);
                    target.addComponent(fragment);
                    target.appendJavascript(
                            "document.getElementById('" + fragment.getMarkupId() + "').focus()");
                }
            });
        }
    });
}

From source file:name.martingeisse.wicket.component.codemirror.CodeMirrorBehavior.java

License:Open Source License

@Override
public void renderHead(Component component, IHeaderResponse response) {
    response.render(//w w  w.  j a v  a2s .co  m
            CssHeaderItem.forReference(new CssResourceReference(CodeMirrorBehavior.class, "codemirror.css")));
    response.render(JavaScriptHeaderItem
            .forReference(new JavaScriptResourceReference(CodeMirrorBehavior.class, "codemirror.js")));
    WicketHeadUtil.includeClassJavascript(response, CodeMirrorBehavior.class);
    mode.renderResourceReferences(response);
    renderInitializerForTextArea(component, response);

    String script = "var q = $('#" + component.getMarkupId() + "'); \n"
            + "q.parents('.collapse').on('shown.bs.collapse', function(e) {q.data('codeMirrorInstance').refresh(); });";
    response.render(OnDomReadyHeaderItem.forScript(script));
}

From source file:name.martingeisse.wicket.component.codemirror.CodeMirrorBehavior.java

License:Open Source License

/**
 * Renders a Javascript fragment to the specified header response that initializes CodeMirror in this mode for the specified text area.
 * //w ww  .  j  a v  a2s  .c o  m
 * @param textArea the text area that shall be using CodeMirror
 * @param response the response to render to
 */
private void renderInitializerForTextArea(Component textArea, IHeaderResponse response) {
    StringBuilder builder = new StringBuilder();
    builder.append("var q = $('#").append(textArea.getMarkupId()).append("'); \n");
    builder.append("var codeMirror = q.createCodeMirrorForTextArea(");
    mode.renderModeParameter(builder);
    builder.append(", ");
    renderOptionsArgument(builder);
    builder.append("); \n");
    builder.append("q.data('codeMirrorInstance', codeMirror); ");
    response.render(OnDomReadyHeaderItem.forScript(builder.toString()));
}

From source file:name.martingeisse.wicket.component.misc.ExpandableRepeater.java

License:Open Source License

/**
 * @param item the rendered item//from   ww  w.  j  a v  a2  s. co  m
 */
protected final void notifyAboutPrototypeItem(final Component item) {
    final ComponentTag componentTag = (ComponentTag) item.getMarkup().get(0);
    notifyAboutPrototypeItem(componentTag.getName(), item.getMarkupId());
}

From source file:name.martingeisse.wicket.component.select.SelectableElementsBehavior.java

License:Open Source License

@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    super.renderHead(component, response);
    WicketHeadUtil.includeClassJavascript(response, SelectableElementsBehavior.class);

    final CallbackParameter[] parameters = new CallbackParameter[] { CallbackParameter.explicit("interaction"),
            CallbackParameter.explicit("selectedValues"), CallbackParameter.explicit("data"), };

    final StringBuilder builder = new StringBuilder();
    builder.append("\t$('#").append(component.getMarkupId()).append("').selectableElements({\n");
    builder.append("\t\telementSelector: '" + elementSelector + "',\n");
    builder.append("\t\tvalueExtractor: function(element) {return " + valueExpression + ";},\n");
    builder.append("\t\tajaxCallback: ").append(getCallbackFunction(parameters).toString().replace("\n", " "))
            .append(",");
    builder.append("\t\tnotSelectedStyle: {'background-color': ''},\n");
    builder.append("\t\tselectedStyle: {'background-color': '#f00'},\n");
    builder.append("\t\tcontextMenuData: ");
    if (contextMenu != null) {
        ContextMenu.renderHead(response);
        contextMenu.buildCreateExpression(builder, "#" + component.getMarkupId(), this);
    } else {//ww w. j a  v  a 2 s .  co  m
        builder.append("null");
    }
    builder.append(",\n");
    builder.append("\t});\n");

    final AjaxRequestTarget target = component.getRequestCycle().find(AjaxRequestTarget.class);
    if (target == null) {
        response.render(OnDomReadyHeaderItem.forScript(builder.toString()));
    } else {
        target.appendJavaScript(builder);
    }

}

From source file:net.dontdrinkandroot.extensions.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(/*from www . ja v  a2s  . com*/
            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.extensions.wicket.behavior.ScrollToBottomBehavior.java

License:Apache License

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

    String componentSelector;//from  w  ww  . j  a  va2s. co  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.extensions.wicket.component.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 . ja  v  a2 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.extensions.wicket.jqueryui.SortableBehavior.java

License:Apache License

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

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

    String containment = "";
    final Component containmentComponent = this.getContainment();
    if (containmentComponent != null) {
        containment = "#" + containmentComponent.getMarkupId();
    }/*from  w  ww.ja va 2 s  . co  m*/

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

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

        @Override
        public List<HeaderItem> getDependencies() {
            return Collections.singletonList(SortableBehavior.this.getJQueryUiHeaderItem());
        }
    };

    String handle = this.getHandle();
    handle = handle == null ? "false" : "'" + handle + "'";
    final OnDomReadyHeaderItem initHeaderItem = new OnDomReadyHeaderItem(
            String.format("initSortable('%s', %s, '%s', '%s', '%s', '%s', %s)", component.getMarkupId(),
                    callbackFunction, component.getPageRelativePath(), this.itemSelector,
                    this.getPlaceHolderClass(), containment, handle)) {

        @Override
        public List<HeaderItem> getDependencies() {
            return Collections.singletonList((HeaderItem) sortableHeaderItem);
        }
    };

    response.render(initHeaderItem);
}