Example usage for org.apache.wicket.markup.html.form Form getJsForInterfaceUrl

List of usage examples for org.apache.wicket.markup.html.form Form getJsForInterfaceUrl

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form getJsForInterfaceUrl.

Prototype

public final CharSequence getJsForInterfaceUrl(CharSequence url) 

Source Link

Usage

From source file:com.antilia.web.field.impl.TableRadioChoice.java

License:Apache License

/**
 * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
 *///from w  w  w  . ja  v a 2 s  .co m
@Override
protected final void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) {
    // Iterate through choices
    final List<? extends T> choices = getChoices();

    // Buffer to hold generated body
    final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70);

    // The selected value
    final String selected = getValue();

    buffer.append("<table style=\"width: 100%;\" cellpadding=\"0\" cellspacing=\"5\">");

    // Loop through choices
    for (int index = 0; index < choices.size(); index++) {
        // Get next choice
        final T choice = choices.get(index);

        Object displayValue = getChoiceRenderer().getDisplayValue(choice);
        Class<?> objectClass = (displayValue == null ? null : displayValue.getClass());

        // Get label for choice
        String label = "";

        if (objectClass != null && objectClass != String.class) {
            final IConverter converter = (IConverter) getConverter(objectClass);

            if (!converter.getClass().isAssignableFrom(objectClass)) {
                throw new IllegalArgumentException(
                        "converter can not convert " + objectClass.getName() + " to string");
            }

            label = converter.convertToString(displayValue, getLocale());
        } else if (displayValue != null) {
            label = displayValue.toString();
        }

        // If there is a display value for the choice, then we know that the
        // choice is automatic in some way. If label is /null/ then we know
        // that the choice is a manually created radio tag at some random
        // location in the page markup!
        if (label != null) {
            // Append option suffix
            buffer.append(getPrefix());

            String id = getChoiceRenderer().getIdValue(choice, index);
            final String idAttr = getMarkupId() + "_" + id;

            buffer.append("<tr>");
            buffer.append("<td style=\"width: 15px; vertical-align: top;\">");

            // Add radio tag
            buffer.append("<input name=\"").append(getInputName()).append("\"").append(" type=\"radio\"")
                    .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : ""))
                    .append((isEnabled() ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id)
                    .append("\" id=\"").append(idAttr).append("\"");

            // Should a roundtrip be made (have onSelectionChanged called)
            // when the option is clicked?
            if (wantOnSelectionChangedNotifications()) {
                CharSequence url = urlFor(IOnChangeListener.INTERFACE);

                Form<?> form = findParent(Form.class);
                if (form != null) {
                    RequestContext rc = RequestContext.get();
                    if (rc.isPortletRequest()) {
                        // restore url back to real wicket path as its going to be interpreted
                        // by the form itself
                        url = ((PortletRequestContext) rc).getLastEncodedPath();
                    }
                    buffer.append(" onclick=\"").append(form.getJsForInterfaceUrl(url)).append(";\"");
                } else {
                    // TODO: following doesn't work with portlets, should be posted to a dynamic
                    // hidden form
                    // with an ActionURL or something
                    // NOTE: do not encode the url as that would give
                    // invalid JavaScript
                    buffer.append(" onclick=\"window.location.href='").append(url)
                            .append((url.toString().indexOf('?') > -1 ? "&amp;" : "?") + getInputName())
                            .append("=").append(id).append("';\"");
                }
            }

            buffer.append("/>");

            buffer.append("</td>");

            buffer.append("<td nowrap=\"nowrap\" style=\"width: 300px;\">");
            // Add label for radio button
            String display = label;
            if (localizeDisplayValues()) {
                display = getLocalizer().getString(label, this, label);
            }
            CharSequence escaped = Strings.escapeMarkup(display, false, true);
            buffer.append(escaped);

            // Append option suffix
            buffer.append(getSuffix());
            buffer.append("</td>");
            buffer.append("</tr>");
        }

    }
    buffer.append("</table>");

    // Replace body
    replaceComponentTagBody(markupStream, openTag, buffer);
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebBaseLabel.java

