You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Per Kreipke <pe...@onclave.com> on 2002/09/04 22:47:08 UTC

[Q] Form posting sitemap pattern...

I can't quite figure out what the right way is to use actions to handle
posting when there is an originating page, the form itself, a validator and
an action.

Scenario:

- The user has a page which displays a collection of items of some sort
(books).
  + page: books.xyz

- clicking 'new' on the books page brings up a form for entering a new
book's details
  + page: newbook.xyz

- posting the book's details should validate the book's details (must have a
title)
  + validator action: ValidateBook.java

- Code adds the book to the book repository
  + add action: AddBook.java


Flows:

books.xyz -> [new book] -> newbook.xyz -> [post]
	-> ValidateBook -> [ok] -> AddBook -> books.xyz


books.xyz -> [new book] -> newbook.xyz -> [post]
	-> ValidateBook -> [fail] -> newbook.xyz


Details:

- to implement both flows above, I can't figure out what:
  + the 'action' target of the POST should be: books.xyz again, newbook.xyz?
  + what matcher to put the validate and add actions on

Any help would be appreciated. A pointer to or an actual sample sitemap
snippet would be great.

FYI, I'm not using XMLForm and I'm using 2.0.3

Per


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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


Re: [Q] Form posting sitemap pattern...

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 04.Sep.2002 -- 02:57 PM, Lajos Moczar wrote:
> 
> The main gotcha here is the formval logicsheet is a bit clumsy to use, 
> as you have to make sure you not only display validation errors to the 
> user, but repopulate valid fields with the data the user already entered.

Lajos, in 2.0.4 (i.e. CVS cocoon_2_0_3_branch) you'll find a SimpleFormTransformer
that could be used alternatively to the formval logicsheet. It does the population
from previous input. It insists on all input elements to have a @name and selection
options need a @value. It skips <error> tags depending on validation results.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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


RE: [Q] Form posting sitemap pattern...

Posted by Per Kreipke <pe...@onclave.com>.
Lajos,

Wow. Very concise, thanks.

So, the tricks I missed were:

- nesting the validate action and the insert action, I had put them together
in an action-set instead. I actually knew better but that was dumb.

