Package org.apache.click.control

Examples of org.apache.click.control.Form$ImmutableNameHiddenField


        map.put("age", null);
        map.put("address.street", null);
        map.put("address.state.code", null);

        // Setup the form and fields with initial values
        Form form = new Form("form");
        TextField idField = new TextField("id");
        idField.setValue(id.toString());
        form.add(idField);
       
        // Create fieldset
        FieldSet fieldset = new FieldSet("fieldset");
        form.add(fieldset);
        TextField nameField = new TextField("name");
        nameField.setValue(name);
        fieldset.add(nameField);
       
        TextField ageField = new TextField("age");
        ageField.setValue(age.toString());       
        form.add(ageField);
        TextField streetField = new TextField("address.street");
        streetField.setValue(street);
        form.add(streetField);
        TextField stateCodeField = new TextField("address.state.code");
        stateCodeField.setValue(stateCode);
        form.add(stateCodeField);

        // Copy the fields values back into the map
        form.copyTo(map, true);

        // Test that values were copied
        String copiedId = map.get("id").toString();
        assertEquals(id, new Integer(copiedId));
        assertEquals(name, map.get("name"));
View Full Code Here


        final String lineOne = "55 Dunkley Avenue";
        final String code = "NSW";
        final boolean active = false;
        final Boolean registered = Boolean.TRUE;
       
        Form form = new Form();
       
        TextField idField = new TextField("address.id");
        form.add(idField);
        TextField lineOneField = new TextField("address.lineOne");
        lineOneField.setValue(lineOne);
        form.add(lineOneField);
        Checkbox activeField = new Checkbox("address.active");
        activeField.setChecked(active);
        form.add(activeField);
        Checkbox registeredField = new Checkbox("address.registered");
        registeredField.setValueObject(registered);
        form.add(registeredField);
        TextField codeField = new TextField("address.state.code");
        codeField.setValue(code);
        form.add(codeField);
       
        User user = new User();       
        form.copyTo(user, true);
       
        assertNull(user.getAddress().getId());
        assertEquals(lineOne, user.getAddress().getLineOne());       
        assertEquals(active, user.getAddress().isActive());
        assertEquals(registered, user.getAddress().isRegistered());
View Full Code Here

        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 map3 = ClickUtils.getParentMessages(textField2);
        assertNotNull(map3);
        assertEquals(1, map3.size());
        assertFalse(map3 == Collections.EMPTY_MAP);       
View Full Code Here

     * Check that all input fields are retrieved from container.
     */
    public void testGetInputFields() {
        MockContext.initContext();
        // set up the form
        Form form = new Form("sample");

        // HiddenField should be included
        HiddenField hiddenField = new HiddenField("hidden", boolean.class);
        form.add(hiddenField);

        // TextField should be included
        TextField idField = new TextField("id");
        form.add(idField);

        // FieldSet should NOT be included
        FieldSet fieldset = new FieldSet("fieldset");
        form.add(fieldset);

        // Label should NOT be included
        Label label = new Label("name");
        form.add(label);

        // Button should NOT be included
        Button button = new Button("button");
        form.add(button);
       
        List fields = ContainerUtils.getInputFields(form);
       
        // Total should be 3 consisting of the fields "hidden", "id" and the
        // Forms internal HiddenFields "form_name".
View Full Code Here

        String price = "10.99";
        context.getMockRequest().setParameter("part.price", price);
        context.getMockRequest().setParameter("form_name", "form");

        // Setup form
        Form form = new Form("form");

        // Setup price field
        TextField priceField = new TextField("part.price");
        form.add(priceField);

        // Process form to bind request parameter to field
        form.onProcess();

        Car car = new Car();
        form.copyTo(car);

        assertEquals(price, priceField.getValue());
    }
View Full Code Here

     * cross-site scripting attacks (XSS).
     */
    public void testEscapeValue() {
        MockContext.initContext();

        Form form = new Form("form");
        CheckList checkList = new CheckList("check");
        form.add(checkList);

        String value = "<script>";
        String expected = "&lt;script&gt;";

        checkList.add(value);
View Full Code Here

    }

    public void testCopyFormToObject() {

      // set up the form
        Form form = new Form("sample");
       
        IntegerField idField = new IntegerField("id");
        form.add(idField);

        FieldSet fieldset = new FieldSet("fieldset");
        form.add(fieldset);

        TextField nameField = new TextField("name");
        fieldset.add(nameField);
       
        DateField dateField = new DateField("dateOfBirth");
        fieldset.add(dateField);
       
        IntegerField intField = new IntegerField("int");
        form.add(intField);

        DoubleField doubleField = new DoubleField("double");
        form.add(doubleField);
              
        Checkbox checkBox = new Checkbox("boolean");
        form.add(checkBox)
       
        LongField telephoneField = new LongField("telephone");
        form.add(telephoneField);
       
        HiddenField hidden = new HiddenField("hidden", String.class);
        form.add(hidden);

        // Populate fields
        idField.setValueObject(ID);
        nameField.setValue(NAME);
        dateField.setValueObject(DATE_OF_BIRTH);
        intField.setValue(String.valueOf(INT));
        doubleField.setValue(String.valueOf(DOUBLE));
        checkBox.setChecked(BOOLEAN);
        telephoneField.setValue(TELEPHONE);

        // copy form to object
        SampleObject sampleObject = new SampleObject();
        ClickUtils.copyFormToObject(form, sampleObject, true);

        // has the object been configured correctly?
        assertEquals(idField.getInteger(), sampleObject.getId());
        assertEquals(nameField.getValue(), sampleObject.getName());
        assertEquals(dateField.getValueObject(), sampleObject.getDateOfBirth());
        assertEquals(telephoneField.getValueObject().toString(), sampleObject.getTelephone());
        assertTrue(sampleObject.getInt() == intField.getInteger().intValue());
        assertTrue(sampleObject.getDouble() == doubleField.getDouble().doubleValue());
        assertTrue(sampleObject.isBoolean() == checkBox.isChecked());
       
        // Test object path copying
       
        User user = new User();
        user.setAddress(new Address());
        user.getAddress().setState(new State());
       
        form = new Form();
        TextField codeField = new TextField("address.state.code");
        codeField.setValue("NSW");
        form.add(codeField);
        form.copyTo(user, true);
        assertEquals("NSW", user.getAddress().getState().getCode());
    }
