cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira ...@upaya.co.uk>
Subject Re: Passing Javascript variable from CFORM definition file into Flowscript
Date Fri, 19 Nov 2004 07:11:51 GMT
Andrew M wrote:

> Hi,
> I have a login definition file which performs validation like so:
>
> 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 userObject = newUserReg.getUser(username, password);
> success = true;
> } catch (e) {
> username.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError("The 
> password, username combination does not exists. Please re-enter.", 
> false));
> password.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError("The 
> password, username combination does not exists. Please re-enter.", 
> false));
> success = false;
> }
>
> return success;
> </fd:javascript>
> </fd:validation>
>
>
> <fd:widgets>
> <fd:field id="username" required="true">
> <fd:label>Username</fd:label>
> <fd:datatype base="string"/>
> <fd:validation>
> <fd:length min="5" max="20"/>
> </fd:validation>
> </fd:field>
>
> <fd:field id="password" required="true">
> <fd:label>Password</fd:label>
> <fd:datatype base="string"/>
> <fd:validation>
> <fd:length min="5" max="20"/>
> </fd:validation>
> </fd:field>
> </fd:widgets>
>
> In my flowscript I do the following:
>
> function login() {
> var form = new Form("forms/login.xml");
>
>
> //make sure form is filled in correctly
> form.showForm("unprotected.xml");
> var model = form.getModel();
> var bizData = {"userObject" : model.userObject}
> ......
> }
>
> How do I get the variable userObject into my function login()? Is this 
> possible?
>
Stick it in the session:
cocoon.session.setAttribute("user", userObject);

Then, every time you need it you can get it out of the session:

var user = cocoon.session.getAttribute("user");

Too simple?

Regards, Upayavira


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


Mime
View raw message