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:org.efaps.ui.wicket.behaviors.dojo.LazyIframeBehavior.java

License:Apache License

/**
 * Render the links for the head./* www  .j av  a  2s  . c o  m*/
 *
 * @param _component component the header will be rendered for
 * @param _response resonse to add
 */
@Override
public void renderHead(final Component _component, final IHeaderResponse _response) {
    super.renderHead(_component, _response);
    final StringBuilder js = new StringBuilder()
            .append("require([\"dojo/ready\",\"dijit/registry\",\"dojo/dom-construct\"],")
            .append(" function(ready, registry, domConstruct) {").append("ready(function() {")
            .append("registry.byId(\"").append(_component.getMarkupId())
            .append("\").set(\"content\", domConstruct.create(\"iframe\", {");

    if (this.frameMarkupId != null) {
        js.append("\"id\": \"").append(this.frameMarkupId).append("\",");
    }

    js.append("\"src\": \"").append(_component.urlFor(ILinkListener.INTERFACE, new PageParameters()))
            .append("\",\"style\": \"border: 0; width: 100%; height: 99%\", \"nodeId\": \"jan\"").append("}));")
            .append("});});");
    _response.render(JavaScriptHeaderItem.forScript(js, _component.getMarkupId()));
}

From source file:org.hippoecm.addon.workflow.WorkflowManagerPluginTest.java

License:Apache License

@Test
public void workflowCategoryIsUsedAsMenu() {
    final JavaPluginConfig config = new JavaPluginConfig();
    config.put("wicket.id", "service.root");
    config.put("workflow.categories", new String[] { "plugin-test" });

    TestWorkflowManagerPlugin manager = new TestWorkflowManagerPlugin(context, config);
    manager.setModel(new JcrNodeModel("/test/folder/doc"));
    tester.startPage(home);// w  w w .j  a v  a 2 s .  c  o m

    TestWorkflowPlugin plugin = context.getService("workflow.plugin", TestWorkflowPlugin.class);
    assertEquals("plugin-test", plugin.getCategory());

    Component button = tester.getComponentFromLastRenderedPage("root:menu:list:0:item:link");
    final TagTester tagTester = tester.getTagById(button.getMarkupId());
    assertTrue(tagTester.getValue().contains("plugin-test"));
}

From source file:org.hippoecm.frontend.behaviors.OnEnterAjaxBehavior.java

License:Apache License

/**
 * Don't call super since WicketAjax is loaded by Yui webapp behavior
 * TODO: webapp ajax is configurable, maybe check here and still load it.
 *//*w  w w .j  a va 2 s .c o m*/
@Override
public final void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);

    if (_helper == null) {
        Page page = component.getPage();
        for (Behavior behavior : page.getBehaviors()) {
            if (behavior instanceof IYuiManager) {
                _helper = ((IYuiManager) behavior).newContext();
                _helper.addJavascriptReference(
                        new JavaScriptResourceReference(OnEnterAjaxBehavior.class, "enter.js"));
                break;
            }
        }
        if (_helper == null) {
            throw new IllegalStateException(
                    "Page has no yui manager behavior, unable to register module dependencies.");
        }
        _helper.addOnDomLoad("new Hippo.EnterHandler('" + component.getMarkupId() + "')");
    }
    _helper.renderHead(response);
}

From source file:org.hippoecm.frontend.plugins.cms.admin.widgets.DefaultFocusBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {
    response.render(OnDomReadyHeaderItem
            .forScript("document.getElementById('" + component.getMarkupId() + "').focus();"));
}

From source file:org.hippoecm.frontend.plugins.jquery.upload.FileUploadBehavior.java

License:Apache License

/**
 * Set parameters that will be used in the jquery-fileupload initialization. See jquery.fileupload.js/options
 *//*w  w  w  .  j ava 2  s. c om*/
protected Map<String, Object> configureParameters(final Component component) {
    Map<String, Object> variables = new HashMap<>();

    variables.put("componentMarkupId", component.getMarkupId());

    // the url to receive file upload
    variables.put("url", settings.getUploadUrl());

    variables.put("maxTotalFiles", settings.getMaxNumberOfFiles());

    // disable client-side file extension validation, accepted any files
    String acceptFileTypes = REGEX_ANYFILE;
    variables.put("acceptFileTypes", acceptFileTypes);

    // Get settings to configure the file upload widget
    variables.put(FileUploadWidgetSettings.MAX_WIDTH_PROP, settings.getMaxWidth());
    variables.put(FileUploadWidgetSettings.MAX_HEIGHT_PROP, settings.getMaxHeight());
    variables.put(FileUploadWidgetSettings.MAX_FILESIZE_PROP, settings.getMaxFileSize());
    variables.put(FileUploadWidgetSettings.AUTOUPLOAD_PROP, settings.isAutoUpload());
    return variables;
}

