You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by William Lee <wl...@sendmail.com> on 2002/10/14 18:09:13 UTC

Wrong value disappeared when an Intake rule is violated

I'm currently using the non-fulcrum Intake service with Turbine 2.2b3. 
One thing that I realized is that when a specific value is violating a 
rule specified in intake.xml, the wrong value is reset to an empty 
string (or null, I don't remember).   This happens as soon as the init() 
function of the IntakeTool when a request comes in, even before you call 
isAllValid().  When going back to the page that contains the error, the 
proper error message associated with the rule is displayed, but the 
value is resetted instead of displaying the wrong value as a result. 
This of course, somewhat defeats the purpose of using Intake.

Is there any way that I can resolve this?

-- 
William Lee (Will)        | Sendmail Inc.
Email:  wlee@sendmail.com | http://www.sendmail.com
Tel:    (510) 594-5505    |


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Wrong value disappeared when an Intake rule is violated

Posted by Rodney Schneider <ro...@actf.com.au>.
On Tue, 15 Oct 2002 02:09, you wrote:
> I'm currently using the non-fulcrum Intake service with Turbine 2.2b3.
> One thing that I realized is that when a specific value is violating a
> rule specified in intake.xml, the wrong value is reset to an empty
> string (or null, I don't remember).   This happens as soon as the init()
> function of the IntakeTool when a request comes in, even before you call
> isAllValid().  When going back to the page that contains the error, the
> proper error message associated with the rule is displayed, but the
> value is resetted instead of displaying the wrong value as a result.
> This of course, somewhat defeats the purpose of using Intake.
>
> Is there any way that I can resolve this?

I've never noticed this before... but I am only just migrating to TDK 2.2b3 
now.  If you provide small snippets of the relevant section of your action 
and screen/template code, I could have a look to see if you are doing 
anything out of the ordinary.

-- Rodney

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Intake and carrying around data / data validation

Posted by Pat Ryan <pr...@cardean.edu>.
Thanks Scott - a follow up clarification for you or anyone else that may be able to
help.

We understand that Intake leaves data in the request (RunData in our case) so
that our Action class can do something with the data.  Every example we have
seen has an action class with code that is basically:

if (valid data)
        setTemplate(show a success template)
else (it is invalid data)
        setTemplate(reshow the form we are processing)

Our flow looks more like...

if (valid data)
        save the valid data in the session
        redirect to a bookmarkable URL for a different page
else (if invalid data)
        save the invalid data in the session
        redirect to a bookmarkable URL for the original form we are processing

By 'bookmarkable URL', we mean something like:

   machine:8080/turbine?param1=foo&param2=bar

Versus the URL that you have after a form POST submission normally is just:
   machine:8080/turbine

Has anybody else come up with a good methodology for handling POST submissions
and ending up at a bookmarkable URL?

Our flow outlined above depends on being able to save the valid or invalid data
from one request to another, which so far is proving to be not easy with Intake,
because Intake likes to recycle the Groups/Fields/IntakeTool objects between
requests.  (Which is great for avoiding object creation/gc, but not great when
we want to keep one of the Groups/Fields/IntakeTool objects around for a later
request...)

Ideas?

Pat, Erich, et al


Scott Eade wrote:

> Intake does leave the data in the request - this allows for the page to be
> redisplayed if you detect an error and return to the same page.
>
> The data is stored in the request within the group used on the data entry
> page.  Are you attempting to use this same group on the subsequent page?
>
> A normal turbine based application would follow these steps:
> 1. User enters data on page
> 2. Action validates data, if invalid return to input page, if valid save the
> data to the database and tell turbine to go to the next page
> 3. Next page re-retrieves the data from the database for display (outside of
> the context of intake).
>
> HTH,
>
> Scott
> --
> Scott Eade
> Backstage Technologies Pty. Ltd.
> http://www.backstagetech.com.au
>
> > From: "Pat Ryan" <pr...@cardean.edu>
> > Reply-To: "Turbine Users List" <tu...@jakarta.apache.org>
> > Date: Tue, 15 Oct 2002 17:33:36 -0500
> > To: Turbine Users List <tu...@jakarta.apache.org>
> > Subject: Intake and carrying around data / data validation
> >
> >
> > Hello Intake Wizards! :-)
> >
> > We are using Intake (or trying to) in our web application that is
> > Jetspeed-based, and therefore has Turbine, Intake, etc for free because they
> > come with Jetspeed...
> >
> > We are trying to understand how to properly use Intake for data validation.
> > The
> > basic problem we are having is that there does not seem to be any way to
> > 'carry
> > forward' Intake data from one request to another, or from one page to another.
> >
> > For example, how about a form that you fill in a few fields, and submit it,
> > and
> > then a 'form' Action class wants to save the data you submitted into the
> > session
> > and redirect you to a different URL where a 'view' Action class will pull the
> > saved data out of the session, and put it into the context so that a velocity
> > template can render it.
> >
> > Problems that come up include...
> > * We tried saving the IntakeTool itself from request to request, since it
> > contains the Groups & Fields, but the Pull service wants to recycle it after
> > each request so it works once and then the data goes away
> > * We tried to pull our intake Group out of the IntakeTool and carry that
> > forward, but IntakeTool.removeGroup() recycles the Group, which blows the data
> > away
> >
> > Our last idea was to make a business object and do the
> > mapToObject/setProperties
> > thing, but that craps out when a form is submitted with invalid data, because
> > formGroup.setProperties(bizObj) throws an exception when trying to set the
> > values from formGroup into the bizObj.
> >
> > So.
> >
> > Has anybody figured out how to use Intake with a lifespan of longer than a
> > single request?  Thanks!!!
> >
> > Pat, Erich, et al
> >
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Intake and carrying around data / data validation

Posted by Scott Eade <se...@backstagetech.com.au>.
Intake does leave the data in the request - this allows for the page to be
redisplayed if you detect an error and return to the same page.

The data is stored in the request within the group used on the data entry
page.  Are you attempting to use this same group on the subsequent page?

A normal turbine based application would follow these steps:
1. User enters data on page
2. Action validates data, if invalid return to input page, if valid save the
data to the database and tell turbine to go to the next page
3. Next page re-retrieves the data from the database for display (outside of
the context of intake).

HTH,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au


> From: "Pat Ryan" <pr...@cardean.edu>
> Reply-To: "Turbine Users List" <tu...@jakarta.apache.org>
> Date: Tue, 15 Oct 2002 17:33:36 -0500
> To: Turbine Users List <tu...@jakarta.apache.org>
> Subject: Intake and carrying around data / data validation
> 
> 
> Hello Intake Wizards! :-)
> 
> We are using Intake (or trying to) in our web application that is
> Jetspeed-based, and therefore has Turbine, Intake, etc for free because they
> come with Jetspeed...
> 
> We are trying to understand how to properly use Intake for data validation.
> The
> basic problem we are having is that there does not seem to be any way to
> 'carry
> forward' Intake data from one request to another, or from one page to another.
> 
> For example, how about a form that you fill in a few fields, and submit it,
> and
> then a 'form' Action class wants to save the data you submitted into the
> session
> and redirect you to a different URL where a 'view' Action class will pull the
> saved data out of the session, and put it into the context so that a velocity
> template can render it.
> 
> Problems that come up include...
> * We tried saving the IntakeTool itself from request to request, since it
> contains the Groups & Fields, but the Pull service wants to recycle it after
> each request so it works once and then the data goes away
> * We tried to pull our intake Group out of the IntakeTool and carry that
> forward, but IntakeTool.removeGroup() recycles the Group, which blows the data
> away
> 
> Our last idea was to make a business object and do the
> mapToObject/setProperties
> thing, but that craps out when a form is submitted with invalid data, because
> formGroup.setProperties(bizObj) throws an exception when trying to set the
> values from formGroup into the bizObj.
> 
> So.
> 
> Has anybody figured out how to use Intake with a lifespan of longer than a
> single request?  Thanks!!!
> 
> Pat, Erich, et al
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Intake and carrying around data / data validation

