You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erik Vullings <er...@gmail.com> on 2007/09/10 00:49:07 UTC

[T5] How to use Services - an example, please

Hi,

I've read the manual about services, but don't get it: It's like seeing the
puzzle pieces, but not the whole. Can someone explain it to me please,
especially:

   1. How can I use a service to connect to my database? Or should I use
   Hibernate?
   2. How can I use a service to access the file system? In the demos,
   Howard uses a service to access his CD library, and it seems really cool,
   but I have no idea how he does it...

More specifically, I had a struts2 MVC webapp which I'm porting to T5. It
had three layers: JSP, which maps nicely to HTML templates, Controllers,
which are myTapestry components and pages, and my DAL, which is still there.
So for every serious class that I need to persist, it has a DAO that does it
for me e.g.:

    public WhateverDAO() {
        dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(Globals.dbDriver);
        dataSource.setUrl(Globals.dbURL);
        dataSource.setUsername(Globals.dbUsername);
        dataSource.setPassword(Globals.dbPassword);
...
}
    public List<QandA> retrieve(long poId) throws SQLException {
        JdbcTemplate jt = new JdbcTemplate(dataSource);
...
}

This does not seem to be the Tapestry way, but can someone show me the true
path :-) A service seems to be the answer... or Hibernate, but I'm not sure
whether that will save me a lot of time.

Thanks,
Erik

Re: [T5] How to use Services - an example, please

Posted by smithfox <ss...@gmail.com>.

http://code.google.com/p/lichen-forum/


Erik Vullings-2 wrote:
> 
> Hi,
> 
> I've read the manual about services, but don't get it: It's like seeing
> the
> puzzle pieces, but not the whole. Can someone explain it to me please,
> especially:
> 
>    1. How can I use a service to connect to my database? Or should I use
>    Hibernate?
>    2. How can I use a service to access the file system? In the demos,
>    Howard uses a service to access his CD library, and it seems really
> cool,
>    but I have no idea how he does it...
> 
> More specifically, I had a struts2 MVC webapp which I'm porting to T5. It
> had three layers: JSP, which maps nicely to HTML templates, Controllers,
> which are myTapestry components and pages, and my DAL, which is still
> there.
> So for every serious class that I need to persist, it has a DAO that does
> it
> for me e.g.:
> 
>     public WhateverDAO() {
>         dataSource = new DriverManagerDataSource();
>         dataSource.setDriverClassName(Globals.dbDriver);
>         dataSource.setUrl(Globals.dbURL);
>         dataSource.setUsername(Globals.dbUsername);
>         dataSource.setPassword(Globals.dbPassword);
> ...
> }
>     public List<QandA> retrieve(long poId) throws SQLException {
>         JdbcTemplate jt = new JdbcTemplate(dataSource);
> ...
> }
> 
> This does not seem to be the Tapestry way, but can someone show me the
> true
> path :-) A service seems to be the answer... or Hibernate, but I'm not
> sure
> whether that will save me a lot of time.
> 
> Thanks,
> Erik
> 
> 

-- 
View this message in context: http://www.nabble.com/-T5--How-to-use-Services---an-example%2C-please-tf4411200.html#a12584957
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: [T5] How to use Services - an example, please

Posted by Davor Hrg <hr...@gmail.com>.
Services are ordinary java classes,

difference is only that some objects you will instantiate
by hand, like StringBuffer or File...

Service is a class for which you let tapestry-ioc to
generate instances. You configure which services
are available in your AppModule and define there
how they are created. If you use bind method
then you supply only the Class and let tapestry fill
in dependancies (through constructor).
If you use buildMyService methods then you require
dependacies by liting them as method parameters
and manualy construct your service.

this is how I can explain it, say if it makes any sense,

Davor Hrg



On 9/10/07, Erik Vullings <er...@gmail.com> wrote:
>
> Hi,
>
> I've read the manual about services, but don't get it: It's like seeing
> the
> puzzle pieces, but not the whole. Can someone explain it to me please,
> especially:
>
>    1. How can I use a service to connect to my database? Or should I use
>    Hibernate?
>    2. How can I use a service to access the file system? In the demos,
>    Howard uses a service to access his CD library, and it seems really
> cool,
>    but I have no idea how he does it...
>
> More specifically, I had a struts2 MVC webapp which I'm porting to T5. It
> had three layers: JSP, which maps nicely to HTML templates, Controllers,
> which are myTapestry components and pages, and my DAL, which is still
> there.
> So for every serious class that I need to persist, it has a DAO that does
> it
> for me e.g.:
>
>     public WhateverDAO() {
>         dataSource = new DriverManagerDataSource();
>         dataSource.setDriverClassName(Globals.dbDriver);
>         dataSource.setUrl(Globals.dbURL);
>         dataSource.setUsername(Globals.dbUsername);
>         dataSource.setPassword(Globals.dbPassword);
> ...
> }
>     public List<QandA> retrieve(long poId) throws SQLException {
>         JdbcTemplate jt = new JdbcTemplate(dataSource);
> ...
> }
>
> This does not seem to be the Tapestry way, but can someone show me the
> true
> path :-) A service seems to be the answer... or Hibernate, but I'm not
> sure
> whether that will save me a lot of time.
>
> Thanks,
> Erik
>