From source file:org.hippoecm.frontend.plugins.yui.layout.WireframeBehavior.java

License:Apache License

@Override
protected void onRenderHead(final IHeaderResponse response) {
    if (isRendered()) {
        return;//w  ww.ja va2  s .co m
    }

    final String markupId = getComponent().getMarkupId(true);

    updateAjaxSettings();

    settings.setMarkupId(markupId);

    IWireframe parentWireframe = getParentWireframe();
    if (parentWireframe != null) {
        settings.setParentId(parentWireframe.getYuiId());
    }

    //Visit child components in order to find components that contain a {@link UnitBehavior}. If another wireframe
    //or unit is encountered, stop going deeper.
    MarkupContainer cont = (MarkupContainer) getComponent();
    cont.visitChildren(new IVisitor<Component, Void>() {
        public void component(Component component, IVisit<Void> visit) {
            for (Object behavior : component.getBehaviors()) {
                if (behavior instanceof IWireframe) {
                    visit.dontGoDeeper();
                } else if (behavior instanceof UnitBehavior) {
                    String position = ((UnitBehavior) behavior).getPosition();
                    UnitSettings unit = settings.getUnit(position);
                    if (unit != null) {
                        YuiId body = unit.getBody();
                        if (body != null) {
                            body.setParentId(null);
                            body.setId(component.getMarkupId());
                        }
                    } else {
                        throw new RuntimeException("Invalid UnitBehavior position " + position);
                    }
                    visit.dontGoDeeper();
                }
            }
        }
    });

    rendered = true;

    response.render(getHeaderItem());
}

From source file:org.hippoecm.frontend.plugins.yui.rightclick.RightClickBehavior.java

License:Apache License

/**
 * Set up a YUI 'contextmenu' event listener on the component. The callback function is parameterized with the x&y
 * coordinates of the click event. Also stop the contextmenu event from propagating to prevent the browser's
 * contextmenu from rendering./*  w  w  w .  java 2 s .c  om*/
 */
@Override
public void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);

    String attributesAsJson = renderAjaxAttributes(component).toString();
    String addEvent = "YAHOO.util.Event.addListener('" + component.getMarkupId() + "','contextmenu', "
            + "function(env) {\n" + "  var x = YAHOO.util.Event.getPageX(env),\n"
            + "      y = YAHOO.util.Event.getPageY(env),\n" + "      call = new Wicket.Ajax.Call(),\n"
            + "      attributes = jQuery.extend({}, " + attributesAsJson + ");\n"
            + "  YAHOO.util.Event.stopEvent(env);\n" + "  call.ajax(attributes);\n" + "});";
    response.render(OnDomReadyHeaderItem.forScript(addEvent));
}

From source file:org.hippoecm.frontend.plugins.yui.scrollbehavior.ScrollBehavior.java

License:Apache License

public void bind(Component component) {
    parameters.put("id", component.getMarkupId());
    parameters.put("filterName", WebApplication.get().getWicketFilter().getFilterConfig().getFilterName());
}

From source file:org.hippoecm.frontend.widgets.AutoFocusSelectTextFieldWidget.java

License:Apache License

/**
 * Add javascript to set focus to the component returned by {@code #getFocusComponent} 
 * and select the text when dialog is rendered.
 *
 * @param response header response// w w w.j  av  a 2s .co  m
 */
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    final Component field = getFocusComponent();
    String script = "document.getElementById('" + field.getMarkupId() + "').focus(); "
            + "document.getElementById('" + field.getMarkupId() + "').select();";
    response.render(OnDomReadyHeaderItem.forScript(script));
}

From source file:org.jaulp.wicket.behaviors.FocusRequestBehavior.java

License:Apache License

/**
 * Creates the java script code for request focus.
 *
 * @param component//  ww  w .j  a v  a2 s  . c o m
 *            the component
 * @return the string
 */
private String createJavaScript(Component component) {
    StringBuilder sb = new StringBuilder();
    sb.append("setTimeout(" + "function() {" + "var component = document.getElementById(\"")
            .append(component.getMarkupId()).append("\");");
    if (clearValue) {
        sb.append("component.value = \"\";");
    }
    sb.append("component.focus();");
    sb.append("component.select();");
    sb.append("}, 1)");
    return sb.toString();
}