Package org.apache.click

Examples of org.apache.click.Page


     * @see org.apache.click.Control#onInit()
     */
    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


        Context context = getContext();

        final HttpServletRequest request = context.getRequest();

        final Page page = ClickUtils.getParentPage(this);

        final Map renderModel = new HashMap(page.getModel());

        renderModel.putAll(getModel());

        if (hasAttributes()) {
            renderModel.put("attributes", getAttributes());
        } else {
            renderModel.put("attributes", Collections.EMPTY_MAP);
        }

        renderModel.put("this", this);

        renderModel.put("context", request.getContextPath());

        Format format = page.getFormat();
        if (format != null) {
            renderModel.put("format", format);
        }

        Map templateMessages = new HashMap(getMessages());
        templateMessages.putAll(page.getMessages());
        renderModel.put("messages", templateMessages);

        renderModel.put("request", request);

        renderModel.put("response", context.getResponse());
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 setup script is recreated and checked if it is contained in
        // the headElement. This check cater for when the field is used by another
        // Control using the fly-weight pattern eg. FormTable.
        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("'");

            String id  = getId();

            // Include the field id as a parameter
            buffer.append(",{parameters: '").append(id).append("=1'");
View Full Code Here

     * CLK-373.
     */
    public void testContainerMessageInheritance() {
        MockContext.initContext(Locale.ENGLISH);

        Page page = new Page();
        MyForm form = new MyForm("myform");
        page.addControl(form);
        Field customField = form.getField("customField");
        Map<String, String> map = form.getMessages();
        assertFalse(map.isEmpty());
        assertTrue(map.size() >= 2);
        assertEquals("Custom Name", customField.getLabel());
View Full Code Here

        streetField.setValue("short");
        fs.add(streetField);
        form.add(fs);

        // Dummy onSubmitCheck to ensure submit check hiddenField is added by the Form
        form.onSubmitCheck(new Page(), "dummy.htm");

        Object state = form.getState();
        Map formStateMap = (Map) state;

        assertEquals(formStateMap.get(nameField.getName()), nameField.getValue());
View Full Code Here

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

        String expected = "Version 0.21";

        Page page = new Page();
        Field field = new TextField("field");
        page.addControl(field);

        String version = field.getMessage("version");
        System.out.println("V " + version);
        assertEquals(expected, version);
View Full Code Here

    public void testDuplicateOnSubmitCheck() {
        MockContext context = MockContext.initContext("test-form.htm");
        MockRequest request = context.getMockRequest();
        request.setParameter("form_name", "form");

        Page page = new Page();

        // Set the page to stateful
        page.setStateful(true);
        Form form = new Form("form");

        // Construct name of submit token
        String submitCheckName = Form.SUBMIT_CHECK + form.getName() + "_" + context.getResourcePath();
View Full Code Here

     */
    public void testOnSubmitCheckMissingParam() {
        MockContext context = MockContext.initContext("test-form.htm");
        MockRequest request = context.getMockRequest();
        request.setParameter("form_name", "form");
        Page page = new Page();
        Form form = new Form("form");

        // Construct name of submit token
        String submitTokenName = Form.SUBMIT_CHECK + form.getName() + "_" + context.getResourcePath();

View Full Code Here

        Map<String, String> map = ClickUtils.getParentMessages(textField);
        assertNotNull(map);
        assertTrue(map.isEmpty());
        assertTrue(map == Collections.EMPTY_MAP);
       
        Page page = new Page();
        page.addControl(textField);
       
        Map<String, String> map2 = ClickUtils.getParentMessages(textField);
        assertNotNull(map2);
        assertEquals(1, map2.size());
        assertFalse(map2 == Collections.EMPTY_MAP);
       
        Page page2 = new Page();
       
        Form form = new Form("form");
        page2.addControl(form);
       
        TextField textField2 = new TextField("test");
        form.add(textField2);

        Map<String, String> map3 = ClickUtils.getParentMessages(textField2);
View Full Code Here

        Context context = getContext();

        final HttpServletRequest request = context.getRequest();

        final Page page = ClickUtils.getParentPage(this);

        final Map<String, Object> renderModel = new HashMap<String, Object>(page.getModel());

        renderModel.putAll(getModel());

        if (hasAttributes()) {
            renderModel.put("attributes", getAttributes());
        } else {
            renderModel.put("attributes", Collections.EMPTY_MAP);
        }

        renderModel.put("this", this);

        renderModel.put("context", request.getContextPath());

        Format format = page.getFormat();
        if (format != null) {
            renderModel.put("format", format);
        }

        Map<String, String> templateMessages = new HashMap<String, String>(getMessages());
        templateMessages.putAll(page.getMessages());
        renderModel.put("messages", templateMessages);

        renderModel.put("request", request);

        renderModel.put("response", context.getResponse());
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.