Example usage for org.apache.wicket.markup ComponentTag remove

List of usage examples for org.apache.wicket.markup ComponentTag remove

Introduction

In this page you can find the example usage for org.apache.wicket.markup ComponentTag remove.

Prototype

public final void remove(String key) 

Source Link

Usage

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

License:Apache License

/**
 * @see org.apache.wicket.markup.html.form.FormComponent#onComponentTag(org.apache.wicket.markup.ComponentTag)
 *//* ww w .  j  a v  a  2 s . c  om*/
@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);
    // since this component cannot be attached to input tag the name
    // variable is illegal
    tag.remove("name");
}

From source file:com.conwax.ajax.SimpleAjaxFallbackLink.java

License:Apache License

/**
 * Removes any inline 'onclick' attributes set by
 * Link#onComponentTag(ComponentTag).//ww  w. ja  va  2  s  .c  o  m
 * 
 * @param tag
 *            the component tag
 */
@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    // Ajax links work with JavaScript Event registration
    tag.remove("onclick");

    String tagName = tag.getName();
    if (isLinkEnabled() && !("a".equalsIgnoreCase(tagName) || "area".equalsIgnoreCase(tagName)
            || "link".equalsIgnoreCase(tagName))) {
        String msg = String.format(
                "%s must be used only with <a>, <area> or <link> markup elements. "
                        + "The fallback functionality doesn't work for other markup elements. "
                        + "Component path: %s, markup element: <%s>.",
                SimpleAjaxFallbackLink.class.getSimpleName(), getClassRelativePath(), tagName);
        findMarkupStream().throwMarkupException(msg);
    }
}

From source file:com.myamamoto.wicket.misc.behavior.AppendErrorClassOnErrorBehavior.java

License:Apache License

@Override
public void onComponentTag(Component arg0, ComponentTag arg1) {
    super.onComponentTag(arg0, arg1);
    String orgClass = arg1.getAttribute(ATTRIBUTE_CLASS);

    if (arg0.hasErrorMessage()) {
        String newClass;/*from www. j  a  v  a2  s .c  o m*/
        boolean existsOrgClass = null != orgClass && !orgClass.isEmpty();
        if (existsOrgClass) {
            newClass = orgClass + this.errorClassWithComma;
        } else {
            newClass = this.errorClass;
        }
        arg1.put(ATTRIBUTE_CLASS, newClass);
    } else {
        boolean existsOrgClass = null != orgClass && !orgClass.isEmpty() && !this.errorClass.equals(orgClass);
        if (existsOrgClass) {
            arg1.put(ATTRIBUTE_CLASS, orgClass.replaceAll(this.errorClassWithComma, ""));
        } else {
            arg1.remove(ATTRIBUTE_CLASS);
        }
    }
}

From source file:com.senacor.wbs.web.core.form.TooltipFeedbackIndicator.java

License:Apache License

@Override
public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);
    if (component.hasErrorMessage()) {
        tag.put("class", "fieldError");
        tag.put("showtooltip", "true");
        tag.put("title", component.getFeedbackMessage().getMessage().toString());
    } else {//from   www. j  a v  a  2s .c  o m
        tag.remove("class");
        tag.remove("showtooltip");
        tag.remove("title");
    }
}

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

