You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Colman <ch...@stepaheadsoftware.com> on 2007/11/01 22:37:39 UTC

Preserving user input after form error

I've created a form and set up some validators on various fields. When
there is an error and the page is redisplayed showing the errors none of
the previous values that the user typed in are there.

Is there an easy way to preserve the values already entered by the user?

I tried overriding onError but it didn't seem to do get it working:

public final void onError()
{
	// update model fields so the user doesn't have to type them in
again
	// -> I was hoping that the next page render would get these 
	//    values from the updated model
	updateFormComponentModels();
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Ok, I'll do that. The problem probably won't happen in the quickstart
form ;)

> 
> why dont you submit a quickstart and then we can figure out why its
> happening
> 
> -igor
> 
> 
> On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > Could it be because the form page is bookmarkable?
> >
> > > thats odd, all the values should be preserved, thats our rawinput
that
> > > all formcomponents have. Do you have a repeater/listview around
your
> > > formcomponents.
> > >
> > > On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > > I've created a form and set up some validators on various
fields.
> > When
> > > > there is an error and the page is redisplayed showing the errors
> > none of
> > > > the previous values that the user typed in are there.
> > > >
> > > > Is there an easy way to preserve the values already entered by
the
> > user?
> > > >
> > > > I tried overriding onError but it didn't seem to do get it
working:
> > > >
> > > > public final void onError()
> > > > {
> > > >     // update model fields so the user doesn't have to type them
in
> > > > again
> > > >     // -> I was hoping that the next page render would get these
> > > >     //    values from the updated model
> > > >     updateFormComponentModels();
> > > > }
> > > >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Martijn Dashorst <ma...@gmail.com>.
http://wicket.apache.org/quickstart.html

On 11/3/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> Is there a page with guidelines on making a wicket quickstart?
>
> > why dont you submit a quickstart and then we can figure out why its
> > happening
> >
> > -igor
> >
> >
> > On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > Could it be because the form page is bookmarkable?
> > >
> > > > thats odd, all the values should be preserved, thats our rawinput
> that
> > > > all formcomponents have. Do you have a repeater/listview around
> your
> > > > formcomponents.
> > > >
> > > > On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > > > I've created a form and set up some validators on various
> fields.
> > > When
> > > > > there is an error and the page is redisplayed showing the errors
> > > none of
> > > > > the previous values that the user typed in are there.
> > > > >
> > > > > Is there an easy way to preserve the values already entered by
> the
> > > user?
> > > > >
> > > > > I tried overriding onError but it didn't seem to do get it
> working:
> > > > >
> > > > > public final void onError()
> > > > > {
> > > > >     // update model fields so the user doesn't have to type them
> in
> > > > > again
> > > > >     // -> I was hoping that the next page render would get these
> > > > >     //    values from the updated model
> > > > >     updateFormComponentModels();
> > > > > }
> > > > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta4/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Is there a page with guidelines on making a wicket quickstart?

> why dont you submit a quickstart and then we can figure out why its
> happening
> 
> -igor
> 
> 
> On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > Could it be because the form page is bookmarkable?
> >
> > > thats odd, all the values should be preserved, thats our rawinput
that
> > > all formcomponents have. Do you have a repeater/listview around
your
> > > formcomponents.
> > >
> > > On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > > I've created a form and set up some validators on various
fields.
> > When
> > > > there is an error and the page is redisplayed showing the errors
> > none of
> > > > the previous values that the user typed in are there.
> > > >
> > > > Is there an easy way to preserve the values already entered by
the
> > user?
> > > >
> > > > I tried overriding onError but it didn't seem to do get it
working:
> > > >
> > > > public final void onError()
> > > > {
> > > >     // update model fields so the user doesn't have to type them
in
> > > > again
> > > >     // -> I was hoping that the next page render would get these
> > > >     //    values from the updated model
> > > >     updateFormComponentModels();
> > > > }
> > > >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Igor Vaynberg <ig...@gmail.com>.
why dont you submit a quickstart and then we can figure out why its happening

-igor


On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> Could it be because the form page is bookmarkable?
>
> > thats odd, all the values should be preserved, thats our rawinput that
> > all formcomponents have. Do you have a repeater/listview around your
> > formcomponents.
> >
> > On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > I've created a form and set up some validators on various fields.
> When
> > > there is an error and the page is redisplayed showing the errors
> none of
> > > the previous values that the user typed in are there.
> > >
> > > Is there an easy way to preserve the values already entered by the
> user?
> > >
> > > I tried overriding onError but it didn't seem to do get it working:
> > >
> > > public final void onError()
> > > {
> > >     // update model fields so the user doesn't have to type them in
> > > again
> > >     // -> I was hoping that the next page render would get these
> > >     //    values from the updated model
> > >     updateFormComponentModels();
> > > }
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Could it be because the form page is bookmarkable?

