Package org.apache.click.util

Examples of org.apache.click.util.HtmlStringBuffer


        HiddenList hiddenList = new HiddenList("hiddenList");
        hiddenList.addValue("A");
        hiddenList.addValue("B");
        hiddenList.addValue("C");
       
        HtmlStringBuffer buffer = new HtmlStringBuffer();
        hiddenList.render(buffer);
       
        assertEquals(
                "<input type=\"hidden\" name=\"hiddenList\" id=\"hiddenList_1\" value=\"A\"/>" +
                "<input type=\"hidden\" name=\"hiddenList\" id=\"hiddenList_2\" value=\"B\"/>" +
                "<input type=\"hidden\" name=\"hiddenList\" id=\"hiddenList_3\" value=\"C\"/>",
                buffer.toString());
    }
View Full Code Here


        String fieldId = getId();
        JsScript script = new JsScript();
        script.setId(fieldId + "_js_setup");

        if (!headElements.contains(script)) {
            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
            buffer.append("var keyboard_png_path=\"");
            buffer.append(context.getRequest().getContextPath());
            buffer.append("/click/keyboard");
            buffer.append(versionIndicator);
            buffer.append(".png\"");
            script.setContent(buffer.toString());
            headElements.add(script);
        }
        return headElements;
    }
View Full Code Here

    protected Decorator createDecorator() {
        return new Decorator() {

            public String render(Object object, Context context) {
                TreeNode treeNode = (TreeNode) object;
                HtmlStringBuffer buffer = new HtmlStringBuffer();

                renderIcon(buffer, treeNode);

                renderCheckbox(buffer, treeNode);

                buffer.elementStart("span");
                if (treeNode.isSelected()) {
                    buffer.appendAttribute("class", "selected");
                } else {
                    buffer.appendAttribute("class", "unselected");
                }
                if (isJavascriptEnabled()) {
                    ((CheckboxJavascriptRenderer) javascriptHandler.getJavascriptRenderer()).renderSelect(
                        buffer);
                }
                buffer.closeTag();

                renderValue(buffer, treeNode);
                buffer.elementEnd("span");

                return buffer.toString();
            }

            /**
             * Render the node's value.
             *
             * @param buffer string buffer containing the markup
             * @param treeNode treeNode to render
             */
            protected void renderValue(HtmlStringBuffer buffer,
                TreeNode treeNode) {

                if (isJavascriptEnabled()) {
                    //create a href to interact with the checkbox on browser
                    buffer.elementStart("a");
                    Map hrefParameters =
                        Collections.singletonMap(SELECT_TREE_NODE_PARAM,
                                                 treeNode.getId());
                    buffer.appendAttribute("href", getHref(hrefParameters));

                    ((CheckboxJavascriptRenderer) javascriptHandler.getJavascriptRenderer()).renderValue(
                        buffer);
                    buffer.closeTag();
                    if (treeNode.getValue() != null) {
                        buffer.append(treeNode.getValue());
                    }
                    buffer.elementEnd("a");
                    buffer.append("\n");

                } else {
                    //just print normal value
                    if (treeNode.getValue() != null) {
                        buffer.append(treeNode.getValue());
                    }
                    buffer.append("\n");
                }
            }
        };
    }
