cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "maisonneuve nico" <nic...@hotmail.com>
Subject woody dynamic validation rule
Date Thu, 31 Jul 2003 02:15:57 GMT
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


Mime
View raw message