Form components that become visible during submit always set their model to null
--------------------------------------------------------------------------------

                 Key: WICKET-3171
                 URL: https://issues.apache.org/jira/browse/WICKET-3171
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.4.9
         Environment: Mac OS X 10.6.4 running Java 1.6.0_22
            Reporter: Jesse Barnum


It seems that non-visible components initially have a convertedValue of null. 
If they become visible during the form submit processing, they will write this 
null value to their model. This can lead to data loss or exceptions.

For example, with this sample code, if the checkbox to make the the 'name' and 
'age' fields visible is checked, null values are written to the data object 
when the form is submitted.

====
package com.prosc.test;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;

public class FormVisibilityTest extends WebPage {
        private SampleBean bean = new SampleBean();
        
        public FormVisibilityTest() {
                Form<SampleBean> form = new Form("form", new 
CompoundPropertyModel(bean) );
                add(form);
                form.add( new CheckBox("showName" ) );
                WebMarkupContainer nameSection = new WebMarkupContainer( 
"nameSection" ) {
                        public boolean isVisible() {
                                //return true; //If everything is visible, 
values are pulled from default SampleBean values and everything works as 
expected
                                return bean.isShowName(); //If visibility 
starts off false when the form is initially submitted but then becomes true 
during the submit process,  null values are submitted to the model
                        }
                };
                form.add( nameSection );
                nameSection.add( new TextField( "name" ) );
                nameSection.add( new TextField( "age" ) );
        }
}


===


package com.prosc.test;

import java.io.Serializable;

public class SampleBean implements Serializable {
        private boolean showName = false;
        private String name = "John";
        private int age = 34;

        public boolean isShowName() {
                return showName;
        }

        public void setShowName( boolean showName ) {
                this.showName = showName;
        }

        public String getName() {
                return name;
        }

        public void setName( String name ) {
                this.name = name;
        }

        public int getAge() {
                return age;
        }

        public void setAge( int age ) {
                this.age = age;
        }
}

====


<html>
<body>
<form wicket:id="form" action="#">
        <p>
                <input type="checkbox" wicket:id="showName">Is name section 
visible?
        </p>

        <p>
        <span wicket:id="nameSection">
                Name: <input type="text" wicket:id="name" value="Bob"><br>
                Age: <input type="text" wicket:id="age" value="25">
        </span>
        </p>
        
        <p><input type="submit"></p>
</form>
</body>
</html>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to