License:Open Source License

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    if (useAJAX) {
        Object oe = scriptable.getClientProperty("ajax.enabled"); //$NON-NLS-1$
        if (oe != null)
            useAJAX = Utils.getAsBoolean(oe);
    }//from w  w w  .  j av  a 2  s  .  c om

    if (!useAJAX) {
        Form<?> f = getForm();
        if (f != null) {
            if (eventExecutor.hasActionCmd()) {
                CharSequence url = urlFor(ILinkListener.INTERFACE);
                tag.put("onclick", f.getJsForInterfaceUrl(url)); //$NON-NLS-1$
            }

            if (eventExecutor.hasDoubleClickCmd()) {
                CharSequence urld = urlFor(IDoubleClickListener.INTERFACE);
                tag.put("ondblclick", f.getJsForInterfaceUrl(urld)); //$NON-NLS-1$
            }

            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                // We need a "return false;" so that the context menu is not displayed in the browser.
                tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }

    if (tag.getName().equalsIgnoreCase("label")) //$NON-NLS-1$
    {
        IFieldComponent labelFor = getLabelFor();
        if (labelFor instanceof Component) {
            tag.put("for", ((Component) labelFor).getMarkupId()); //$NON-NLS-1$
            char displayMnemonic = (char) getDisplayedMnemonic();
            if (displayMnemonic > 0)
                tag.put("accesskey", Character.toString(displayMnemonic)); //$NON-NLS-1$
        }
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebBaseSelectBox.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    if (useAJAX) {
        Object oe = scriptable.getClientProperty("ajax.enabled");
        if (oe != null)
            useAJAX = Utils.getAsBoolean(oe);
    }//from  w w  w .  ja  v a  2 s.com
    if (!useAJAX) {
        Form<?> f = getForm();
        if (f != null) {
            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                // We need a "return false;" so that the context menu is not displayed in the browser.
                tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataCheckBoxChoice.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    if (useAJAX) {
        Object oe = scriptable.getClientProperty("ajax.enabled"); //$NON-NLS-1$
        if (oe != null)
            useAJAX = Utils.getAsBoolean(oe);
    }//from   w  w  w.j  a va 2  s  .  c  om
    if (!useAJAX) {
        Form<?> f = getForm();
        if (f != null) {
            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                // We need a "return false;" so that the context menu is not displayed in the browser.
                tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataListBox.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    if (!multiSelection) {
        tag.remove("multiple"); //$NON-NLS-1$
    }//  w ww . j a  va2s.  c  om
    tag.put("size", Math.max(2, getChoices().size())); //$NON-NLS-1$

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    if (useAJAX) {
        Object oe = scriptable.getClientProperty("ajax.enabled"); //$NON-NLS-1$
        if (oe != null)
            useAJAX = Utils.getAsBoolean(oe);
    }
    if (!useAJAX) {
        Form<?> f = getForm();
        if (f != null) {
            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                // We need a "return false;" so that the context menu is not displayed in the browser.
                tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataTextArea.java

License:Open Source License

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    if (useAJAX) {
        Object oe = scriptable.getClientProperty("ajax.enabled");
        if (oe != null)
            useAJAX = Utils.getAsBoolean(oe);
    }/*  w  w  w  .ja v a 2s  . c om*/

    if (!useAJAX) {
        Form<?> f = getForm();
        if (f != null) {
            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                // We need a "return false;" so that the context menu is not displayed in the browser.
                tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }
}

From source file:com.userweave.components.authorization.AuthOnlyDropDownChoice.java

License:Open Source License

/**
 * Processes the component tag.// www .j  a va 2  s .  c o  m
 * 
 * @param tag
 *            Tag to modify
 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
 */
@Override
protected void onComponentTag(final ComponentTag tag) {
    if (!isAuthorized) {
        tag.setName("em");
    } else {
        checkComponentTag(tag, "select");

        // Should a roundtrip be made (have onSelectionChanged called) when the
        // selection changed?
        if (wantOnSelectionChangedNotifications()) {
            // we do not want relative URL here, because it will be used by
            // Form#dispatchEvent
            CharSequence url = urlFor(new ListenerInterfaceRequestHandler(
                    new PageAndComponentProvider(getPage(), this), IOnChangeListener.INTERFACE));

            Form<?> form = findParent(Form.class);
            if (form != null) {
                tag.put("onchange", form.getJsForInterfaceUrl(url.toString()));
            } else {
                tag.put("onchange",
                        "window.location.href='" + url + (url.toString().indexOf('?') > -1 ? "&" : "?")
                                + getInputName() + "=' + this.options[this.selectedIndex].value;");
            }
        }
    }

    super.onComponentTag(tag);
}

From source file:org.cdlflex.ui.markup.html.form.ButtonRadioChoice.java

License:Apache License

/**
 * Builds the round-trip url added as "onclick" attribute to the radio choice button for the given id.
 * // ww w .j  a v  a  2s .c  om
 * @param id the id value of the choice renderer
 * @return a url usable in an "onclick" attribute
 */
protected String buildOnClickUrl(String id) {
    CharSequence url = urlFor(IOnChangeListener.INTERFACE, new PageParameters());
    Form<?> form = findParent(Form.class);

    String onclick;
    if (form != null) {
        onclick = form.getJsForInterfaceUrl(url) + ";";
    } else {
        onclick = "window.location.href='" + url;
        onclick += (url.toString().indexOf('?') > -1 ? '&' : '?') + getInputName();
        onclick += "=" + id + ";";
    }

    return onclick;
}