--__--__--

Message: 3
Date: Tue, 17 Dec 2002 18:46:02 -0800
From: "Kirk Rasmussen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: [OS-webwork] Maintaining checkbox state in feedback loop
Reply-To: [EMAIL PROTECTED]

Hello everyone,
Please excuse this newbie question but I'm still coming up to speed on =
WW and I've run into a little problem with checkboxes.  There wasn't an =
example in the distribution that I could find for the following =
situation.

On my form I have the following:

<form action=3D"<webwork:url page=3D"foo.action"/>" method=3D"POST">
  <ui:textfield label=3D"'Email'" name=3D"'email'" maxlength=3D"100"/>
  <ui:textfield label=3D"'Confirm email'" name=3D"'confirmedEmail'" =
maxlength=3D"100"/>
  <ui:checkbox label=3D"'Check here to receive newsletter'" =
name=3D"'newsletter'" fieldValue=3D"true"/>
</form>

On initial load I want the checkbox to default to checked.  In my Action =
class I have:

    protected boolean newsletter =3D true;
    protected boolean promotions =3D true;

    public boolean getNewsletter()
    {
        System.err.println( "getNewsletter()" );
       =20
        return newsletter;
    }
   =20
    public void setNewsletter( boolean checked )
    {
        System.err.println( "setNewsletter()" );
       =20
        this.newsletter =3D checked;
    }

This works fine on initial load (foo!default.action) but fails on the =
POST feedback loop (e.g. user enters invalid e-mail address) if I =
deselect the newsletter checkbox.  The checkbox will stay checked =
because the internal state has already been set to true.

Since there is no parameter being passed to the WW dispatcher, =
setNewletter(false) will never get called, right?  How do I handle a =
"missing" parameter in WW???

Am I missing something?  =20

Thanks,
Kirk Rasmussen
Lucasfilm Ltd.

--__--__--

> Message: 4
> From: "Cameron Braid" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Subject: RE: [OS-webwork] Maintaining checkbox state in feedback loop
> Date: Wed, 18 Dec 2002 14:47:44 +1000
> Reply-To: [EMAIL PROTECTED]
> 
> I am not an expert on WW, though the normal way to deal with 'missing'
> http data is to set a default value for the property and it can be
> overridden by the request parameter...
> 
> i.e. if you set 
> 
> protected boolean newsletter = false;
> 
> instead of true, then WW will call the setNewsletter(true) when the
> checkbox is checked.
> 
> Cam
> 

But the problem is I want the default to be true.  I guess I
could have a hidden input value that set it to false so that
there is always at least one "newsletter" parameter passed to 
the action, though it seems sort of hackish to me since it 
has dependencies on the HTML form.

Is there a way to get the original parameter map?  I looked at
the code for ActionSupport and it doesn't look like the map gets 
saved.  I suppose I could get the HttpServletRequest and look for 
the parameter in there but it ties the action to the servlet API. 

Is there a way to deal with this in a more generic fashion?

Thanks,
Kirk Rasmussen
Lucasfilm Ltd.




-------------------------------------------------------
This SF.NET email is sponsored by: Order your Holiday Geek Presents Now!
Green Lasers, Hip Geek T-Shirts, Remote Control Tanks, Caffeinated Soap,
MP3 Players,  XBox Games,  Flying Saucers,  WebCams,  Smart Putty.
T H I N K G E E K . C O M       http://www.thinkgeek.com/sf/
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to