myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Diaz" <alexwar...@gmail.com>
Subject Re: managed bean with request scope
Date Thu, 02 Oct 2008 22:35:45 GMT
I put a breakpoint and the first time the page is loaded the constructor  
is called, but after that the constructor is not called anymore.

On Thu, 02 Oct 2008 15:46:39 -0400, Guy Bashan <guy.bashan@gmail.com>  
wrote:

> This sounds very weird...
> Did you try something else rather that print the query string?
> 1) Try to put there a breakpoint and see if it is hit.
> 2) Try to output from the method some random value (something like  
> Math.random()) and see if it changes.
> 3) Try to make "hard" refresh (ctrl+f5) to eliminate some caching issues  
> (it's weak, but just in case...)
> 4) Try to open another browser session (even with a different browser)  
> to see if the bean will be created with a different session.
>
>
>
> -----Original Message-----
> From: Alex Diaz [mailto:alexware69@gmail.com]
> Sent: Thursday, October 02, 2008 9:12 PM
> To: MyFaces Discussion
> Subject: Re: managed bean with request scope
>
> Andrew, thanks for your answer. The bean is created the first time and I
> know that because I have an EL reference to a property of that bean. What
> I am trying to do is to get the url query string passed along with the
> request and print it (for testing). The first time I call the page it
> succesfully get the url query string , but the second time I call the  
> page
> it wont execute the constructor and then the property used by the EL wont
> change to the new url query string.
>
> On Thu, 02 Oct 2008 13:59:34 -0400, Andrew Robinson
> <andrew.rw.robinson@gmail.com> wrote:
>
>> No, the point is that beans are not created until they are used.
>>
>> So if you have <h:outputText value="#{myBean.someVariable}" />, and then
>> that component is rendered, the OutputTextRenderer will call getValue()
>> on
>> the HtmlOutputText component. This causes #{myBean.someVariable} to be
>> evaluated. When faces sees that myBean is a request scope bean but does
>> not
>> exist yet, it creates one. Then getSomeVariable() is called on that new
>> instance.
>>
>> Therefore, managed beans are only created when they are asked for by the
>> EL
>> resolver. So unless you actually evaluate #{myBean} or a property of
>> myBean,
>> myBean will never be created. This is for performance. If there is no
>> request for a java bean, why create one?
>>
>> So to your original question, you say your constructor is not called, my
>> question is if you are sure you bean is even being used. The constructor
>> will only be called when the bean is needed.
>>
>> -Andrew
>>
>> On Thu, Oct 2, 2008 at 11:56 AM, Alex Diaz <alexware69@gmail.com> wrote:
>>
>>> Yes I have a reference like that. should I remove it?
>>>
>>>
>>> On Thu, 02 Oct 2008 12:52:37 -0400,
>>> <Matt.Rossner-prest@sanofi-aventis.com>
>>> wrote:
>>>
>>>  It just means you have some EL reference in the page like
>>>>
>>>> <t:outputText value="#{myBean.someVariable}" />
>>>>
>>>> In this case "myBean" is being referenced.
>>>>
>>>> -----Original Message-----
>>>> From: Alex Diaz [mailto:alexware69@gmail.com]
>>>> Sent: jeudi 2 octobre 2008 18:28
>>>> To: MyFaces Discussion
>>>> Subject: Re: managed bean with request scope
>>>>
>>>> I dont know what referred means?
>>>>
>>>> On Thu, 02 Oct 2008 11:31:58 -0400, Andrew Robinson
>>>> <andrew.rw.robinson@gmail.com> wrote:
>>>>
>>>>  Is your bean referred to? Beans are created lazily, so if the EL
>>>>>
>>>> engine
>>>>
>>>>> never resolves that bean, it will not be created.
>>>>>
>>>>> On Thu, Oct 2, 2008 at 7:47 AM, Alex Diaz <alexware69@gmail.com>
>>>>>
>>>> wrote:
>>>>
>>>>>
>>>>>  Are the managed beans with request scope destroyed after each  
>>>>> request
>>>>>>
>>>>>
>>>>  to a
>>>>>> page? If so, then why the beans constructor is not being called 

>>>>>> after
>>>>>> subsequent requests?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> --
>>>>>> Using Opera's revolutionary e-mail client:  
>>>>>> http://www.opera.com/mail/
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>>>
>
>
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Mime
View raw message