Package org.apache.click

Examples of org.apache.click.Page


     * CLK-453
     */
    public void testGetHeadElements() {
        MockContext.initContext();

        Page page = new Page();
        PageImports pageImports = new PageImports(page);

        // Check imports using an internal Form Control
        FormTable table = new FormTable("table");

        pageImports.processControl(table);
        List headElements = pageImports.getHeadElements();
        List jsElements = pageImports.getJsElements();

        assertTrue(headElements.get(0).toString().contains("/table.css"));
        assertTrue(headElements.get(1).toString().contains("/control.css"));
        assertTrue(jsElements.get(0).toString().contains("/control.js"));


        // Check imports using an external Form Control
        page = new Page();
        pageImports = new PageImports(page);

        Form form = new Form("form");
        table = new FormTable("table", form);
        form.add(table);
View Full Code Here


    }

    public void testI18N() {
        MockContext.initContext();

        Page page = new Page();
        Menu rootMenu = new MyMenu("root");
        page.addControl(rootMenu);

        Menu menu = new MyMenu("mymenu");
        rootMenu.add(menu);

        assertEquals("Root Label", menu.getLabel());
View Full Code Here

    @Override
    public void setParent(Object parent) {
        if (parent == null) {
            // If the field parent control is set to null (indicating the field
            // is being removed), also remove the field from its parent page
            Page page = getPage();
            if (page != null) {
                page.getControls().remove(this);
                page.getModel().remove(getName());
            }
        }
        super.setParent(parent);
    }
View Full Code Here

            throw new IllegalStateException("AutoCompleteTextField name"
                + " is not defined. Set the name before calling"
                + " getHeadElements().");
        }

        Page page = getPage();
        if (page == null) {
            throw new IllegalStateException("The AutoCompleteTextField, '"
                + fieldName + "', is not attached to the Page. Add"
                + " AutoCompleteTextField to a parent form or container and"
                + " attach the parent to the Page before calling"
                + " getHeadElements().");
        }

        Context context = getContext();

        if (headElements == null) {
            headElements = super.getHeadElements();

            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);

            headElements.add(new CssImport("/click/extras-control.css",
                versionIndicator));
            headElements.add(new JsImport("/click/control.js", versionIndicator));
            headElements.add(new JsImport("/click/prototype/prototype.js",
                versionIndicator));
            headElements.add(new JsImport("/click/prototype/effects.js",
                versionIndicator));
            headElements.add(new JsImport("/click/prototype/controls.js",
                versionIndicator));
        }

        // Note the addLoadEvent script is recreated and checked if it
        // is contained in the headElement.
        String fieldId = getId();
        JsScript script = new JsScript();
        script.setId(fieldId + "_autocomplete");
        if (!headElements.contains(script)) {
            // Script must be executed as soon as browser dom is ready
            script.setExecuteOnDomReady(true);

            String contextPath = context.getRequest().getContextPath();
            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
            buffer.append("new Ajax.Autocompleter(");
            buffer.append("'").append(fieldId).append("'");
            buffer.append(",'").append(fieldId).append("_auto_complete_div'");
            buffer.append(",'").append(contextPath).append(page.getPath()).append(
                "'");
            buffer.append(",").append(getAutoCompleteOptions()).append(");");
            script.setContent(buffer.toString());
            headElements.add(script);
        }
View Full Code Here

     */
    @Override
    public void onInit() {
        super.onInit();

        Page page = getPage();
        if (page == null) {
            // If parent page is not reachable, exit early
            return;
        }

        // See whether control has been registered at Page level.
        Object control = page.getModel().get(getName());

        // If not registered, then register control
        if (control == null) {
            // Ensure current parent control does not change
            Object parent = getParent();
            page.addControl(this);
            setParent(parent);

        } else if (!(control instanceof AutoCompleteTextField)) {
            String message =
                "Non AutoCompleteTextField object '"
View Full Code Here

                    if (parent == null) {
                        return control.getMessages();
                    }

                } else if (parent instanceof Page) {
                    Page page = (Page) parent;
                    return page.getMessages();

                } else if (parent != null) {
                    // Unknown parent class
                    return Collections.EMPTY_MAP;
                }
View Full Code Here

                    if (parent == null) {
                        return message;
                    }

                } else if (parent instanceof Page) {
                    Page page = (Page) parent;
                    if (page.getMessages().containsKey(name)) {
                        message = (String) page.getMessages().get(name);
                    }
                    return message;

                } else if (parent != null) {
                    // Unknown parent class
View Full Code Here

     * @throws Exception if an error occurs creating the Page
     */
    protected Page newPageInstance(String path, Class pageClass,
            HttpServletRequest request) throws Exception {

        Page page = null;

        String beanName = toBeanName(pageClass);

        if (getApplicationContext().containsBean(beanName)) {
            page = (Page) getApplicationContext().getBean(beanName);

        } else if (getApplicationContext().containsBean(pageClass.getName())) {
            page = (Page) getApplicationContext().getBean(pageClass.getName());

        } else {
            page = (Page) pageClass.newInstance();

            // Inject any Spring beans into the page instance
            if (!pageSetterBeansMap.isEmpty()) {
                List beanList = (List) pageSetterBeansMap.get(page.getClass());
                if (beanList != null) {
                    for (int i = 0; i < beanList.size(); i++) {
                        BeanNameAndMethod bnam = (BeanNameAndMethod) beanList.get(i);
                        Object bean = getApplicationContext().getBean(bnam.beanName);

View Full Code Here

     */
    public void setParent(Object parent) {
        if (parent == null) {
            // If the field parent control is set to null (indicating the field
            // is being removed), also remove the field from its parent page
            Page page = getPage();
            if (page != null) {
                page.getControls().remove(this);
                page.getModel().remove(getName());
            }
        }
        super.setParent(parent);
    }
View Full Code Here

            throw new IllegalStateException("AutoCompleteTextField name"
                + " is not defined. Set the name before calling"
                + " getHeadElements().");
        }

        Page page = getPage();
        if (page == null) {
            throw new IllegalStateException("The AutoCompleteTextField, '"
                + fieldName + "', is not attached to the Page. Add"
                + " AutoCompleteTextField to a parent form or container and"
                + " attach the parent to the Page before calling"
                + " getHeadElements().");
        }

        Context context = getContext();

        if (headElements == null) {
            headElements = super.getHeadElements();

            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);

            headElements.add(new CssImport("/click/extras-control.css",
                versionIndicator));
            headElements.add(new JsImport("/click/control.js", versionIndicator));
            headElements.add(new JsImport("/click/prototype/prototype.js",
                versionIndicator));
            headElements.add(new JsImport("/click/prototype/effects.js",
                versionIndicator));
            headElements.add(new JsImport("/click/prototype/controls.js",
                versionIndicator));
        }

        // Note the addLoadEvent script is recreated and checked if it
        // is contained in the headElement.
        String fieldId = getId();
        JsScript script = new JsScript();
        script.setId(fieldId + "_autocomplete");
        if (!headElements.contains(script)) {
            // Script must be executed as soon as browser dom is ready
            script.setExecuteOnDomReady(true);

            String contextPath = context.getRequest().getContextPath();
            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
            buffer.append("new Ajax.Autocompleter(");
            buffer.append("'").append(fieldId).append("'");
            buffer.append(",'").append(fieldId).append("_auto_complete_div'");
            buffer.append(",'").append(contextPath).append(page.getPath()).append(
                "'");
            buffer.append(",").append(getAutoCompleteOptions()).append(");");
            script.setContent(buffer.toString());
            headElements.add(script);
        }
View Full Code Here

TOP

Related Classes of org.apache.click.Page

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.