> thats odd, all the values should be preserved, thats our rawinput that
> all formcomponents have. Do you have a repeater/listview around your
> formcomponents.
> 
> On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > I've created a form and set up some validators on various fields.
When
> > there is an error and the page is redisplayed showing the errors
none of
> > the previous values that the user typed in are there.
> >
> > Is there an easy way to preserve the values already entered by the
user?
> >
> > I tried overriding onError but it didn't seem to do get it working:
> >
> > public final void onError()
> > {
> > 	// update model fields so the user doesn't have to type them in
> > again
> > 	// -> I was hoping that the next page render would get these
> > 	//    values from the updated model
> > 	updateFormComponentModels();
> > }
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
> what servlet container are you using? i think this problem popped up
> on weblogic before and was due to a combination of a weblogic bug and
> the particular servlet mapping that was used.

Tomcat 5.5.20

> 
> does the behavior happen to all form components or just some
> particular one?

All components don't preserve their values.

> try it without that funky onerror() override.

I commented out the funky onerror() override and the problem still
exists.

Hmmmm, getting curiouser and curiouser!

> 
> -igor
> 
> On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > > can you make sure your servlet mapping is of form /foo/*
> > >
> > > -igor
> >
> > Yes it's of that form.
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Igor Vaynberg <ig...@gmail.com>.
what servlet container are you using? i think this problem popped up
on weblogic before and was due to a combination of a weblogic bug and
the particular servlet mapping that was used.

does the behavior happen to all form components or just some
particular one? try it without that funky onerror() override.

-igor

On 11/2/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > can you make sure your servlet mapping is of form /foo/*
> >
> > -igor
>
> Yes it's of that form.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
> can you make sure your servlet mapping is of form /foo/*
> 
> -igor

Yes it's of that form.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Igor Vaynberg <ig...@gmail.com>.
can you make sure your servlet mapping is of form /foo/*

-igor


On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > i dont know what goes wrong then for you because  if i test this:
> >
> > http://wicketstuff.org/wicket12/forminput/
> >
> > that that works fine. If you make a validation error on 1 the rest
> keep
> > there values.
>
>
> The only difference I can see so far is that my form page is an
> 'extended' page where the form component is added in mark up inside a
>
> <wicket:extend>
>         ... form sits in here ...
> </wicket:extend>
>
> construct.
>
>
> > On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> > >
> > > Oh yeah, I'm using Wicket 1.2.6 if that has any bearing on the
> > > situation.
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
> i dont know what goes wrong then for you because  if i test this:
> 
> http://wicketstuff.org/wicket12/forminput/
> 
> that that works fine. If you make a validation error on 1 the rest
keep
> there values.


The only difference I can see so far is that my form page is an
'extended' page where the form component is added in mark up inside a

<wicket:extend>
	... form sits in here ...
</wicket:extend>

construct. 

 
> On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> >
> > Oh yeah, I'm using Wicket 1.2.6 if that has any bearing on the
> > situation.
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Johan Compagner <jc...@gmail.com>.
i dont know what goes wrong then for you because  if i test this:

http://wicketstuff.org/wicket12/forminput/

that that works fine. If you make a validation error on 1 the rest keep
there values.




On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
>
> Oh yeah, I'm using Wicket 1.2.6 if that has any bearing on the
> situation.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Oh yeah, I'm using Wicket 1.2.6 if that has any bearing on the
situation.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Fri, 02 Nov 2007, Chris Colman wrote:
>       private String captchaInput = new String("fred");

private String captchaInput = "fred";

> 	public final void onError()
> 	{
> 		super.onError();
> 			
> 		// update model fields so the user doesn't have to 
> 		// type them in again
> 		updateFormComponentModels();
> 		refreshCapture();
> 	}

This is suspicious.

If I understand correctly, Wicket manipulates form component
input via three diffferent phases:

  1) raw input: directly from the HTTP request
  2) converted input: raw input converted to objects
  3) model: converted input set to models of FormComponents

onError might get called before raw input could be converted,
for example when entering text to an HTML field bound to a 
numeric java field. And if you then update the model values
from (empty) converted input, the HTML input fields might 
display the new, empty values instead of the preserved 
raw input.

I might be wrong as welll and suggest you to dig in the source
code and/or debug to see what really happens.

Best wishes,
Timo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Preserving user input after form error

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
> thats odd, all the values should be preserved, thats our rawinput that
> all formcomponents have. Do you have a repeater/listview around your
> formcomponents.
> 

Hmmm, I don't know why my form doesn't preserve it. Here's the source of
the form. Can you spot anything that I'm doing wrong?

// -[KeepHeading]-


// -[Copyright]-

/**
 * (c) 2007. Step Ahead Software. All rights reserved.
 * 
 * Source file created and managed by Javelin (TM) Step Ahead Software.
 * To maintain code and model synchronization you may directly edit code
in method bodies
 * and any sections starting with the 'Keep_*' marker. Make all other
changes via Javelin.
 * See http://stepaheadsoftware.com for more details.
 */