Posted by Pat Ryan <pr...@cardean.edu>.
Hello Intake Wizards! :-)

We are using Intake (or trying to) in our web application that is
Jetspeed-based, and therefore has Turbine, Intake, etc for free because they
come with Jetspeed...

We are trying to understand how to properly use Intake for data validation.  The
basic problem we are having is that there does not seem to be any way to 'carry
forward' Intake data from one request to another, or from one page to another.

For example, how about a form that you fill in a few fields, and submit it, and
then a 'form' Action class wants to save the data you submitted into the session
and redirect you to a different URL where a 'view' Action class will pull the
saved data out of the session, and put it into the context so that a velocity
template can render it.

Problems that come up include...
* We tried saving the IntakeTool itself from request to request, since it
contains the Groups & Fields, but the Pull service wants to recycle it after
each request so it works once and then the data goes away
* We tried to pull our intake Group out of the IntakeTool and carry that
forward, but IntakeTool.removeGroup() recycles the Group, which blows the data
away

Our last idea was to make a business object and do the mapToObject/setProperties
thing, but that craps out when a form is submitted with invalid data, because
formGroup.setProperties(bizObj) throws an exception when trying to set the
values from formGroup into the bizObj.

So.

Has anybody figured out how to use Intake with a lifespan of longer than a
single request?  Thanks!!!

