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.obiba.onyx.marble.core.wicket.consent.ElectronicConsentPage.java

License:Open Source License

@SuppressWarnings("serial")
public ElectronicConsentPage(final Component finishButton) {

    pdfResource = new DynamicWebResource() {
        @Override//from   w  ww.  j  a v a2s . co m
        protected ResourceState getResourceState() {
            return new ResourceState() {
                @Override
                public String getContentType() {
                    return "application/pdf";
                }

                @Override
                public byte[] getData() {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    try {
                        Streams.copy(fdfProducer.getPdfTemplate(), baos);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    return baos.toByteArray();
                }
            };
        }

    };

    fdfResource = new DynamicWebResource() {
        @Override
        protected ResourceState getResourceState() {
            return new ResourceState() {
                byte[] fdf;

                @Override
                public String getContentType() {
                    return "application/vnd.fdf";
                }

                @Override
                synchronized public byte[] getData() {
                    if (fdf == null) {
                        String pdfUrl = RequestUtils
                                .toAbsolutePath(urlFor(IResourceListener.INTERFACE) + PDF_OPEN_PARAMETERS);
                        log.info("PDF URL is {}", pdfUrl);
                        PageParameters params = new PageParameters();
                        params.add("accepted", "true");
                        params.add("finishLinkId", finishButton.getMarkupId());
                        String acceptUrl = RequestUtils
                                .toAbsolutePath(urlFor(ElectronicConsentUploadPage.class, params).toString());

                        params = new PageParameters();
                        params.add("accepted", "false");
                        params.add("finishLinkId", finishButton.getMarkupId());
                        String refuseUrl = RequestUtils
                                .toAbsolutePath(urlFor(ElectronicConsentUploadPage.class, params).toString());
                        try {
                            fdf = fdfProducer.buildFdf(pdfUrl, acceptUrl, refuseUrl);
                        } catch (IOException e) {
                            fdf = null;
                            throw new RuntimeException(e);
                        }
                    }
                    return fdf;
                }
            };
        }
    };

    add(new FdfEmbedTag());
}

From source file:org.objetdirect.wickext.core.javascript.JsStatement.java

License:Open Source License

/**
 * Appends the jQuery's <code>$</code> function to the current {@link JsStatement}.
 * If context is not null, the generated JavaScript code will be:
 * <p>//from   ww w  . ja  v  a2s. c  o m
 *    <code>$("#component.getMarkupId selector")</code>
 * </p>
 * If context is null, the generated JavaScript code will be:
 * <p>
 *    <code>$("selector")</code>
 * </p>
 * @return {@link JsStatement} this instance.
 */
public JsStatement $(Component context, String selector) {
    String dollarSelector = context == null ? selector : ("#" + context.getMarkupId() + " " + selector);
    statement.append("$('");
    statement.append(dollarSelector);
    statement.append("')");
    return this;
}

From source file:org.objetdirect.wickext.core.javascript.JsStatement.java

License:Open Source License

/**
 * Same method as {@link #$(Component, String)} with an empty selector.
 * @return {@link JsStatement} this instance.
 *///from  w  ww . ja v a2 s  .c o  m
public JsStatement $(Component context) {
    String dollarSelector = context == null ? "" : ("'#" + context.getMarkupId() + "'");
    statement.append("$(");
    statement.append(dollarSelector);
    statement.append(")");
    return this;
}

From source file:org.odlabs.wiquery.core.javascript.JsStatement.java

License:Open Source License

/**
 * Same method as {@link #$(Component, String)} with an empty selector.
 * //from   w  w  w  .j ava  2 s.  co m
 * @return {@link JsStatement} this instance.
 */
public JsStatement $(Component context) {
    StringBuilder dollarSelector = new StringBuilder();
    if (context == null)
        dollarSelector.append("");
    else
        dollarSelector.append('#').append(context.getMarkupId());

    statement.append("$('");
    statement.append(dollarSelector);
    statement.append("')");
    return this;
}

From source file:org.odlabs.wiquery.core.javascript.JsStatement.java

License:Open Source License

/**
 * Appends the jQuery's <code>$</code> function to the current {@link JsStatement}. If
 * context is not null, the generated JavaScript code will be:
 * <p>/*from   w  w w.  j a  v  a 2  s .  com*/
 * <code>$("#component.getMarkupId selector")</code>
 * </p>
 * If context is null, the generated JavaScript code will be:
 * <p>
 * <code>$("selector")</code>
 * </p>
 * 
 * @return {@link JsStatement} this instance.
 */
public JsStatement $(Component context, String selector) {
    StringBuilder dollarSelector = new StringBuilder();
    if (context == null)
        dollarSelector.append(selector);
    else
        dollarSelector.append('#').append(context.getMarkupId()).append(' ').append(selector);

    statement.append("$('");
    statement.append(dollarSelector);
    statement.append("')");
    return this;
}

From source file:org.onexus.ui.authentication.persona.SignOutBehavior.java

License:Apache License

@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    component.setOutputMarkupId(true);//from w ww.java2 s  .com
    super.renderHead(component, response);

    final Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("componentId", component.getMarkupId());
    BrowserId personaId = SessionHelper.getBrowserId(Session.get());
    String userName = personaId == null ? "" : personaId.getEmail();
    variables.put("userName", userName);
    variables.put("callbackUrl", getCallbackUrl());

    final TextTemplate verifyTemplate = new PackageTextTemplate(VerifyBehavior.class, "signout.js.tmpl");
    String asString = verifyTemplate.asString(variables);

    response.render(GuestPanel.INCLUDE);
    response.render(OnDomReadyHeaderItem.forScript(asString));

}

