Package org.apache.click.control

Examples of org.apache.click.control.Form


        Panel panel1 = new Panel("panel1", "panel/tabbed/panel1.htm");
        tabbedPanel.add(panel1);

        Panel panel2 = new Panel("panel2", "panel/tabbed/form-panel2.htm");
        Form form = new Form("form");
        panel2.add(form);

        // PLEASE NOTE: Form is addedd to the second Panel(at index 1), so when it
        // posts to the server it needs to send the index of it's own Panel so that the
        // TabbedPanel activates that Panel actives Panel at index 1. If we don't
        // cater for this, the form post will be handled by the Panel at index 0

        // When TabbedPanel detects the request Parameter 'tabPanelIndex', it
        // switches to the Panel at the given index.
        // we add a HiddenField called 'tabPanelIndex' set to index 1.
        //
        int tabIndex = 1;
        form.add(new HiddenField("tabPanelIndex", tabIndex));

        final TextField field = new TextField("name", "Enter your name");
        form.add(field);
        Submit submit = new Submit("go");
        submit.setActionListener(new ActionListener() {

            public boolean onAction(Control source) {
                addModel("msg", "Hi " + field.getValue() + ". Your form has been saved!");
                return true;
            }
        });
        form.add(submit);
        panel2.setLabel("The Second Panel");
        tabbedPanel.add(panel2);

        Panel panel3 = new Panel("panel3", "panel/tabbed/table-panel3.htm");
        Table table = new Table("table");
View Full Code Here


    public void demo1() {
        // Create a submit link.
        final SubmitLink submitLink = new SubmitLink("save");

        Form form = new Form("demo1");
        addControl(form);

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

        fieldSet.add(new TextField("name"));

        // Add the submit link to the fieldSet
        fieldSet.add(submitLink);
View Full Code Here

    public void demo2() {
        // Create a submit link which includes parameters.
        final SubmitLink paramLink = new SubmitLink("paramLink");

        Form form = new Form("demo2");
        addControl(form);

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

        fieldSet.add(new TextField("name"));

        // Add some parameters to the parametrized submit link
        paramLink.setValue("myValue");
View Full Code Here

    public void demo4() {
        // Create a submit link
        final SubmitLink confirmationLink = new SubmitLink("confirmationLink");

        Form form = new Form("demo4");
        addControl(form);

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

        fieldSet.add(new TextField("name"));

        // Add the submit link to the FieldSet
        fieldSet.add(confirmationLink);

        // Set custom JavaScript for the onclick event. The confirmSubmit function
        // is defined in the page template -> submit-link-demo.htm
        String clickEvent = "return confirmSubmit(this, '" + form.getId() + "', 'Are you sure?');";
        confirmationLink.setOnClick(clickEvent);

        // The Parametrized SubmitLink action listener
        confirmationLink.setActionListener(new ActionListener() {
View Full Code Here

    private static final long serialVersionUID = 1L;

    public ControlHeadDemo() {

        Form form = new Form("form");

        StarRating rating = new StarRating("rating", 5, 2);
        form.add(rating);

        form.add(new Submit("save"));

        addControl(form);
    }
View Full Code Here

     * Sanity checks for ClickUtils.copyFormToObject.
     */
    public void testCopyFormToObject() {

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

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

        TextField nameField = new TextField("name");
        fieldset.add(nameField);

        TextField dateField = new TextField("dateOfBirth");
        fieldset.add(dateField);
       
        TextField intField = new TextField("int");
        form.add(intField);

        TextField doubleField = new TextField("double");
        form.add(doubleField);
              
        Checkbox checkBox = new Checkbox("boolean");
        form.add(checkBox)
       
        TextField telephoneField = new TextField("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(new Integer(idField.getValue()), sampleObject.getId());
        assertEquals(nameField.getValue(), sampleObject.getName());
       
        //NOTE the dateField was NOT copied to the sampleObject's Date property.
        //Use org.apache.click.extras.control.DateField in the extras project, to
        //copy a Date property.
        assertEquals(null, sampleObject.getDateOfBirth());
        assertEquals(telephoneField.getValueObject().toString(), sampleObject.getTelephone());
        assertTrue(sampleObject.getInt() == new Integer(intField.getValue()).intValue());
        assertTrue(sampleObject.getDouble() == new Double(doubleField.getValue()).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

    /**
     * Sanity checks for ClickUtils.copyObjectToForm.
     */
    public void testCopyObjectToForm() {
        // set up the form
        Form form = new Form("sample");
       
        TextField idField = new TextField("id");
        form.add(idField);

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

        TextField nameField = new TextField("name");
        fieldset.add(nameField);
       
        TextField dateField = new TextField("dateOfBirth");
        fieldset.add(dateField);
       
        TextField intField = new TextField("int");
        form.add(intField);
               
        TextField doubleField = new TextField("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(), new Integer(idField.getValue()));
        assertEquals(sampleObject.getName(), nameField.getValue());
        assertEquals(sampleObject.getDateOfBirth().toString(), dateField.getValue());
        assertTrue(sampleObject.getInt() == new Integer(intField.getValue()).intValue());
        assertTrue(sampleObject.getDouble() == new Double(doubleField.getValue()).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<String, Object> map = new HashMap<String, Object>();
        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

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

        // Setup the form and fields
        Form form = new Form("form");
        TextField idField = new TextField("id");
        form.add(idField);

        // Create fieldset
        FieldSet fieldset = new FieldSet("fieldset");
        form.add(fieldset);
        TextField nameField = new TextField("name");
        fieldset.add(nameField);

        TextField ageField = new TextField("age");
        form.add(ageField);
        TextField streetField = new TextField("address.street");
        form.add(streetField);
        TextField stateCodeField = new TextField("address.state.code");
        form.add(stateCodeField);

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

        // Test that values were copied
        assertEquals(id, new Integer(idField.getValue()));
        assertEquals(name, nameField.getValue());
        assertEquals(age, new Integer(ageField.getValue()));
View Full Code Here

        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

TOP

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

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.