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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]