You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Jesse Barnum (JIRA)" <ji...@apache.org> on 2010/11/15 13:52:13 UTC

[jira] Created: (WICKET-3171) Form components that become visible during submit always set their model to null

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.


[jira] Assigned: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg reassigned WICKET-3171:
-------------------------------------

    Assignee: Igor Vaynberg

> 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
>            Assignee: Igor Vaynberg
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Updated: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Jesse Barnum (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Barnum updated WICKET-3171:
---------------------------------

    Description: 
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.

I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 

====
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>


  was:
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>



Added suggestion for how to fix

> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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.


[jira] Updated: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Jesse Barnum (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Barnum updated WICKET-3171:
---------------------------------

    Description: 
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.

I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 

====
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>


=======

package com.prosc.test;

import org.apache.wicket.util.tester.WicketTester;
import junit.framework.TestCase;

public class FormVisibilityTestcase extends TestCase {
	public void testSubmit() {
		WicketTester tester = new WicketTester();
		tester.startPage( FormVisibilityTest.class );
		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
	}
}


  was:
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.

I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 

====
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>



Added test case

> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Resolved: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-3171.
-----------------------------------

    Resolution: Invalid

> 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
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Commented: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12964795#action_12964795 ] 

Igor Vaynberg commented on WICKET-3171:
---------------------------------------

@douglas: i would say it is evil in 95% of situations. isvisible() is not final because onconfigure() was added recently and there is still the rare 5% usecase where you have a valid reason to override isvisible().

> 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
>            Assignee: Igor Vaynberg
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Updated: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Jeremy Thomerson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeremy Thomerson updated WICKET-3171:
-------------------------------------

    Fix Version/s:     (was: 1.5-M4)
                       (was: 1.4.14)

Removing fix versions on things that were marked as fixVersion = (1.4.14 || 1.5-M4), but also weren't fixed (marked "not a problem", "won't fix", etc) so that they don't show up in release notes when in reality they weren't part of the release.

> 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
>            Assignee: Igor Vaynberg
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Commented: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Douglas Ferguson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12964785#action_12964785 ] 

Douglas Ferguson commented on WICKET-3171:
------------------------------------------

Are you saying that overriding isVisible() is evil in all situations or just for form components.. We do this al over the place. If it is so evil then why isn't the method final?

> 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
>            Assignee: Igor Vaynberg
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Commented: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Jesse Barnum (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932076#action_12932076 ] 

Jesse Barnum commented on WICKET-3171:
--------------------------------------

Right, clearly, Wicket cannot magically do something with inputs that it never receives from the browser - what I am expecting though, is that Wicket should not try to update the non-visible form component models with invalid data if they become visible as a side effect of processing other (visible) components on the form.

> 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
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Commented: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932106#action_12932106 ] 

Igor Vaynberg commented on WICKET-3171:
---------------------------------------

instead of overriding isvisible() override onconfigure() and toggle visibility there based on checkbox's model. overriding isvisible() is evil, it can change values in the middle of traversals, etc.

> 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
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Reopened: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Martin Grigorov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Grigorov reopened WICKET-3171:
-------------------------------------


Now it is more clear what you mean.

> 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
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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


[jira] Closed: (WICKET-3171) Form components that become visible during submit always set their model to null

Posted by "Martin Grigorov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Grigorov closed WICKET-3171.
-----------------------------------

       Resolution: Not A Problem
    Fix Version/s: 1.5-M4
                   1.4.14

It is not Wicket form processing behavior. It is normal behavior of the html <form> - all form elements which are invisible (display: none) or disabled do not submit their values. I.e. Wicket cannot read values for them in the request parameters because there is nothing for these elements.

> 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
>             Fix For: 1.4.14, 1.5-M4
>
>
> 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.
> I'm not that familiar with the Wicket form processing internals, but it seems to me that the solution is to gather a list of all visible components before processing any of them, and then iterate through that list, ignoring new components (with invalid state) that become visible. 
> ====
> 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>
> =======
> package com.prosc.test;
> import org.apache.wicket.util.tester.WicketTester;
> import junit.framework.TestCase;
> public class FormVisibilityTestcase extends TestCase {
> 	public void testSubmit() {
> 		WicketTester tester = new WicketTester();
> 		tester.startPage( FormVisibilityTest.class );
> 		tester.setParameterForNextRequest( "form:showName", Boolean.TRUE );
> 		tester.submitForm( "form" ); //This causes an exception because it tries to submit a null value to a setter that expects an int primitive for 'age'
> 		//org.apache.wicket.util.convert.ConversionException: Can't convert null value to a primitive class: int for setting it on com.prosc.test.SampleBean@5289e2f1
> 	}
> }

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