On 08/02/2011 12:16 PM, ERNESTO ARROYO RON wrote:
I am on holidays, and trying to use some Tapestry awesome features, as the
inyection.
But I do not understand some issues, and cannot find the answer in the wiki or
somewhere, to the info is not enough clear for me, sorry.
This is very simple. In the Java part of a page I want to inject the DAO, so I
use this code:
@Inject
private IAplicacionesDAO appDAO;
To have this code running I need to add the service implementation via
AppModule and bind:
public static void bind(ServiceBinder binder)
{
binder.bind(IAplicacionesDAO.class,AplicacionesDAO.class);
Two questions:
a) if I add a constructor to the first class, I have an error:
Class com.earroyoron.pages.VerAplicaciones was not transformed for use as a
component; this can happen if it is an interface, or was not in a package
subject to component transformation
and in the documentation I read the constructor was needed! But without it
works and with it I have an error….
A constructor should not be used in a Page or Component class. Tapestry
does a lot of work behind the scenes when deployed to transform these
classes you write so they function nicely. Read up on the page
lifecycle: http://tapestry.apache.org/page-life-cycle.html
I assume there is some initialization you would like to do on your page
when it is rendered and displayed (which you may have thought belonged
in a constructor), for this you would implement one of the render
lifecycle methods. http://tapestry.apache.org/component-rendering.html
For example
@BeginRender
public void loadUser(){
userId = 1;
appDAO.loadUser(userId);
}
b) Cannot Tapestry find the service without the bind? The infection in the DAO
to use Hibernate does not need to say nothing to Tapestry, it works without any
extra configuration in module.
You will need to do the binding so it can auto-bind your service for
you. You could alternately write a build method to build the service
yourself, but that would be more work and I'm assuming is not what you
wanted. http://tapestry.apache.org/defining-tapestry-ioc-services.html
Thank you in advance, when I learn I promise to help the newbies!
:O)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org