[ http://issues.apache.org/jira/browse/COCOON-1804?page=all ]

Simone Gianni updated COCOON-1804:
----------------------------------

    Attachment: javaflow-fomcocoon.diff

This patch solves the problem, also if not perfect I don't think it's so easy 
to do much more. 

What i've done is this :
- Created a new class FOM_SimpleCocoon
... It's a javascript host object
... Exposes request, response, session and context
... It does not (yet?) exposes log and parameters
... Does not have (obviously) the methods of the FOM_Cocoon object like 
sendPage etc..
- In JavascriptHelper, when a function is called :
... If there is not already a scope created by flowscript, getRootScope is 
called.
... I added the object model as a parameter of getRootScope.
... If an object model is specified, it's used to create a new instance of 
FOM_SimpleCocoon
... This instance is placed in a new scope, with the name "cocoon"
... The javascript function is explicity applied to this new scope

This way, the difference between a javascript snippet in a definition, wether 
using flowscript or javaflow, is smaller, since cocoon.request, cocoon.session, 
cocoon.response and cocoon.context are now available, and I don't think much 
more is needed. It would be nice to also have log and parameters, just to be 
more compatible with the complete FOM_Cocoon, but since i don't think they can 
be obtained from an ObjectModel, they should be added as new parameters in all 
the JavascripHelper calls.

> Javascript FOM_SCOPE issue when using Java as the flow engine - 
> ReferenceError: "cocoon" is not defined
> -------------------------------------------------------------------------------------------------------
>
>          Key: COCOON-1804
>          URL: http://issues.apache.org/jira/browse/COCOON-1804
>      Project: Cocoon
>         Type: Bug
>   Components: Blocks: Java Flow
>     Versions: 2.1.8
>     Reporter: Andrew Madu
>     Priority: Blocker
>  Attachments: javaflow-fomcocoon.diff
>
> I have created a  java flow class which does the following:
> //Load in validation file
> FormInstance form = new FormInstance("forms/login.xml");
> My login map (snippet) is as follows:
> Login.xml:
>     <fd:validation>
>         <fd:javascript>
>             var success = true;
>             var newUserReg = new Packages.test.User();
>             var username = widget.lookupWidget("username");
>             var password = widget.lookupWidget("password");
>            
>             try {
>                 
>                 var checkUserTest = newUserReg.getUser(username.value, 
> password.value);
>                 
>                 if (checkUserTest != null) {
>                     cocoon.session.setAttribute("user", checkUserTest);
>                     success = true;
>                 }else{
>                     username.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError(e, false));
>                     password.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError("The password, 
> username combination does not exist. Please enter another one.", false));
>                     success = false;
>                 }
>             } catch (e) {
>                     username.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError(e, false));
>                     password.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError("e.", false));
>                     success = false;
>             }
>             return success;
>         </fd:javascript>
>     </fd:validation>
> I am getting an error message when the line 
> 'cocoon.session.setAttribute("user", checkUserTest)' is hit.:
> ReferenceError: "cocoon" is not defined
> What is the issue here, can I create a session object from within form 
> validation/javascript in another way?
> Andrew

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to