- [here's the kicker] the validator action gets called both when posting
_and_ when simply displaying the form.

- actions without any sub components to execute are pure code and can
actually 'populate' your pipeline (e.g. the way the validator stores stuff).
That's a _very_ handy trick. Will come in handy for setting request
params/globals.

Will try immediately,

Per

> Hi Per -
>
> If you were using the formval logicsheet and the FormValidatorAction,
> you'd have something like this:
>
>   <map:match pattern="newbook">
>    <map:act type="form-validator">
>     <map:parameter name="descriptor"
>       value="context://newbook-def.xml"/>
>     <map:parameter name="validate-set" value="add"/>
>
>     <map:act type="db-insert">
>      <map:parameter name="descriptor"
>       value="context://newbook-def.xml"/>
>      <map:redirect-to uri="books"/>
>     </map:act>
>    </map:act>
>    <map:generate type="serverpages" src="addbook.xsp"/>
>    <map:transform src="addbook.xsl"/>
>    <map:serialize/>
>   </map:match>
>
> Here, the "newbook" pipeline is the action for your form and "books" is
> the pipeline for the display of books (not shown). When the "newbook"
> pipeline executes, the action "validator" tries to validate the posted
> form. If nothing was posted, or if the validation failed, execution
> drops outside that <map:act> block to the "addbook.xsp" page, which
> contains your form and which uses the formval logicsheet to access info
> on what failed during validation. If validation succeeds, then
> everything inside that <map:act> block gets executed which, as you can
> see, uses the DatabaseAddAction to insert the row in your database and
> then redirects the user to the "books" pipeline. Key to the
> DatabaseAddAction, FormValidatorAction and formval logicsheet is the
> descriptor file "newbook-def.xml". All these concepts are discussed in
> the Cocoon documentation.
>
> The main gotcha here is the formval logicsheet is a bit clumsy to use,
> as you have to make sure you not only display validation errors to the
> user, but repopulate valid fields with the data the user already entered.
>
> Regards,
>
> Lajos
>
> galatea.com
> Cocoon training, consulting & support
>
>
> Per Kreipke wrote:
>
> > I can't quite figure out what the right way is to use actions to handle
> > posting when there is an originating page, the form itself, a
> validator and
> > an action.
> >
> > Scenario:
> >
> > - The user has a page which displays a collection of items of some sort
> > (books).
> >   + page: books.xyz
> >
> > - clicking 'new' on the books page brings up a form for entering a new
> > book's details
> >   + page: newbook.xyz
> >
> > - posting the book's details should validate the book's details
> (must have a
> > title)
> >   + validator action: ValidateBook.java
> >
> > - Code adds the book to the book repository
> >   + add action: AddBook.java
> >
> >
> > Flows:
> >
> > books.xyz -> [new book] -> newbook.xyz -> [post]
> > 	-> ValidateBook -> [ok] -> AddBook -> books.xyz
> >
> >
> > books.xyz -> [new book] -> newbook.xyz -> [post]
> > 	-> ValidateBook -> [fail] -> newbook.xyz
> >
> >
> > Details:
> >
> > - to implement both flows above, I can't figure out what:
> >   + the 'action' target of the POST should be: books.xyz again,
> newbook.xyz?
> >   + what matcher to put the validate and add actions on
> >
> > Any help would be appreciated. A pointer to or an actual sample sitemap
> > snippet would be great.
> >
> > FYI, I'm not using XMLForm and I'm using 2.0.3
> >
> > Per
> >
> >
> > ---------------------------------------------------------------------
> > Please check that your question  has not already been answered in the
> > FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> >
> > To unsubscribe, e-mail:     <co...@xml.apache.org>
> > For additional commands, e-mail:   <co...@xml.apache.org>
> >
> >
>
>
> --
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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


Re: [Q] Form posting sitemap pattern...

Posted by Lajos Moczar <lm...@galatea.com>.
Hi Per -

If you were using the formval logicsheet and the FormValidatorAction, 
you'd have something like this:

  <map:match pattern="newbook">
   <map:act type="form-validator">
    <map:parameter name="descriptor"
      value="context://newbook-def.xml"/>
    <map:parameter name="validate-set" value="add"/>

    <map:act type="db-insert">
     <map:parameter name="descriptor"
      value="context://newbook-def.xml"/>
     <map:redirect-to uri="books"/>
    </map:act>
   </map:act>
   <map:generate type="serverpages" src="addbook.xsp"/>
   <map:transform src="addbook.xsl"/>
   <map:serialize/>
  </map:match>

Here, the "newbook" pipeline is the action for your form and "books" is 
the pipeline for the display of books (not shown). When the "newbook" 
pipeline executes, the action "validator" tries to validate the posted 
form. If nothing was posted, or if the validation failed, execution 
drops outside that <map:act> block to the "addbook.xsp" page, which 
contains your form and which uses the formval logicsheet to access info 
on what failed during validation. If validation succeeds, then 
everything inside that <map:act> block gets executed which, as you can 
see, uses the DatabaseAddAction to insert the row in your database and 
then redirects the user to the "books" pipeline. Key to the 
DatabaseAddAction, FormValidatorAction and formval logicsheet is the 
descriptor file "newbook-def.xml". All these concepts are discussed in 
the Cocoon documentation.

The main gotcha here is the formval logicsheet is a bit clumsy to use, 
as you have to make sure you not only display validation errors to the 
user, but repopulate valid fields with the data the user already entered.

Regards,

Lajos

galatea.com
Cocoon training, consulting & support


Per Kreipke wrote:

> I can't quite figure out what the right way is to use actions to handle
> posting when there is an originating page, the form itself, a validator and
> an action.
> 
> Scenario:
> 
> - The user has a page which displays a collection of items of some sort
> (books).
>   + page: books.xyz
> 
> - clicking 'new' on the books page brings up a form for entering a new
> book's details
>   + page: newbook.xyz
> 
> - posting the book's details should validate the book's details (must have a
> title)
>   + validator action: ValidateBook.java
> 
> - Code adds the book to the book repository
>   + add action: AddBook.java
> 
> 
> Flows:
> 
> books.xyz -> [new book] -> newbook.xyz -> [post]
> 	-> ValidateBook -> [ok] -> AddBook -> books.xyz
> 
> 
> books.xyz -> [new book] -> newbook.xyz -> [post]
> 	-> ValidateBook -> [fail] -> newbook.xyz
> 
> 
> Details:
> 
> - to implement both flows above, I can't figure out what:
>   + the 'action' target of the POST should be: books.xyz again, newbook.xyz?
>   + what matcher to put the validate and add actions on
> 
> Any help would be appreciated. A pointer to or an actual sample sitemap
> snippet would be great.
> 
> FYI, I'm not using XMLForm and I'm using 2.0.3
> 
> Per
> 
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
> 
> 


-- 




---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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