View Full Code Here

        assertEquals("NSW", user.getAddress().getState().getCode());
    }

    public void testCopyObjectToForm() {
        // set up the form
        Form form = new Form("sample");
       
        IntegerField idField = new IntegerField("id");
        form.add(idField);

        FieldSet fieldset = new FieldSet("fieldset");
        form.add(fieldset);

        TextField nameField = new TextField("name");
        fieldset.add(nameField);
       
        DateField dateField = new DateField("dateOfBirth");
        fieldset.add(dateField);
       
        IntegerField intField = new IntegerField("int");
        form.add(intField);
               
        DoubleField doubleField = new DoubleField("double");
        form.add(doubleField);
              
        Checkbox checkBox = new Checkbox("boolean");
        form.add(checkBox);
       
        HiddenField hidden = new HiddenField("hidden", String.class);
        form.add(hidden);
       
        // Populate object
        SampleObject sampleObject = new SampleObject();
        sampleObject.setId(ID);
        sampleObject.setName(NAME);
        sampleObject.setDateOfBirth(DATE_OF_BIRTH);
        sampleObject.setInt(INT);
        sampleObject.setDouble(DOUBLE);
        sampleObject.setBoolean(BOOLEAN);

        // copy object to form
        ClickUtils.copyObjectToForm(sampleObject, form, true);

        // has the form been configured correctly?
        assertEquals(sampleObject.getId(), idField.getInteger());
        assertEquals(sampleObject.getName(), nameField.getValue());
        assertEquals(sampleObject.getDateOfBirth(), dateField.getDate());
        assertTrue(sampleObject.getInt() == intField.getInteger().intValue());
        assertTrue(sampleObject.getDouble() == doubleField.getDouble().doubleValue());
        assertTrue(sampleObject.isBoolean() == checkBox.isChecked());
       
        // Test object path copying
       
        User user = new User();
        user.setAddress(new Address());
        user.getAddress().setState(new State());
        user.getAddress().getState().setCode("NSW");
       
        form = new Form();
        TextField codeField = new TextField("address.state.code");
        form.add(codeField);
        form.copyFrom(user, true);
        assertEquals("NSW", codeField.getValueObject());
       
        Map map = new HashMap();
        map.put("name", "malcolm");
        form = new Form();
        TextField nameField2 = new TextField("name");
        form.add(nameField2);
        form.copyFrom(map, true);
        assertEquals("malcolm", nameField2.getValue());
    }
View Full Code Here

        final String lineOne = "55 Dunkley Avenue";
        final String code = "NSW";
        final boolean active = false;
        final Boolean registered = Boolean.TRUE;
       
        Form form = new Form();
       
        IntegerField idField = new IntegerField("address.id");
        form.add(idField);
        TextField lineOneField = new TextField("address.lineOne");
        lineOneField.setValue(lineOne);
        form.add(lineOneField);
        Checkbox activeField = new Checkbox("address.active");
        activeField.setChecked(active);
        form.add(activeField);
        Checkbox registeredField = new Checkbox("address.registered");
        registeredField.setValueObject(registered);
        form.add(registeredField);
        TextField codeField = new TextField("address.state.code");
        codeField.setValue(code);
        form.add(codeField);
       
        User user = new User();       
        form.copyTo(user, true);
       
        assertNull(user.getAddress().getId());
        assertEquals(lineOne, user.getAddress().getLineOne());       
        assertEquals(active, user.getAddress().isActive());
        assertEquals(registered, user.getAddress().isRegistered());
View Full Code Here

        assertEquals(1, StringUtils.countMatches(imports, "/control.js"));
        assertEquals(1, StringUtils.countMatches(imports, "/control.css"));


        // Check imports using an external Form Control
        Form form = new Form("form");
        table = new FormTable("table", form);
        form.add(table);

        imports = form.getHtmlImports();
        assertEquals(1, StringUtils.countMatches(imports, "/table.css"));
        assertEquals(1, StringUtils.countMatches(imports, "/control.js"));
        assertEquals(1, StringUtils.countMatches(imports, "/control.css"));
    }
View Full Code Here

TOP

Related Classes of org.apache.click.control.Form$ImmutableNameHiddenField

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.