Pat, Erich, et al


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Wrong value disappeared when an Intake rule is violated

Posted by William Lee <wl...@sendmail.com>.
> I've never noticed this before... but I am only just migrating to TDK 2.2b3 
> now.  If you provide small snippets of the relevant section of your action 
> and screen/template code, I could have a look to see if you are doing 
> anything out of the ordinary.
> 
> -- Rodney
> 

Essentially I have the following in the intake.xml:

<group name="ForwardAdd" key="mforwardadd">
   <field name="Add" key="add" type="String">
     <rule name="maxLength" value="255">TEXT.std_field_long_error</rule>
     <rule name="mask" 
value="^.+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-\.]+$">TEXT.illegal_email_address</rule>
   </field>
</group>

The group and field are pretty standard.  I have the following in the 
velocity template:

#set ($fagroup = $intake.ForwardAdd.Default)

... later on ...

Add an email address:
<input type="text" name="$fagroup.Add.Key"
value="$!vcstr_tool.toHtml($!fagroup.Add.Value.toString())" size="25">
<input type="submit" name="eventSubmit_doAddforward"
value="Add">

<!-- This is the error message -->
<font size="1">
#if (!$fagroup.Add.isValid())
$!vcstr_tool.toHtml($i18n.get($fagroup.Add.Message))<br>
#end
</font>

The vcstr_tool is my custom thing that'll escape the html characters 
from the given string.

In the handler code (an action):

     public void doAddforward(RunData data, Context ctx)
     {
         IntakeTool intake = (IntakeTool)ctx.get("intake");
         if (intake.isAllValid())
         {
             try
             {
                 Group forwardAdd = intake.get("ForwardAdd", 
IntakeTool.DEFAULT_KEY);
                 Field addField = forwardAdd.get("Add");
                 .... more stuff to use the addField here ...
             }
             catch (Exception e)
             {
             }
         }
         else
         {
             data.setMessage(
                     Localization.getString("TEXT.Invalid_input", 
data.getRequest()));
             return;
         }
     }


The problem is, if I put in a wrong value (that violates the regex, for 
example) in the text box, the wrong value will disappear the next time 
when I load the page, even though the correct error message is displayed.

When I stepped through the debugger I found that the value is gone 
before the "IntakeTool intake = ..." line.  I even traced to the init() 
call of the IntakeTool and it seems like the value is gone after you 
call init() of the tool.  Is there anything I do wrong here?

On the side note, I have always had issue with Intake's handling of 
empty strings.  What I realize is, if you have an empty string in the 
form, it won't get submitted (or the ParameterParser won't take it??  I 
didn't do much investigation on this).  As a result, the field 
associated with the empty string will not appear in the group.  However, 
sometimes I REALLY want to have a field that sets to null or "".   If I 
use the mapToObject to map a certain field to an object, calling 
setProperties() will not call "set" for the empty fields.  Thus, the 
internal state of the object would not change.  Is there anything I can 
do here?

-- 
William Lee (Will)        | Sendmail Inc.
Email:  wlee@sendmail.com | http://www.sendmail.com
Tel:    (510) 594-5505    |


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>