You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by maisonneuve nico <ni...@hotmail.com> on 2003/07/31 04:15:57 UTC
woody dynamic validation rule
hi , i would make a account form with woody and store informations in a xml
file (in fact in a XML database)
with this structure :
<user>
<id>0100007f664e8bad000000f69dd0d652</id>
<login>nicolas</login>
<password>cococo</password>
<name>maisonneuve</name>
<firstname>nicolas</firstname>
<role>user</role>
<email>nico@rococo.com</email>
<entreprise>paris5</entreprise>
</user>
in the create action, at the end of the submit, i have to check if the login
is already used or not.
i cant create a validation rule despit of the update action (in update
action, the login check will be always true and a validation error will be
created)
so i make a avalon XMLDBcomponent with the hasResult(Xpath)
and update the file.js with this source code;
but how tell to the user the invalide login error (with validate rule it's
easy but with this way i don't know how do)
or can we create a dynamic validatation rule
thank in advance
cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody.js") ;
cocoon.load("flow/xmldb.js") ;
var display_pipeline = "account-display" ;
var sucess_pipeline = "account-sucess" ;
var collectionDB = "xmldb:xindice://localhost:8080/db/user" ;
var documentID;
var document;
var action;
function account(form) {
action=cocoon.parameters["action"];
if (action=="update") {
// bind the form with the document with the ID
documentID=cocoon.parameters["documentID"];
document = loadDocument(documentID,collectionDB);
}
// shows the form to the user until is validated successfully
form.show(display_pipeline, formHandler);
// bind the form's data back to the document
form.save(document);
// save the DOM-tree
if (action=="update")
updateDocument(document, documentID,collectionDB);
if (action=="create")
addDocument(document, documentID,collectionDB)
cocoon.sendPage(sucess_pipeline);
form.finish();
}
function formHandler(form) {
var model = form.getModel();
if (verify(model))
return true;
else
return false;
}
function verify(model) {
// create a ID if the id is null
if (model.id == null)
{
xmldb.setCollection(collectionDB);
model.id=xmldb.generateID();
}
// init the user role if it is null
if (model.role ==null)
{
model.role="user";
}
if (action=="create")
{
var results=xmldb.hasResults("//user[login='"+model.login+"' and
password='"+model.password+"'");
return (!results);
}
else return true;
}
_________________________________________________________________
MSN Messenger 6 http://g.msn.fr/FR1001/866 : ajoutez une image à votre
pseudo pour dialoguer avec vos amis
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: woody dynamic validation rule
Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2003-07-31 at 04:15, maisonneuve nico wrote:
> hi , i would make a account form with woody and store informations in a xml
> file (in fact in a XML database)
> with this structure :
> <user>
> <id>0100007f664e8bad000000f69dd0d652</id>
> <login>nicolas</login>
> <password>cococo</password>
> <name>maisonneuve</name>
> <firstname>nicolas</firstname>
> <role>user</role>
> <email>nico@rococo.com</email>
> <entreprise>paris5</entreprise>
> </user>
>
> in the create action, at the end of the submit, i have to check if the login
> is already used or not.
> i cant create a validation rule despit of the update action (in update
> action, the login check will be always true and a validation error will be
> created)
yep, validation rules are mostly for generic stuff. Application-specific
validations are better done by 'outside code', like you're doing.
> so i make a avalon XMLDBcomponent with the hasResult(Xpath)
> and update the file.js with this source code;
> but how tell to the user the invalide login error (with validate rule it's
> easy but with this way i don't know how do)
You would need to have an addValidationError() method on the widget.
Unfortunately that doesn't exist yet, though it is planned to add such a
thing.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org