cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Rusnak <m...@cyberspace.sk>
Subject Re: Getting database connection in flow script
Date Thu, 28 Oct 2004 22:48:00 GMT
Hello,
I solved the problem getting database connection so that I created
Registrator java class which implements Serviceable interface. Then
the flowscript loads Registrator class by method cocoon.createObject()
in order to allow accessing Avalon services.

Now I need to solve another problem. When the user with the specified
username exists in the database, Registrator class thows
RegistrationException and the form shall be displayed again with an
error message at the corresponding textfield. I have following questions:

1. Is it possible to specify exception class in catch clause? Currently
   I use instanceof operator.

2. How to setup errorMessage for the specific widget?

Here is the script:

registration() {

    var form = new Form("forms/registration.xml")
    var success

    do {
        success = true
        form.showForm("registration-display-pipeline")

        var model = form.getModel()

        var registrator = cocoon.createObject("Registrator")

        try {
            registrator.register(model.username, model.password)
        } catch(e) {
            if(e instanceof RegistrationException) {
                success = false
            } else throw e
        }
    } while(!success)

    cocoon.sendPage("success.html")
}




Antonio Gallardo wrote:
> Servus Martin!
> 
> Martin Rusnak dijo:
> 
>>Dear All,
>>
>>I am using CForms/flow-script. When the form is submited, I usually call
>>a methods in my database utility classes from flow-script to perform a
>>DB queries. For that I need to obtain a database connection from the
>>pool. I tried the method: Database.getConnection("connection-id"), but
>>it returns ScriptableConnection class. Is it possible to get reference
>>to java.sql.Connection in flow-script?
> 
> 
> I never used directly java.sql.* in JSFlow, but I think it should work.
> 
> 
>>What is the preferred way to
>>handle database calls in flow-script?
> 
> 
> Well, I think the "prefered" way depends of how much you will use
> databases. There are diferent approach:
> 
> The olders are:
> 
> 1-ESQL tranformer
> 2-ESQL logicsheet in XSP
> 3-Modular DB Actions - http://wiki.apache.org/cocoon/ReinhardHorn
> 
> The "newer" approach is using a O/R mapping tool - i.e.:Apache OJB,
> Hibernate, etc. This approach is particular powerful because allow you to
> have better SoC + all the advantage that a O/R tool + better abstraction.
> 
> You can find more info in section 7. "Databases" at:
> http://wiki.apache.org/cocoon/HowTos
> 
> Best Regards,
> 
> Antonio Gallardo.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 


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


Mime
View raw message