License:Open Source License

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

    if (tag.getName().equalsIgnoreCase("button")) //$NON-NLS-1$
    {//from w w  w  .ja v  a 2 s .c o m
        tag.remove("value"); //$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) {
            CharSequence url = urlFor(ILinkListener.INTERFACE);
            tag.put("onclick", getForm().getJsForInterfaceUrl(url)); //$NON-NLS-1$
            tag.remove("name");//otherwise org.apache.wicket thinks it has cliked, all button names is always present in the submit params! //$NON-NLS-1$

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

            if (eventExecutor.hasRightClickCmd()) {
                CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
                tag.put("oncontextmenu", getForm().getJsForInterfaceUrl(urlr) + " return false;"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        } else {
            // fix for issue 164656: we don't want single clicks to cause a form submit and block the double clicks.
            if ((!eventExecutor.hasActionCmd()) && (eventExecutor.hasDoubleClickCmd()))
                tag.put("onclick", "return false;"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        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.WebDataListBox.java

License:Open Source License

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

    if (!multiSelection) {
        tag.remove("multiple"); //$NON-NLS-1$
    }//from ww  w .  j  av  a  2 s  . co  m
    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.WebTabPanel.java

License:Open Source License

public WebTabPanel(IApplication application, final RuntimeTabPanel scriptable, String name, int orient,
        boolean oneTab) {
    super(name);/* ww  w . j a  v a  2 s  .co  m*/
    this.application = application;
    this.orient = orient;

    final boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    setOutputMarkupPlaceholderTag(true);

    if (orient != TabPanel.SPLIT_HORIZONTAL && orient != TabPanel.SPLIT_VERTICAL)
        add(new Label("webform", new Model<String>("")));//temporary add, in case the tab panel does not contain any tabs //$NON-NLS-1$ //$NON-NLS-2$

    // TODO check ignore orient and oneTab??
    IModel<Integer> tabsModel = new AbstractReadOnlyModel<Integer>() {
        private static final long serialVersionUID = 1L;

        @Override
        public Integer getObject() {
            return Integer.valueOf(allTabs.size());
        }
    };

    if (orient != TabPanel.HIDE && orient != TabPanel.SPLIT_HORIZONTAL && orient != TabPanel.SPLIT_VERTICAL
            && !(orient == TabPanel.DEFAULT_ORIENTATION && oneTab)) {
        add(new Loop("tablinks", tabsModel) //$NON-NLS-1$
        {
            private static final long serialVersionUID = 1L;

            private String focusedItem;

            @Override
            protected void populateItem(final LoopItem item) {
                final WebTabHolder holder = allTabs.get(item.getIteration());
                MarkupContainer link = null;
                link = new ServoySubmitLink("tablink", useAJAX) //$NON-NLS-1$
                {
                    private static final long serialVersionUID = 1L;

                    /**
                     * @see wicket.ajax.markup.html.AjaxFallbackLink#onClick(wicket.ajax.AjaxRequestTarget)
                     */
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Page page = findPage();
                        if (page != null) {
                            setActiveTabPanel(holder.getPanel());
                            if (target != null) {
                                relinkAtTabPanel(WebTabPanel.this);
                                focusedItem = item.getId();
                                WebEventExecutor.generateResponse(target, page);
                            }
                        }
                    }

                    private void relinkAtForm(WebForm form) {
                        form.visitChildren(WebTabPanel.class, new IVisitor<WebTabPanel>() {
                            public Object component(WebTabPanel wtp) {
                                relinkAtTabPanel(wtp);
                                return IVisitor.CONTINUE_TRAVERSAL;
                            }
                        });
                    }

                    private void relinkAtTabPanel(WebTabPanel wtp) {
                        wtp.relinkFormIfNeeded();
                        wtp.visitChildren(WebForm.class, new IVisitor<WebForm>() {
                            public Object component(WebForm form) {
                                relinkAtForm(form);
                                return IVisitor.CONTINUE_TRAVERSAL;
                            }
                        });
                    }

                    @Override
                    protected void disableLink(final ComponentTag tag) {
                        // if the tag is an anchor proper
                        if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") //$NON-NLS-1$//$NON-NLS-2$
                                || tag.getName().equalsIgnoreCase("area")) //$NON-NLS-1$
                        {
                            // Remove any href from the old link
                            tag.remove("href"); //$NON-NLS-1$
                            tag.remove("onclick"); //$NON-NLS-1$
                        }
                    }

                };

                if (item.getId().equals(focusedItem)) {
                    IRequestTarget currentRequestTarget = RequestCycle.get().getRequestTarget();
                    if (currentRequestTarget instanceof AjaxRequestTarget) {
                        ((AjaxRequestTarget) currentRequestTarget).focusComponent(link);
                    }
                    focusedItem = null;
                }

                if (holder.getTooltip() != null) {
                    link.setMetaData(TooltipAttributeModifier.TOOLTIP_METADATA, holder.getTooltip());
                }

                TabIndexHelper.setUpTabIndexAttributeModifier(link, tabSequenceIndex);
                link.add(TooltipAttributeModifier.INSTANCE);

                if (item.getIteration() == 0)
                    link.add(new AttributeModifier("firsttab", true, new Model<Boolean>(Boolean.TRUE))); //$NON-NLS-1$
                link.setEnabled(holder.isEnabled() && WebTabPanel.this.isEnabled());

                String text = holder.getText();
                if (holder.getDisplayedMnemonic() > 0) {
                    final String mnemonic = Character.toString((char) holder.getDisplayedMnemonic());
                    link.add(new SimpleAttributeModifier("accesskey", mnemonic)); //$NON-NLS-1$
                    if (text != null && text.contains(mnemonic) && !HtmlUtils.hasUsefulHtmlContent(text)) {
                        StringBuffer sbBodyText = new StringBuffer(text);
                        int mnemonicIdx = sbBodyText.indexOf(mnemonic);
                        if (mnemonicIdx != -1) {
                            sbBodyText.insert(mnemonicIdx + 1, "</u>"); //$NON-NLS-1$
                            sbBodyText.insert(mnemonicIdx, "<u>"); //$NON-NLS-1$
                            text = sbBodyText.toString();
                        }
                    }
                }
                ServoyTabIcon tabIcon = new ServoyTabIcon("icon", holder, scriptable); //$NON-NLS-1$
                link.add(tabIcon);

                Label label = new Label("linktext", new Model<String>(text)); //$NON-NLS-1$
                label.setEscapeModelStrings(false);
                link.add(label);
                item.add(link);
                IModel<String> selectedOrDisabledClass = new AbstractReadOnlyModel<String>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String getObject() {
                        if (!holder.isEnabled() || !WebTabPanel.this.isEnabled()) {
                            if (currentForm == holder.getPanel()) {
                                return "disabled_selected_tab"; //$NON-NLS-1$
                            }
                            return "disabled_tab"; //$NON-NLS-1$
                        } else {
                            if (currentForm == holder.getPanel()) {
                                return "selected_tab"; //$NON-NLS-1$
                            }
                            return "deselected_tab"; //$NON-NLS-1$
                        }
                    }
                };
                item.add(new AttributeModifier("class", true, selectedOrDisabledClass)); //$NON-NLS-1$
                label.add(new StyleAppendingModifier(new Model<String>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String getObject() {
                        String style = "white-space: nowrap;"; //$NON-NLS-1$
                        if (foreground != null) {
                            style += " color:" + PersistHelper.createColorString(foreground); //$NON-NLS-1$
                        }
                        if (holder.getIcon() != null) {
                            style += "; padding-left: 3px"; //$NON-NLS-1$
                        }
                        return style;
                    }
                }));
            }
        });

        // All tab panels get their tabs rearranged after they make it to the browser.
        // On Chrome & Safari the tab rearrangement produces an ugly flicker effect, because
        // initially the tabs are not visible and then they are made visible. By
        // sending the tab as invisible and turning it to visible only after the tabs
        // are arranged, this jumping/flickering effect is gone. However a small delay can now be
        // noticed in Chrome & Safari, which should also be eliminated somehow.
        // The tab panel is set to visible in function "rearrageTabsInTabPanel" from "servoy.js".
        add(new StyleAppendingModifier(new Model<String>() {
            private static final long serialVersionUID = 1L;

            @Override
            public String getObject() {
                return "visibility: hidden;overflow:hidden"; //$NON-NLS-1$
            }
        }));

        add(new AbstractServoyDefaultAjaxBehavior() {

            @Override
            protected void respond(AjaxRequestTarget target) {
            }

            @Override
            public void renderHead(IHeaderResponse response) {
                super.renderHead(response);
                boolean dontRearrangeHere = false;

                if (!(getRequestCycle().getRequestTarget() instanceof AjaxRequestTarget)
                        && Utils.getAsBoolean(((MainPage) getPage()).getController().getApplication()
                                .getRuntimeProperties().get("enableAnchors"))) //$NON-NLS-1$
                {
                    Component parentForm = getParent();
                    while ((parentForm != null) && !(parentForm instanceof WebForm))
                        parentForm = parentForm.getParent();
                    if (parentForm != null) {
                        int anch = ((WebForm) parentForm).getAnchors(WebTabPanel.this.getMarkupId());
                        if (anch != 0 && anch != IAnchorConstants.DEFAULT)
                            dontRearrangeHere = true;
                    }
                }
                if (!dontRearrangeHere) {
                    String jsCall = "rearrageTabsInTabPanel('" + WebTabPanel.this.getMarkupId() + "');"; //$NON-NLS-1$ //$NON-NLS-2$
                    // Safari and Konqueror have some problems with the "domready" event, so for those
                    // browsers we'll use the "load" event. Otherwise use "domready", it reduces the flicker
                    // effect when rearranging the tabs.
                    ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties();
                    if (clp.isBrowserKonqueror() || clp.isBrowserSafari())
                        response.renderOnLoadJavascript(jsCall);
                    else
                        response.renderOnDomReadyJavascript(jsCall);
                }
            }

            @Override
            public boolean isEnabled(Component component) {
                return WebClientSession.get().useAjax();
            }

        });
    }
    add(StyleAttributeModifierModel.INSTANCE);
    add(TooltipAttributeModifier.INSTANCE);
    this.scriptable = scriptable;
    ((ChangesRecorder) scriptable.getChangesRecorder()).setDefaultBorderAndPadding(null,
            TemplateGenerator.DEFAULT_LABEL_PADDING);
}

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