package com.sas.av.ui.wicket.templates.original;

import java.lang.*;
import com.sas.av.ui.wicket.templates.original.StandardPage;
    
import com.sas.av.model.context.EServerContext;


// -[KeepBeforeClass]-
import com.sas.av.ui.wicket.templates.*;

import wicket.PageParameters;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.*;
import wicket.markup.html.panel.*;
import wicket.util.string.*;
import wicket.model.*;

import wicket.model.PropertyModel;

import wicket.markup.html.image.*;
import wicket.extensions.markup.html.captcha.*;

import java.lang.*;
import java.util.Random;



// -[Class]-

/**
 * Information Request Page.
 * 
 * @author Chris Colman
 */
public 
class InformationRequestPage extends StandardPage
{
// -[KeepWithinClass]-


    // inner class form:	

    public final class InformationRequestForm extends Form
    {
      private final InformationRequest infoRequest =
		new InformationRequest();

	// CAPTCHA Challenge
      private String captchaValue = generateCaptchaValue();
      private String captchaInput = new String("fred");
	public String getCaptchaInput() {return captchaInput;}
	public void setCaptchaInput(String iCaptchaInput)
		{ captchaInput = iCaptchaInput; }
      public String generateCaptchaValue()
		{ return
Integer.toString(random.nextInt(2000000)+1000000); }
	private Image captchaImage = new Image("captchaImage");
	private CaptchaValidator captchaValidator;

      public InformationRequestForm(final String iId)
      {
      	super(iId);

		add(new TextArea("name", new PropertyModel(infoRequest,
"name")).setRequired(true));
		add(new TextArea("company", new
PropertyModel(infoRequest, "company")));
		add(new TextArea("phone", new PropertyModel(infoRequest,
"phone")));
		add(new TextArea("email", new PropertyModel(infoRequest,
"email")).setRequired(true));
		add(new TextArea("comments", new
PropertyModel(infoRequest, "comments")));

		TextField captchaField = new TextField("captcha", new
PropertyModel(this, "captchaInput"));
		captchaValidator = new CaptchaValidator(captchaValue);
		captchaField.add(captchaValidator);
		add(captchaField);
             
		refreshCapture();
		add(captchaImage);
        }

	public final void onError()
	{
		super.onError();
			
		// update model fields so the user doesn't have to 
		// type them in again
		updateFormComponentModels();
		refreshCapture();
	}
		
	public void refreshCapture()
	{
		captchaValue = generateCaptchaValue();			
		CaptchaImageResource captchaImageResource = new
CaptchaImageResource(captchaValue, 80, 5); 
		captchaImage.setImageResource(captchaImageResource);
		captchaValidator.setCaptchaValue(captchaValue);
	}
	

	public final void onSubmit()
      {
		StringBuffer sb = new StringBuffer();
		sb.append("Name " + infoRequest.getName());

		PageParameters pageParameters = new PageParameters();
	
		// set up parameters
		...
			
		setResponsePage(
			InformationRequestAckPage.class,
pageParameters);
     }
}


// -[Fields]-



/**
 * A random object!
 */
public static transient Random random = new Random();


// -[Methods]-




/**
 * Constructs the object
 */
public InformationRequestPage()



{
}

/**
 * 
 */
public InformationRequestPage(final PageParameters parameters)
  throws StringValueConversionException
{
	super(parameters);
	
	add(new FeedbackPanel("feedback"));
	add(new InformationRequestForm("informationRequest"));
}

}



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Preserving user input after form error

Posted by Johan Compagner <jc...@gmail.com>.
thats odd, all the values should be preserved, thats our rawinput that
all formcomponents have. Do you have a repeater/listview around your
formcomponents.

On 11/1/07, Chris Colman <ch...@stepaheadsoftware.com> wrote:
> I've created a form and set up some validators on various fields. When
> there is an error and the page is redisplayed showing the errors none of
> the previous values that the user typed in are there.
>
> Is there an easy way to preserve the values already entered by the user?
>
> I tried overriding onError but it didn't seem to do get it working:
>
> public final void onError()
> {
> 	// update model fields so the user doesn't have to type them in
> again
> 	// -> I was hoping that the next page render would get these
> 	//    values from the updated model
> 	updateFormComponentModels();
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org