You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Andrew Madu <an...@gmail.com> on 2006/03/21 15:29:26 UTC

Java Flow/

Hi,
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 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");
            cocoon.session.setAttribute("user", null);

            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("The password,
username combination does not exist. Please enter another one.", false));
                    success = false;
            }

            return success;
        </fd:javascript>
    </fd:validation>

I am getting an error message when the line:

cocoon.session.setAttribute("user", null);

is hit. What is the issue with this when using javaflow instead of
flowscript? How can I alter thsi map so that it is java flow complient? I
tried:

<fd:java>

as a starter but got an error with that.

Andrew

Re: Java Flow/

Posted by Andrew Madu <an...@gmail.com>.
Simone,
the bug has been filed.

Many thanks

Andrew

On 3/21/06, Simone Gianni <s....@thebug.it> wrote:
>
> Hi Andrew,
> please file a bug about this on
> http://issues.apache.org/jira/browse/COCOON . I'm not sure about it, but
> maybe it's not so difficult to initialize the cocoon javascript object for
> definition embedded javascript even when the entire javascript flow engine
> is not on.
>
> Write your code snippet in the bug, so that committers can test it.
>
> Apart from the (horrible) work around i wrote you about, nothing else came
> to my mind.
>
>
> Simone
>
> Andrew Madu wrote:
>
> Hi Simone,
> I should have mentioned that the error I am getting is the following:
>
> ReferenceError: "cocoon" is not defined
>
> The rest of the code seems to be fine though. I am hoping that this is
> simple issue to resolve, without having to do a major code change ;-),
> otherwise I will have to stiick with flowscript.
>
> Andrew
>
> On 3/21/06, Simone Gianni <s....@thebug.it> wrote:
> >
> > Hi Andrew,
> > I would move all the login code in the flow, since the fd:validation is
> > not the right place to do application logic.
> >
> > But if you really need it there, i think you will have to rewrite your
> > code. Unfortunately, the javascript snippet is executed using the
> > FOM_SCOPE, which contains the cocoon object and all the rest, but it
> > seems like this scope is initialized inside the flowscript code, so
> > looks like it's not available when in javaflow. I think this is a cocoon
> > bug, since the usage of a different flow engine should not change the
> > behaviour or embedded javascript snippets of a definition. I think
> > nobody noticed this since it's not so common to access the session from
> > inside an fd:validation expecially when javaflow is used.
> >
> > You could try a really non-tidy way : put the session in a form
> > attribute from javaflow, and then retrieve it inside the javascript:
> >
> > FormInstance form = new FormInstance("forms/login.xml");
> > form.setAttribute("session", getRequest().getSession());
> >
> >         <fd:javascript>
> >             var success = true;
> >             var newUserReg = new Packages.test.User();
> >             var username = widget.lookupWidget("username");
> >             var password = widget.lookupWidget("password");
> >             var session = widget.getForm().getAttribute('session');
> >             session.setAttribute ("user", null);
> >
> > I haven't tested this, and don't know which error your code reports, but
> > hope it helps. Please consider moving the login code from the
> > fd:validation to the flow.
> >
> > Simone
> >
> > Andrew Madu wrote:
> >
> > > Hi,
> > > 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 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");
> > >             cocoon.session.setAttribute ("user", null);
> > >
> > >             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("The
> > > password, username combination does not exist. Please enter another
> > > one.", false));
> > >                     success = false;
> > >             }
> > >
> > >             return success;
> > >         </fd:javascript>
> > >     </fd:validation>
> > >
> > > I am getting an error message when the line:
> > >
> > > cocoon.session.setAttribute("user", null);
> > >
> > > is hit. What is the issue with this when using javaflow instead of
> > > flowscript? How can I alter thsi map so that it is java flow
> > > complient? I tried:
> > >
> > > <fd:java>
> > >
> > > as a starter but got an error with that.
> > >
> > > Andrew
> >
> > --
> > Simone Gianni
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>  --
> Simone Gianni
>