From source file:org.onexus.ui.authentication.persona.VerifyBehavior.java

License:Apache License

@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    component.setOutputMarkupId(true);/* w  w  w  . j a  v a2  s. c om*/
    super.renderHead(component, response);

    final Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("componentId", component.getMarkupId());
    variables.put("callbackUrl", getCallbackUrl());

    final TextTemplate verifyTemplate = new PackageTextTemplate(VerifyBehavior.class, "verify.js.tmpl");
    String asString = verifyTemplate.asString(variables);
    response.render(OnDomReadyHeaderItem.forScript(asString));
}

From source file:org.opensingular.form.wicket.behavior.ConfigureByMInstanciaAttributesBehavior.java

License:Apache License

public void renderHead(Component component, IHeaderResponse response) {
    if (component instanceof FormComponent<?>)
        response.render(OnDomReadyHeaderItem.forScript("" + "$('label[for=" + component.getMarkupId() + "]')"
                + ".find('span.required').remove().end()"
                + ((isInstanceRequired(component)) ? ".append('<span class=\\'required\\'>*</span>')" : "")
                + ""));
}

From source file:org.opensingular.form.wicket.behavior.InputMaskBehavior.java

License:Apache License

/**
 * <p>Retorna o <i>script</i> gerado para este <i>behavior</i>.</p>
 *
 * @param component componente o qual este <i>behavior</i> dever ser adicionado.
 * @return o <i>javascript</i> gerado.
 *//* ww w  . j a va 2 s . co  m*/
protected String getScript(Component component) {
    return "var $this = $('#" + component.getMarkupId() + "');"
    //  + "$this.on('paste', function(event) {console.log(event); setTimeout(function(){$this.change();},1);});"
            + "$this.on('drop', function(event) {" + "  event.preventDefault();"
            + "  $this.val(event.originalEvent.dataTransfer.getData('text'));"
            + "  $this.inputmask('remove').inputmask(" + jsonOptions + ");"
            + "  setTimeout(function(){$this.change();},1);" + "});" + "$this.inputmask('remove').inputmask("
            + jsonOptions + ");";
}

From source file:org.opensingular.form.wicket.behavior.MoneyMaskBehavior.java

License:Apache License

/**
 * <p>Retorna o <i>script</i> gerado para este <i>behavior</i>.</p>
 *
 * @param component componente o qual este <i>behavior</i> dever ser adicionado.
 * @return o <i>javascript</i> gerado.
 *//*from  w  ww  .j a va2  s. co m*/
protected String getScript(Component component) {
    return "var $this = $('#" + component.getMarkupId() + "');"
            + "$this.on('paste', function() {setTimeout(function(){$this.maskMoney('mask');},1);});"
            + "$this.on('drop', function(event) {" + "  event.preventDefault();"
            + "  $this.val(event.originalEvent.dataTransfer.getData('text'));" + "  $this.maskMoney('mask');"
            + "  setTimeout(function(){$this.maskMoney('mask');},1);" + "});" + "$this.maskMoney("
            + getJsonOptions() + ");";
}