License:Open Source License

/**
 * Processes the component tag.// w  ww . j  a  v a2 s. co m
 * 
 * @param tag
 *            Tag to modify
 * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
 */
@Override
protected void onComponentTag(final ComponentTag tag) {
    PackageResourceReference img;

    if (!isAuthorized) {
        tag.setName("img");

        final String value = getValue();
        if (value != null && value.equals("true")) {
            img = new PackageResourceReference(AuthOnlyCheckBox.class, "res/check.png");
        } else {
            img = new PackageResourceReference(AuthOnlyCheckBox.class, "res/uncheck.png");
        }
        CharSequence url = RequestCycle.get().urlFor(img, null);

        tag.put("src",
                RequestCycle.get().getOriginalResponse().encodeURL(Strings.replaceAll(url, "&", "&amp;")));
    } else {
        checkComponentTag(tag, "input");
        checkComponentTagAttribute(tag, "type", "checkbox");

        final String value = getValue();
        if (value != null) {
            try {
                if (Strings.isTrue(value)) {
                    tag.put("checked", "checked");
                } else {
                    // In case the attribute was added at design time
                    tag.remove("checked");
                }
            } catch (StringValueConversionException e) {
                throw new WicketRuntimeException("Invalid boolean value \"" + value + "\"", e);
            }
        }

        // Should a roundtrip be made (have onSelectionChanged called) when the
        // checkbox 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();
            //               }
            //               tag.put("onclick", form.getJsForInterfaceUrl(url));
            //            }
            //            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
            //               tag.put("onclick", "window.location.href='" + url +
            //                  (url.toString().indexOf('?') > -1 ? "&amp;" : "?") + getInputName() +
            //                  "=' + this.checked;");
            //            }

        }
    }

    super.onComponentTag(tag);
}

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

License:Open Source License

/**
 * @see org.apache.wicket.markup.html.form.FormComponent#onComponentTag(org.apache.wicket.markup.ComponentTag)
 *//*from   w ww  . j  av  a 2 s . c o  m*/
@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    // since this component cannot be attached to input tag the name
    // variable is illegal
    tag.remove("name");
}

From source file:cz.zcu.kiv.eegdatabase.wui.components.form.MyFormComponentLabel.java

License:Apache License

@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);
    //FormComponentPanel arent represented by form contro tags in the markup
    //specifying 'for' attribute for the label would result in invalid html
    if (this.getFormComponent() instanceof FormComponentPanel) {
        tag.remove("for");
    }//from w  w w  .jav a 2s.  c  om
}