Re: Java Flow/

Posted by Simone Gianni <s....@thebug.it>.
Hi Andrew,
please file a bug about this on 
http://issues.apache.org/jira/browse/COCOON . I'm not sure about it, but 
maybe it's not so difficult to initialize the cocoon javascript object 
for definition embedded javascript even when the entire javascript flow 
engine is not on.

Write your code snippet in the bug, so that committers can test it.

Apart from the (horrible) work around i wrote you about, nothing else 
came to my mind.

Simone

Andrew Madu wrote:

> Hi Simone,
> I should have mentioned that the error I am getting is the following:
>
> ReferenceError: "cocoon" is not defined
>
> The rest of the code seems to be fine though. I am hoping that this is 
> simple issue to resolve, without having to do a major code change ;-), 
> otherwise I will have to stiick with flowscript.
>
> Andrew
>
> On 3/21/06, *Simone Gianni* <s.gianni@thebug.it 
> <ma...@thebug.it>> wrote:
>
>     Hi Andrew,
>     I would move all the login code in the flow, since the
>     fd:validation is
>     not the right place to do application logic.
>
>     But if you really need it there, i think you will have to rewrite your
>     code. Unfortunately, the javascript snippet is executed using the
>     FOM_SCOPE, which contains the cocoon object and all the rest, but it
>     seems like this scope is initialized inside the flowscript code, so
>     looks like it's not available when in javaflow. I think this is a
>     cocoon
>     bug, since the usage of a different flow engine should not change the
>     behaviour or embedded javascript snippets of a definition. I think
>     nobody noticed this since it's not so common to access the session
>     from
>     inside an fd:validation expecially when javaflow is used.
>
>     You could try a really non-tidy way : put the session in a form
>     attribute from javaflow, and then retrieve it inside the javascript:
>
>     FormInstance form = new FormInstance("forms/login.xml");
>     form.setAttribute("session", getRequest().getSession());
>
>             <fd:javascript>
>                 var success = true;
>                 var newUserReg = new Packages.test.User();
>                 var username = widget.lookupWidget("username");
>                 var password = widget.lookupWidget("password");
>                 var session = widget.getForm().getAttribute('session');
>                 session.setAttribute ("user", null);
>
>     I haven't tested this, and don't know which error your code
>     reports, but
>     hope it helps. Please consider moving the login code from the
>     fd:validation to the flow.
>
>     Simone
>
>     Andrew Madu wrote:
>
>     > Hi,
>     > 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 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");
>     >             cocoon.session.setAttribute ("user", null);
>     >
>     >             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("The
>     > password, username combination does not exist. Please enter another
>     > one.", false));
>     >                     success = false;
>     >             }
>     >
>     >             return success;
>     >         </fd:javascript>
>     >     </fd:validation>
>     >
>     > I am getting an error message when the line:
>     >
>     > cocoon.session.setAttribute("user", null);
>     >
>     > is hit. What is the issue with this when using javaflow instead of
>     > flowscript? How can I alter thsi map so that it is java flow
>     > complient? I tried:
>     >
>     > <fd:java>
>     >
>     > as a starter but got an error with that.
>     >
>     > Andrew
>
>     --
>     Simone Gianni
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>     <ma...@cocoon.apache.org>
>     For additional commands, e-mail: users-help@cocoon.apache.org
>     <ma...@cocoon.apache.org>
>
>
-- 
Simone Gianni

Re: Java Flow/

Posted by Andrew Madu <an...@gmail.com>.
Hi Simone,
I should have mentioned that the error I am getting is the following:

ReferenceError: "cocoon" is not defined

The rest of the code seems to be fine though. I am hoping that this is
simple issue to resolve, without having to do a major code change ;-),
otherwise I will have to stiick with flowscript.

Andrew

