|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Singleton CreatorHi,
In one of my messages in the users mail list, I asked about how to create a singleton class in DWR. Joe kindly refered to this page http://getahead.org/dwr/server/dwrxml/creators/scripted It was a good solution but I didn't like to use any extra jar from apache. I found an easy way in spring for declaring singleton beans <bean id="singleton" class="example.LegacySingleton" factory-method="getInstance" /> Today, I went through DWR trying to implement the same thing to be used in my project First I got the DWR source and added a new Creator for singleton in the dwr.xml I added this declaration <creator id="singleton" class=" org.directwebremoting.create.SingletonCreator" /> The class implementation is attached. After that I made a simple singleton class "UserService" attached The definition in the dwr.xml will be easy and clear <create creator="singleton" javascript="userServiceSingleton"> <param name="class" value="org.egjug.dwr.UserService" /> <param name="factoryMethod" value="getInstance" /> </create> The complete project is attached. I will add this simple howto to my blog later on. -- Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@egjug.org | +20103836920 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
|
|
|
Re: Re: [dwr-user] Singleton CreatorRegards, On 4/10/07, Joe Walker <joe@...> wrote:
-- Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@ egjug.org | +20103836920 |
|
|
Re: [dwr-user] Singleton Creator hi,
I found your method very interesting but you did not mention how to add the tag "creator". For the readers: it takes place between tag "init". I also have a question it is possible that DWR share the same instance with a bean?. For example I create an instance of a class with DWR and I want to access it by a bean declared on another page jsp. thx. MehdiNux |
|
|
Re: [dwr-user] Singleton CreatorYes, creators can specify a scope attirbute.
See the DWR docs: http://getahead.org/dwr/server/dwrxml/creators mehdiNux wrote: > hi, > I found your method very interesting but you did not mention how to add > the tag "creator". For the readers: it takes place between tag "init". > I also have a question it is possible that DWR share the same instance > with a bean?. > For example I create an instance of a class with DWR and I want to access > it by a bean declared on another page jsp. > thx. > > MehdiNux > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: [dwr-user] Singleton Creatoryes I know but the scope share session juste with other call of DWRfunction ca .
when I declare a bean as <jsp:useBean id="MyBean" scope="session " class="Myclass"> it creates another instance of Myclass even if I put a scope application. in other words when I declare an instance regardless of the scope with DWR , it ll be visible just in the DWR
|
|
|
Re: [dwr-user] Singleton CreatorOk, I misunderstood your first response.
You would like your jsp:useBean tag to locate the DWR created instance in the session (and not create a new instance). Is that correct? Sure this could be done. DWR does keep the session scoped bean in the session. The problem you are having is that the key that DWR uses is not "MyBean". I think (I am not sure) that DWR keys the bean based on the javascript attribute on the create element specified in your configuration. So try something like: jsp:useBean id="whatever your javascript attribute is on your creator" If that doesn't give you what you are looking for than I am wrong and you can debug the session to find the correct key to use. mehdiNux wrote: > yes I know but the scope share session juste with other call of DWRfunction > ca . > when I declare a bean as <jsp:useBean id="MyBean" scope="session " > class="Myclass"> it creates another instance of Myclass even if I put a > scope application. > in other words when I declare an instance regardless of the scope with DWR , > it ll be visible just in the DWR > > > > David Marginian-2 wrote: > >> Yes, creators can specify a scope attirbute. >> >> See the DWR docs: >> http://getahead.org/dwr/server/dwrxml/creators >> >> mehdiNux wrote: >> >>> hi, >>> I found your method very interesting but you did not mention how to >>> add >>> the tag "creator". For the readers: it takes place between tag "init". >>> I also have a question it is possible that DWR share the same >>> instance >>> with a bean?. >>> For example I create an instance of a class with DWR and I want to >>> access >>> it by a bean declared on another page jsp. >>> thx. >>> >>> MehdiNux >>> >>> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@... >> For additional commands, e-mail: dev-help@... >> >> >> >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: [dwr-user] Singleton Creatorthank you very much David Marginian-2 ,it works very well it's what I needed
. I did not know that the id is so important lol.
sorry for my bad English lol .
thx MehdiNux
|
|
|
Re: [dwr-user] Singleton CreatorNo problem glad it is working for you.
mehdiNux wrote: > thank you very much David Marginian-2 ,it works very well it's what I needed > :jumping:. I did not know that the id is so important lol. > sorry for my bad English lol:-D. > thx > MehdiNux > > David Marginian-2 wrote: > >> Ok, I misunderstood your first response. >> >> You would like your jsp:useBean tag to locate the DWR created instance >> in the session (and not create a new instance). Is that correct? Sure >> this could be done. DWR does keep the session scoped bean in the >> session. The problem you are having is that the key that DWR uses is >> not "MyBean". I think (I am not sure) that DWR keys the bean based on >> the javascript attribute on the create element specified in your >> configuration. >> >> So try something like: >> jsp:useBean id="whatever your javascript attribute is on your creator" >> >> If that doesn't give you what you are looking for than I am wrong and >> you can debug the session to find the correct key to use. >> >> mehdiNux wrote: >> >>> yes I know but the scope share session juste with other call of >>> DWRfunction >>> ca . >>> when I declare a bean as <jsp:useBean id="MyBean" scope="session " >>> class="Myclass"> it creates another instance of Myclass even if I put a >>> scope application. >>> in other words when I declare an instance regardless of the scope with >>> DWR , >>> it ll be visible just in the DWR >>> >>> >>> >>> David Marginian-2 wrote: >>> >>> >>>> Yes, creators can specify a scope attirbute. >>>> >>>> See the DWR docs: >>>> http://getahead.org/dwr/server/dwrxml/creators >>>> >>>> mehdiNux wrote: >>>> >>>> >>>>> hi, >>>>> I found your method very interesting but you did not mention how to >>>>> add >>>>> the tag "creator". For the readers: it takes place between tag "init". >>>>> I also have a question it is possible that DWR share the same >>>>> instance >>>>> with a bean?. >>>>> For example I create an instance of a class with DWR and I want to >>>>> access >>>>> it by a bean declared on another page jsp. >>>>> thx. >>>>> >>>>> MehdiNux >>>>> >>>>> >>>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: dev-unsubscribe@... >>>> For additional commands, e-mail: dev-help@... >>>> >>>> >>>> >>>> >>>> >>> >>> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@... >> For additional commands, e-mail: dev-help@... >> >> >> >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
| Free embeddable forum powered by Nabble | Forum Help |