View Full Code Here

                controlLink.setParameter(Table.PAGE, String.valueOf(table.getPageNumber() - 1));
                controlLink.setTitle(previousTitle);
                previousLabel = controlLink.toString();
            }

            HtmlStringBuffer pagesBuffer =
                new HtmlStringBuffer(table.getNumberPages() * 70);

            // Create sliding window of paging links
            int lowerBound = Math.max(0, table.getPageNumber() - 5);
            int upperBound = Math.min(lowerBound + 10, table.getNumberPages());
            if (upperBound - lowerBound < 10) {
                lowerBound = Math.max(upperBound - 10, 0);
            }

            for (int i = lowerBound; i < upperBound; i++) {
                String pageNumber = String.valueOf(i + 1);
                if (i == table.getPageNumber()) {
                    pagesBuffer.append("<strong>" + pageNumber + "</strong>");

                } else {
                    controlLink.setLabel(pageNumber);
                    controlLink.setParameter(Table.PAGE, String.valueOf(i));
                    controlLink.setTitle(gotoTitle + " " + pageNumber);
                    controlLink.render(pagesBuffer);
                }

                if (i < upperBound - 1) {
                    pagesBuffer.append(", ");
                }
            }
            String pageLinks = pagesBuffer.toString();

            if (table.getPageNumber() < table.getNumberPages() - 1) {
                controlLink.setLabel(nextLabel);
                controlLink.setParameter(Table.PAGE, String.valueOf(table.getPageNumber() + 1));
                controlLink.setTitle(nextTitle);
View Full Code Here

     *
     * @return the HTML representation of this paginator
     */
    @Override
    public String toString() {
        HtmlStringBuffer buffer = new HtmlStringBuffer();

        render(buffer);

        return buffer.toString();
    }
View Full Code Here

        public void init(TreeNode treeNode) {
            super.init(treeNode);
            selectId = buildString("s_", treeNode.getId(), "");
            checkboxId = buildString("c_", treeNode.getId(), "");

            HtmlStringBuffer buffer = new HtmlStringBuffer();
            buffer.append(" onclick=\"handleNodeSelection(this, event,'");
            buffer.append(selectId);
            buffer.append("','");
            buffer.append(checkboxId);
            buffer.append("',false); return false;\"");
            nodeSelectionString = buffer.toString();

            buffer = new HtmlStringBuffer();
            buffer.append(" onclick=\"onCheckboxClick(this,event,'");
            buffer.append(selectId);
            buffer.append("',");
            buffer.append(Boolean.toString(isSelectChildNodes()));
            buffer.append(");\"");
            checkboxOnClickString = buffer.toString();
        }
View Full Code Here

     */
    public String getOnClick(Object value) {
        Context context = getContext();
        String uri = ClickUtils.getRequestURI(context.getRequest());

        HtmlStringBuffer buffer =
            new HtmlStringBuffer(uri.length() + getName().length() + 40);

        buffer.append(uri);
        buffer.append("?");
        buffer.append(ACTION_BUTTON);
        buffer.append("=");
        buffer.append(getName());

        if (value != null) {
            buffer.append("&amp;");
            buffer.append(VALUE);
            buffer.append("=");
            buffer.append(ClickUtils.encodeUrl(value, context));
        }

        if (hasParameters()) {
            for (String name : getParameters().keySet()) {
                if (!name.equals(ACTION_BUTTON) && !name.equals(VALUE)) {
                    Object paramValue = getParameters().get(name);
                    String encodedValue
                        = ClickUtils.encodeUrl(paramValue, context);
                    buffer.append("&amp;");
                    buffer.append(name);
                    buffer.append("=");
                    buffer.append(encodedValue);
                }
            }
        }

        return "javascript:document.location.href='"
               + context.getResponse().encodeURL(buffer.toString())
               + "';";
    }
View Full Code Here

                }
            }
        }

        if (params != null && !params.isEmpty()) {
            HtmlStringBuffer buffer = new HtmlStringBuffer();

            for (Iterator<String> i = params.keySet().iterator(); i.hasNext();) {
                String paramName = i.next();
                Object paramValue = params.get(paramName);

                // Check for multivalued parameter
                if (paramValue instanceof String[]) {
                    String[] paramValues = (String[]) paramValue;
                    for (int j = 0; j < paramValues.length; j++) {
                        buffer.append(paramName);
                        buffer.append("=");
                        buffer.append(ClickUtils.encodeUrl(paramValues[j], context));
                        if (j < paramValues.length - 1) {
                            buffer.append("&");
                        }
                    }
                } else {
                    if (paramValue != null) {
                        buffer.append(paramName);
                        buffer.append("=");
                        buffer.append(ClickUtils.encodeUrl(paramValue, context));
                    }
                }
                if (i.hasNext()) {
                    buffer.append("&");
                }
            }

            if (buffer.length() > 0) {
                if (location.contains("?")) {
                    location += "&" + buffer.toString();
                } else {
                    location += "?" + buffer.toString();
                }
            }
        }

        redirect = location;
View Full Code Here

     * Return the Field focus JavaScript.
     *
     * @return the Field focus JavaScript
     */
    public String getFocusJavaScript() {
        HtmlStringBuffer buffer = new HtmlStringBuffer(32);

        buffer.append("setFocus('");
        buffer.append(getId());
        buffer.append("');");

        return buffer.toString();
    }
View Full Code Here

     *
     * @return the HTML representation of this control
     */
    @Override
    public String toString() {
        HtmlStringBuffer buffer = new HtmlStringBuffer(getControlSizeEst());
        render(buffer);
        return buffer.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.click.util.HtmlStringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.