Re: Stateless form.processForm

2014-11-13 Thread Barbara Slupik

Hello

Do you have main_template.xml in your main-display-pipeline? Perhaps  
is is enough to define your form template without continuation, like  
ft:form-template action=xxx method=POST. Also perhaps you don't  
need any processing in flow.js after form.showForm(main-display- 
pipeline, data).


Barbara

On 12 Nov 2014, at 17:22, Oliver Bienert wrote:


Hello Cocoon users,

I have created a cocoon 2.2 project. It uses cforms to present a  
record
from an h2 database to the user. I use continuations and a page  
redirect

to switch between records:

   var form = new Form(cocoon://resource/internal/ 
main_definition.xml);
   form.createBinding(cocoon://resource/internal/ 
main_binding.xml);

   // Get data from database and update model
   var bean = javaMain.fillBean(active);
   // Load bean data into form
   form.load(bean);
   form.showForm(main-display-pipeline, data);
   // After submit: Load form data into model
   form.save(bean);
   // Save bean to database
   ...
   // Issue a http redirect from client
   cocoon.sendPage(redirect);

In the sitemap I issue the redirect via redirect-to uri=...

Works so far but I don't really feel this the right way to present  
records to a user.
I mean I don't need a flow between pages so IMHO I don't need  
continuation.


I found out about sending a form stateless by using sendForm.
When the form is submitted I could reattached data by  
form.processForm(viewdata).


Now here I'm stuck. How do I create an appropriate viewData map? I  
googled several hours, but to no avail.

I found a solution with javaflow, but that's not an option for me:

   FormInstance form = new FormInstance(forms/ 
formdefinition.xml);

   Form model = (Form) form.getModel();
   FormContext formContext = new FormContext(getRequest(),  
Locale.getDefault());

   model.process(formContext);

How would I do that in Javascript?

I tried something along those lines:

   function processForm() {
   var javaMain = cocoon.getComponent(mainbean);
   var form = new Form(cocoon://resource/internal/ 
main_definition.xml);
   form.createBinding(cocoon://resource/internal/ 
main_binding.xml);

   var request = cocoon.request;
   var bean = javaMain.newBean();
   form.processForm(request);
   form.save(bean);
   }

but get an error:

org.mozilla.javascript.EvaluatorException:  
servlet:org.apache.cocoon.forms.impl.servlet+:/resource/internal/ 
flow/javascript/Form.js, line 157: Java class  
org.apache.cocoon.environment.http.HttpRequest has no public  
instance field or method named CocoonFormsInstance.


How is this supposed to work?

Regards Oliver



-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org



Re: Stateless form.processForm

2014-11-13 Thread Oliver Bienert
Hi,

it was may mistake, of course it's wrong to use the request object as a
parameter to the function processForm. Instead I have to pass it the
same viewdata (A Javascript object) as when sending the form.

And yes, main_template is in the main-display-pipeline and I changed the
action attribute appropriately.
I think you can omit the action attribute altogether, after form submit
you end up in the same flowscript function. Here you can check for GET
or POST method of request to decide whether you have some form data to
be stored.

Thank you for your quick answer, anyway.

Cheers Oliver


On Thu, 2014-11-13 at 08:59 +0100, Barbara Slupik wrote:
 Hello
 
 Do you have main_template.xml in your main-display-pipeline? Perhaps  
 is is enough to define your form template without continuation, like  
 ft:form-template action=xxx method=POST. Also perhaps you don't  
 need any processing in flow.js after form.showForm(main-display- 
 pipeline, data).
 
 Barbara
 
 On 12 Nov 2014, at 17:22, Oliver Bienert wrote:
 
  Hello Cocoon users,
 
  I have created a cocoon 2.2 project. It uses cforms to present a  
  record
  from an h2 database to the user. I use continuations and a page  
  redirect
  to switch between records:
 
 var form = new Form(cocoon://resource/internal/ 
  main_definition.xml);
 form.createBinding(cocoon://resource/internal/ 
  main_binding.xml);
 // Get data from database and update model
 var bean = javaMain.fillBean(active);
 // Load bean data into form
 form.load(bean);
 form.showForm(main-display-pipeline, data);
 // After submit: Load form data into model
 form.save(bean);
 // Save bean to database
 ...
 // Issue a http redirect from client
 cocoon.sendPage(redirect);
 
  In the sitemap I issue the redirect via redirect-to uri=...
 
  Works so far but I don't really feel this the right way to present  
  records to a user.
  I mean I don't need a flow between pages so IMHO I don't need  
  continuation.
 
  I found out about sending a form stateless by using sendForm.
  When the form is submitted I could reattached data by  
  form.processForm(viewdata).
 
  Now here I'm stuck. How do I create an appropriate viewData map? I  
  googled several hours, but to no avail.
  I found a solution with javaflow, but that's not an option for me:
 
 FormInstance form = new FormInstance(forms/ 
  formdefinition.xml);
 Form model = (Form) form.getModel();
 FormContext formContext = new FormContext(getRequest(),  
  Locale.getDefault());
 model.process(formContext);
 
  How would I do that in Javascript?
 
  I tried something along those lines:
 
 function processForm() {
 var javaMain = cocoon.getComponent(mainbean);
 var form = new Form(cocoon://resource/internal/ 
  main_definition.xml);
 form.createBinding(cocoon://resource/internal/ 
  main_binding.xml);
 var request = cocoon.request;
 var bean = javaMain.newBean();
 form.processForm(request);
 form.save(bean);
 }
 
  but get an error:
 
  org.mozilla.javascript.EvaluatorException:  
  servlet:org.apache.cocoon.forms.impl.servlet+:/resource/internal/ 
  flow/javascript/Form.js, line 157: Java class  
  org.apache.cocoon.environment.http.HttpRequest has no public  
  instance field or method named CocoonFormsInstance.
 
  How is this supposed to work?
 
  Regards Oliver
 
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
  For additional commands, e-mail: users-h...@cocoon.apache.org
 
 
 
 -
 To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
 For additional commands, e-mail: users-h...@cocoon.apache.org
 



-
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org