Hello Raul, After taking a look at Tapestry 4 "tapestry.state.ApplicationObjects" configuration point, it seems clear to me that you have no way to provide _directly_ any object (I mean, using an "object translator") to that configuration. The way you describe your configuration cannot work, since <invoke-factory> requires an object (using "object translator") that must implement StateObjectFactory interface, but GlobalMenu does not implement that interface.
In addition there is a mistake in the way you want to "pass" your GlobalMenu object to the configuration, you would need to set "object:GlobalMenu" not merely "GlobalMenu". I really advise you to take a look at HiveMind documentation to better understand the concepts of configuration and translators, and particularly the object translator which allows many things to be injected but is sometimes difficult to use. Anyway, as a conclusion, I believe what you want to achieve is not directly feasible, but you can work around this by either: - creating a service that would implement StateObjectFactory and would be injected your GlobalMenu object (and pass it to the ASO config as object="service:YourService") OR - have your GlobalMenu object implement itself the StateObjectFactory interface (and pass it to the ASO config as object="object:GlobalMenu" The second solution is easier but not very "clean". The first solution is "more beautiful" but requires one more class. Maybe it would be good (but I don't know if it makes sense in the Tapestry world) to require the additional possibility in Tapestry ASO configuration to pass directly an object (instead of having only <create-instance> and <ivoke-factory> "methods")? Cheers Jean-Francois -----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Raul Raja Martinez Sent: Monday, December 05, 2005 9:53 AM To: tapestry-user@jakarta.apache.org Subject: Re: Injecting registry services to POJOS Hi Jean-Francois, I've tried your method not using the builder.create(). Here is what I have done: <contribution configuration-id="hiveutils.ObjectBuilderObjects"> <object name="GlobalMenu" cached="true" class="com.estudiowebs.CMS.DAO.GlobalMenu"> <inject name="EntityService" object="service:com.estudiowebs.CMS.services.EntityService" /> </object> </contribution> <state-object name="globalMenu" scope="application"> <invoke-factory object="GlobalMenu" /> </state-object> and it does't work because it complains that the object in invoke-factory can't be null. Do you know what will be the right way to reference it? Thanks. Raul. Jean-Francois Poilpret wrote: > Hi Raul, > > ObjectBuilder builder =... > > Here, ... is supposed to be replaced either with: > - a call to HiveMind registry to get the hiveutils.ObjectBuilder service > - or by nothing if builder is directly injected into the class that has this > code. > > One extra point though, as I said (maybe I was not very clear about that) in > my last mail, you do not need to directly call ObjectBuilder.create() (this > is useful only in situations where you need to pass an extra runtime > argument to your constructor, or when you need to get a new POJO instance > every time). > > As I said, it seems you have a default constructor and therefore, a simpler > way to inject a POJO in a service through hiveutils.ObjectBuilder is to use > (in a transparent way) the hiveutils ObjectProvider for ObjectBuilder: > - whenever a service or configuration accepts an object (defined in the > config schema by translator="object"), then you can put the following into > the configuration: "object:MyPOJOName", where MyPOJOName is the name you > have set for your POJO inside the hiveutils.ObjectBuilderObjects > configuration. > > This way you do not need to produce any specific code, everything is inside > your HiveMind config files. > The only point that you must ensure is that you actually have th > epossibility to inject an object (ie the config/service accepts the "object" > translator). For further info on the object translator, you should take a > look at the HiveMind web site. > > Cheers > > Jean-Francois > > -----Original Message----- > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Raul Raja Martinez > Sent: Monday, December 05, 2005 6:12 AM > To: tapestry-user@jakarta.apache.org > Subject: Re: Injecting registry services to POJOS > > Hi Jean-Francois > I'm gonna try the HiveUtil approach, > both in your email and in > http://hivetranse.sourceforge.net/quickstart.html#start.objectbuilder > you refer to: > > ObjectBuilder builder =... > GlobalMenu globaleMenu = builder.create("globalMenu", myArg); > > What is "..." supposed to be? :( > > Thanks > > Raul. > > > Jean-Francois Poilpret wrote: >> Hi Raul, >> >> From what I saw in another of your emails, I guess what you have to do if >> you want to use HiveUtils is a config like this: >> >> <contribution configuration-id="hiveutils.ObjectBuilderObjects"> >> <object name="globalMenu" cached="true" >> class="com.estudiowebs.CMS.DAO.GlobalMenu"> >> <inject name="EntityService" >> object="service:com.estudiowebs.CMS.services.EntityService" /> > >> </object> >> </contribution> >> >> This will call the default constructor of GlobalMenu and then inject the >> EntityService through the setter method. >> >> Now the problem still remains on the Tapestry side: how to inject the pojo >> globalMenu to the tapestry.state.ApplicationObjects configuration? >> Since I do not have Tapestry on hand I cannot check what is possible to do >> in the contributions for this configuration, but I suppose there must be a >> way (an attribute) to inject your POJO by using "object:globalMenu". >> >> Now for your question about a HiveMind utilities newsgroup, unfortunately >> not (or not yet). The only way currently is to use the online forums (I > hate >> that but I discovered that my provider's email server was not recognized > by >> SourceForge so that any mail sent to the SF newsgroup would fail because > of >> my own email address! Actually I plan to change this addres, but that is > not >> done yet). Hope to create a mailing list soon. >> >> Cheers >> >> Jean-Francois >> >>>>> <contribution configuration-id="tapestry.state.ApplicationObjects"> >>>>> <state-object name="globalMenu" scope="application"> >>>>> <create-instance class="com.estudiowebs.CMS.DAO.GlobalMenu" /> >>>>> </state-object> >>>>> </contribution> >> -----Original Message----- >> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Raul Raja Martinez >> Sent: Sunday, December 04, 2005 12:36 PM >> To: tapestry-user@jakarta.apache.org >> Subject: Re: Injecting registry services to POJOS >> >> Hi Jean-Francois, first of all thanks for your help, >> >> My pojo is basicaly the menu of my webapp, since everybody will have the >> same I thought that the best thing would be to make it an application >> scope object and fetch the records at startup. since i have already >> declared a Hibernate Session service I wanted to inject that service >> into this object so that I could use it to query the objects. >> >> I have also many webservices in the same webapp that are not tapestry >> related and I'd like to use these services both in the tapestry and >> servlets. >> >> I think this is or would be a common problem for Tapestry 4 users. >> Many have already asked how to access the Tapestry hivemind registry >> from other objects that are not of type Component or Page. My problem is >> that I don't even know if this is posible since someone mentioned in >> this newsgroup that the Tapestry hivemind registry wasn't available >> directly and also annotations like @InjectObject only work within pages >> or components. >> >> Anyway, I'll try your solution, >> Is there a newsgroup for Hivemind utilities? >> >> Thanks, >> >> Raul. >> >> >> Jean-Francois Poilpret wrote: >>> Hi Raul, >>> >>> I do not know Tapestry, but I know HiveUtils (I wrote it;-)), the >>> contribution you describe below seems OK to me (at first sight). >>> >>> However it depends exactly on what you want to achieve. >>> In particular is your POJO a singleton in your application, or do you > need >>> to inject a new instance every time? From your initial Tapestry example, > I >>> believe it is a singleton, so when using HiveUtils, you should probably >> put >>> the "cache" attribute to true to make sure HiveUtils will not create more >>> than one instance: >>> >>> <contribution configuration-id="hiveutils.ObjectBuilderObjects"> >>> <object name="globalMenu" cached="true" >>> class="com.estudiowebs.CMS.DAO.GlobalMenu"> >>> <inject >>> object="service:com.estudiowebs.CMS.services.EntityService" /> >>> <inject-arg /> >>> </object> >>> </contribution> >>> >>> Please note however that according to the above config (independently of >> the >>> cache attribute), you need to use hiveutils.ObjectBuilder service to get >> the >>> instance of your object because, you have declared your POJO to require a >>> runtime argument in the constructor ("<inject-arg/>") which means the >>> constructor for it should look like: >>> public GlobalMenu(com.estudiowebs.CMS.services.EntityService >>> service, >>> MyArgType myarg) {... >>> NB: MyArgType can be any type. >>> >>> Then to get the instance of your POJO you need to do: >>> >>> ObjectBuilder builder =... >>> GlobalMenu globaleMenu = builder.create("globalMenu", myArg); >>> >>> where myArg is of type MyArgType. >>> >>> Is this what you want to do? >>> Do you really need the extra runtime argument? >>> If not then it would make it easier to inject globalMenu into other >> objects, >>> services, or configurations by using: >>> "object:globalMenu" >>> >>> I hope it gives you a better view of what you can do and how you can do >> it, >>> now if you need further precisions or if you want to give more details >> about >>> what you want to do, you are welcome. >>> >>> One last point: HiveUtils is part of the HiveMind Utilities project on >>> SourceForge (formarly known as "hivetranse"), which is independent of >>> HiveMind and Tapestry (by independent I talk about the involved persons >> and >>> the communication channels). So it might be better to proceed with this >>> discussion on the HiveMind Utilities forums, except if this is a common >>> Tapestry problem. >>> >>> Cheers >>> >>> Jean-Francois >>> >>> -----Original Message----- >>> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Raul Raja Martinez >>> Sent: Sunday, December 04, 2005 5:54 AM >>> To: tapestry-user@jakarta.apache.org >>> Subject: Re: Injecting registry services to POJOS >>> >>> I was trying to do that using hiveutils, sorry, but still very new to >>> hivemind and IOC: >>> >>> <contribution configuration-id="hiveutils.ObjectBuilderObjects"> >>> >>> > <objectname="globalMenu"cached="false"class="com.estudiowebs.CMS.DAO.GlobalM >>> enu"> >>> <inject >>> object="service:com.estudiowebs.CMS.services.EntityService" /> >>> <inject-arg /> >>> </object> >>> >>> </contribution> >>> >>> I just need and example on how to inject one of my services in one of my >>> POJO so that I can access my hibernate session from my pojos. >>> >>> Thanks. >>> >>> Raul. >>> >>> >>> John Coleman wrote: >>>> HiveMind injects by interface automatically if you use its service >> builder >>>> (it will use setter methods of the declared interface type), in Tapestry >>>> pages you can also use the page to inject services. So you never have to >>> use >>>> annotations. >>>> >>>> I don't think it matters about the order of instantiation, HM should >>> insure >>>> every service is set up with the references it needs. >>>> >>>> John >>>> >>>> ----- Original Message ----- >>>> From: "Raul Raja Martinez" <[EMAIL PROTECTED]> >>>> To: <tapestry-user@jakarta.apache.org> >>>> Sent: Saturday, December 03, 2005 11:46 AM >>>> Subject: Injecting registry services to POJOS >>>> >>>> >>>>> Hi, >>>>> >>>>> I have a service in my hivemodule.xml that I'd like to inject in a Pojo >>>>> that at the same time gets loaded as a an application scope object at >>>>> startup: >>>>> >>>>> <contribution configuration-id="tapestry.state.ApplicationObjects"> >>>>> <state-object name="globalMenu" scope="application"> >>>>> <create-instance class="com.estudiowebs.CMS.DAO.GlobalMenu" /> >>>>> </state-object> >>>>> </contribution> >>>>> >>>>> This is an object that I load from the database once at startup and I >>>>> need to inject my Hivetranse Hibernate3 session service into it so that >>>>> I use that service for loading the object. >>>>> Since annotations like @InjectObject are not allowed in regular POJOS >>>>> and I don't have access to the Tapestry Registry, I don't really know >>>>> what would be the best way to solve this problem >>>>> >>>>> On the other side I have in the same application a couple of servlets >>>>> that serve as XML source for a Laszlo application, and I have the same >>>>> problem. >>>>> >>>>> Any help is appreciated. >>>>> >>>>> >>>>> I'd really love to be able to @InjectObject("service....") anywhere >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>> >>>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>> >>>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]