On 3/21/06, Simone Gianni <s....@thebug.it> wrote:
>
> Hi Andrew,
> I would move all the login code in the flow, since the fd:validation is
> not the right place to do application logic.
>
> But if you really need it there, i think you will have to rewrite your
> code. Unfortunately, the javascript snippet is executed using the
> FOM_SCOPE, which contains the cocoon object and all the rest, but it
> seems like this scope is initialized inside the flowscript code, so
> looks like it's not available when in javaflow. I think this is a cocoon
> bug, since the usage of a different flow engine should not change the
> behaviour or embedded javascript snippets of a definition. I think
> nobody noticed this since it's not so common to access the session from
> inside an fd:validation expecially when javaflow is used.
>
> You could try a really non-tidy way : put the session in a form
> attribute from javaflow, and then retrieve it inside the javascript:
>
> FormInstance form = new FormInstance("forms/login.xml");
> form.setAttribute("session", getRequest().getSession());
>
>         <fd:javascript>
>             var success = true;
>             var newUserReg = new Packages.test.User();
>             var username = widget.lookupWidget("username");
>             var password = widget.lookupWidget("password");
>             var session = widget.getForm().getAttribute('session');
>             session.setAttribute("user", null);
>
> I haven't tested this, and don't know which error your code reports, but
> hope it helps. Please consider moving the login code from the
> fd:validation to the flow.
>
> Simone
>
> Andrew Madu wrote:
>
> > Hi,
> > 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 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");
> >             cocoon.session.setAttribute("user", null);
> >
> >             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("The
> > password, username combination does not exist. Please enter another
> > one.", false));
> >                     success = false;
> >             }
> >
> >             return success;
> >         </fd:javascript>
> >     </fd:validation>
> >
> > I am getting an error message when the line:
> >
> > cocoon.session.setAttribute("user", null);
> >
> > is hit. What is the issue with this when using javaflow instead of
> > flowscript? How can I alter thsi map so that it is java flow
> > complient? I tried:
> >
> > <fd:java>
> >
> > as a starter but got an error with that.
> >
> > Andrew
>
> --
> Simone Gianni
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: Java Flow/

Posted by Simone Gianni <s....@thebug.it>.
Hi Andrew,
I would move all the login code in the flow, since the fd:validation is 
not the right place to do application logic.

But if you really need it there, i think you will have to rewrite your 
code. Unfortunately, the javascript snippet is executed using the 
FOM_SCOPE, which contains the cocoon object and all the rest, but it 
seems like this scope is initialized inside the flowscript code, so 
looks like it's not available when in javaflow. I think this is a cocoon 
bug, since the usage of a different flow engine should not change the 
behaviour or embedded javascript snippets of a definition. I think 
nobody noticed this since it's not so common to access the session from 
inside an fd:validation expecially when javaflow is used.

You could try a really non-tidy way : put the session in a form 
attribute from javaflow, and then retrieve it inside the javascript:

FormInstance form = new FormInstance("forms/login.xml");
form.setAttribute("session", getRequest().getSession());

        <fd:javascript>
            var success = true;
            var newUserReg = new Packages.test.User();
            var username = widget.lookupWidget("username");
            var password = widget.lookupWidget("password");
            var session = widget.getForm().getAttribute('session');
            session.setAttribute("user", null);

I haven't tested this, and don't know which error your code reports, but 
hope it helps. Please consider moving the login code from the 
fd:validation to the flow.

Simone

Andrew Madu wrote:

> Hi,
> 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 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");
>             cocoon.session.setAttribute("user", null);
>             
>             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("The 
> password, username combination does not exist. Please enter another 
> one.", false));
>                     success = false;
>             }
>
>             return success;
>         </fd:javascript>
>     </fd:validation>
>
> I am getting an error message when the line:
>
> cocoon.session.setAttribute("user", null);
>
> is hit. What is the issue with this when using javaflow instead of  
> flowscript? How can I alter thsi map so that it is java flow 
> complient? I tried:
>
> <fd:java>
>
> as a starter but got an error with that.
>
> Andrew

-- 
Simone Gianni

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