ViewScoped bean created multiple times?

2014-11-07 Thread Bjørn T Johansen
I trying to create a webapplication using request and/or viewscope instead of 
sessionscope, which I have always used... (Neved needed to concern
myself with memory usage in the apps I have implemented.. :) )
But I now have a problem using @ViewScoped..
When I access index.xhtml which uses a managed bean in viewscope, the 
constructor is called multiple times. And the same with an init method, that
should be called only once. I am using..:





..

to call the init method, but I have also tried using f:event prerenderView and 
also @PostConstruct but I am not able to make the bean call the init
method only once...

What am I missing?


Regards,

BTJ
-- 
---
Bjørn T Johansen

b...@havleik.no
---
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic 
messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"
---


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Kito Mann
Hello Bjorn,

Do you have component bindings in your page (i.e )? That causes the exact behavior you're
describing in versions of JSF prior to 2.2. What version of MyFaces are you
using?

___

Kito D. Mann | @kito99 | Author, JSF in Action
Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and consulting
http://www.JSFCentral.com | @jsfcentral
+1 203-998-0403

* Listen to the Enterprise Java Newscast: *http://
enterprisejavanews.com
*
* JSFCentral Interviews Podcast:
http://www.jsfcentral.com/resources/jsfcentralpodcasts/
* Sign up for the JSFCentral Newsletter: http://oi.vresp.com/?fid=ac048d0e17

On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:

> I trying to create a webapplication using request and/or viewscope instead
> of sessionscope, which I have always used... (Neved needed to concern
> myself with memory usage in the apps I have implemented.. :) )
> But I now have a problem using @ViewScoped..
> When I access index.xhtml which uses a managed bean in viewscope, the
> constructor is called multiple times. And the same with an init method, that
> should be called only once. I am using..:
>
> 
> 
> 
>
> ..
>
> to call the init method, but I have also tried using f:event prerenderView
> and also @PostConstruct but I am not able to make the bean call the init
> method only once...
>
> What am I missing?
>
>
> Regards,
>
> BTJ
> --
>
> ---
> Bjørn T Johansen
>
> b...@havleik.no
>
> ---
> Someone wrote:
> "I understand that if you play a Windows CD backwards you hear strange
> Satanic messages"
> To which someone replied:
> "It's even worse than that; play it forwards and it installs Windows"
>
> ---
>


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Howard W. Smith, Jr.
Interesting, you asked the same question in PrimeFaces forum.

http://forum.primefaces.org/viewtopic.php?f=3&t=40267


On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:

> I trying to create a webapplication using request and/or viewscope instead
> of sessionscope, which I have always used... (Neved needed to concern
> myself with memory usage in the apps I have implemented.. :) )
> But I now have a problem using @ViewScoped..
> When I access index.xhtml which uses a managed bean in viewscope, the
> constructor is called multiple times. And the same with an init method, that
> should be called only once. I am using..:
>
> 
> 
> 
>
> ..
>
> to call the init method, but I have also tried using f:event prerenderView
> and also @PostConstruct but I am not able to make the bean call the init
> method only once...
>
> What am I missing?
>
>
> Regards,
>
> BTJ
> --
>
> ---
> Bjørn T Johansen
>
> b...@havleik.no
>
> ---
> Someone wrote:
> "I understand that if you play a Windows CD backwards you hear strange
> Satanic messages"
> To which someone replied:
> "It's even worse than that; play it forwards and it installs Windows"
>
> ---
>


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Bjørn T Johansen
No bindings...  And using Myfaces 2.2.5

BTJ

On Fri, 7 Nov 2014 15:57:00 -0500
Kito Mann  wrote:

> Hello Bjorn,
> 
> Do you have component bindings in your page (i.e  binding="#{myBean.comp}"/>)? That causes the exact behavior you're
> describing in versions of JSF prior to 2.2. What version of MyFaces are you
> using?
> 
> ___
> 
> Kito D. Mann | @kito99 | Author, JSF in Action
> Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and consulting
> http://www.JSFCentral.com | @jsfcentral
> +1 203-998-0403
> 
> * Listen to the Enterprise Java Newscast: *http://
> enterprisejavanews.com
> *
> * JSFCentral Interviews Podcast:
> http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> * Sign up for the JSFCentral Newsletter: http://oi.vresp.com/?fid=ac048d0e17
> 
> On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> 
> > I trying to create a webapplication using request and/or viewscope instead
> > of sessionscope, which I have always used... (Neved needed to concern
> > myself with memory usage in the apps I have implemented.. :) )
> > But I now have a problem using @ViewScoped..
> > When I access index.xhtml which uses a managed bean in viewscope, the
> > constructor is called multiple times. And the same with an init method, that
> > should be called only once. I am using..:
> >
> > 
> > 
> > 
> >
> > ..
> >
> > to call the init method, but I have also tried using f:event prerenderView
> > and also @PostConstruct but I am not able to make the bean call the init
> > method only once...
> >
> > What am I missing?
> >
> >
> > Regards,
> >
> > BTJ
> > --
> >
> > ---
> > Bjørn T Johansen
> >
> > b...@havleik.no
> >
> > ---
> > Someone wrote:
> > "I understand that if you play a Windows CD backwards you hear strange
> > Satanic messages"
> > To which someone replied:
> > "It's even worse than that; play it forwards and it installs Windows"
> >
> > ---
> >


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Bjørn T Johansen
Yes, I did.. But since I did not get any answer there and I thought that this 
was more a JSF question than a PrimeFaces question, I thought I should
try here Was that wrong?

BTJ

On Fri, 7 Nov 2014 15:58:59 -0500
"Howard W. Smith, Jr."  wrote:

> Interesting, you asked the same question in PrimeFaces forum.
> 
> http://forum.primefaces.org/viewtopic.php?f=3&t=40267
> 
> 
> On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> 
> > I trying to create a webapplication using request and/or viewscope instead
> > of sessionscope, which I have always used... (Neved needed to concern
> > myself with memory usage in the apps I have implemented.. :) )
> > But I now have a problem using @ViewScoped..
> > When I access index.xhtml which uses a managed bean in viewscope, the
> > constructor is called multiple times. And the same with an init method, that
> > should be called only once. I am using..:
> >
> > 
> > 
> > 
> >
> > ..
> >
> > to call the init method, but I have also tried using f:event prerenderView
> > and also @PostConstruct but I am not able to make the bean call the init
> > method only once...
> >
> > What am I missing?
> >
> >
> > Regards,
> >
> > BTJ
> > --
> >
> > ---
> > Bjørn T Johansen
> >
> > b...@havleik.no
> >
> > ---
> > Someone wrote:
> > "I understand that if you play a Windows CD backwards you hear strange
> > Satanic messages"
> > To which someone replied:
> > "It's even worse than that; play it forwards and it installs Windows"
> >
> > ---
> >



Re: ViewScoped bean created multiple times?

2014-11-07 Thread Howard W. Smith, Jr.
That's fine.

Can you provide your XHTML and java bean definition (source code) here? You
provided a little bit of your java bean in primefaces forum.

Your XHTML and java bean may help us on this list to help you.


On Fri, Nov 7, 2014 at 4:11 PM, Bjørn T Johansen  wrote:

> Yes, I did.. But since I did not get any answer there and I thought that
> this was more a JSF question than a PrimeFaces question, I thought I should
> try here Was that wrong?
>
> BTJ
>
> On Fri, 7 Nov 2014 15:58:59 -0500
> "Howard W. Smith, Jr."  wrote:
>
> > Interesting, you asked the same question in PrimeFaces forum.
> >
> > http://forum.primefaces.org/viewtopic.php?f=3&t=40267
> >
> >
> > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> >
> > > I trying to create a webapplication using request and/or viewscope
> instead
> > > of sessionscope, which I have always used... (Neved needed to concern
> > > myself with memory usage in the apps I have implemented.. :) )
> > > But I now have a problem using @ViewScoped..
> > > When I access index.xhtml which uses a managed bean in viewscope, the
> > > constructor is called multiple times. And the same with an init
> method, that
> > > should be called only once. I am using..:
> > >
> > > 
> > > 
> > > 
> > >
> > > ..
> > >
> > > to call the init method, but I have also tried using f:event
> prerenderView
> > > and also @PostConstruct but I am not able to make the bean call the
> init
> > > method only once...
> > >
> > > What am I missing?
> > >
> > >
> > > Regards,
> > >
> > > BTJ
> > > --
> > >
> > >
> ---
> > > Bjørn T Johansen
> > >
> > > b...@havleik.no
> > >
> > >
> ---
> > > Someone wrote:
> > > "I understand that if you play a Windows CD backwards you hear strange
> > > Satanic messages"
> > > To which someone replied:
> > > "It's even worse than that; play it forwards and it installs Windows"
> > >
> > >
> ---
> > >
>
>


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Bjørn T Johansen
That I can do... :)

Attached...


BTJ

On Fri, 7 Nov 2014 16:14:55 -0500
"Howard W. Smith, Jr."  wrote:

> That's fine.
> 
> Can you provide your XHTML and java bean definition (source code) here? You
> provided a little bit of your java bean in primefaces forum.
> 
> Your XHTML and java bean may help us on this list to help you.
> 
> 
> On Fri, Nov 7, 2014 at 4:11 PM, Bjørn T Johansen  wrote:
> 
> > Yes, I did.. But since I did not get any answer there and I thought that
> > this was more a JSF question than a PrimeFaces question, I thought I should
> > try here Was that wrong?
> >
> > BTJ
> >
> > On Fri, 7 Nov 2014 15:58:59 -0500
> > "Howard W. Smith, Jr."  wrote:
> >
> > > Interesting, you asked the same question in PrimeFaces forum.
> > >
> > > http://forum.primefaces.org/viewtopic.php?f=3&t=40267
> > >
> > >
> > > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> > >
> > > > I trying to create a webapplication using request and/or viewscope
> > instead
> > > > of sessionscope, which I have always used... (Neved needed to concern
> > > > myself with memory usage in the apps I have implemented.. :) )
> > > > But I now have a problem using @ViewScoped..
> > > > When I access index.xhtml which uses a managed bean in viewscope, the
> > > > constructor is called multiple times. And the same with an init
> > method, that
> > > > should be called only once. I am using..:
> > > >
> > > > 
> > > > 
> > > > 
> > > >
> > > > ..
> > > >
> > > > to call the init method, but I have also tried using f:event
> > prerenderView
> > > > and also @PostConstruct but I am not able to make the bean call the
> > init
> > > > method only once...
> > > >
> > > > What am I missing?
> > > >
> > > >
> > > > Regards,
> > > >
> > > > BTJ
> > > > --
> > > >
> > > >
> > ---
> > > > Bjørn T Johansen
> > > >
> > > > b...@havleik.no
> > > >
> > > >
> > ---
> > > > Someone wrote:
> > > > "I understand that if you play a Windows CD backwards you hear strange
> > > > Satanic messages"
> > > > To which someone replied:
> > > > "It's even worse than that; play it forwards and it installs Windows"
> > > >
> > > >
> > ---
> > > >
> >
> >


index.xhtml
Description: application/xhtml
package no.havleik.kbnjulekalender.controller;

import no.havleik.kbnjulekalender.model.Price;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Bjørn T Johansen on 26.10.2014
 */
@ManagedBean(name = "calendarController")
@ViewScoped
public class CalendarController implements Serializable
{
private static final long serialVersionUID = 108478021854906487L;

private static final Logger log = LoggerFactory.getLogger(CalendarController.class);

@ManagedProperty(value="#{priceController}")
private PriceController priceController;

List priceList = new ArrayList<>();

public CalendarController()
{
super();
System.out.println("Constructor of CalendarController");
//log.debug("All prices size = {}", priceController.getPriceListAll().size());
}

public String initPrices()
{
log.debug("Initializing prices...");
priceList.clear();
for (Price price : priceController.getPriceListAll())
{
priceList.add(price);
}

return null;
}

public List getPriceList()
{
return priceList;
}

public void setPriceController(PriceController priceController)
{
this.priceController = priceController;
}
}


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Kito Mann
OK. What version do you have in your faces-config.xml file? Also, do you
have javax.faces.PARTIAL_STATE_SAVING set to false in web.xml?

___

Kito D. Mann | @kito99 | Author, JSF in Action
Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and consulting
http://www.JSFCentral.com | @jsfcentral
+1 203-998-0403

* Listen to the Enterprise Java Newscast: *http://
enterprisejavanews.com
*
* JSFCentral Interviews Podcast:
http://www.jsfcentral.com/resources/jsfcentralpodcasts/
* Sign up for the JSFCentral Newsletter: http://oi.vresp.com/?fid=ac048d0e17

On Fri, Nov 7, 2014 at 4:09 PM, Bjørn T Johansen  wrote:

> No bindings...  And using Myfaces 2.2.5
>
> BTJ
>
> On Fri, 7 Nov 2014 15:57:00 -0500
> Kito Mann  wrote:
>
> > Hello Bjorn,
> >
> > Do you have component bindings in your page (i.e  > binding="#{myBean.comp}"/>)? That causes the exact behavior you're
> > describing in versions of JSF prior to 2.2. What version of MyFaces are
> you
> > using?
> >
> > ___
> >
> > Kito D. Mann | @kito99 | Author, JSF in Action
> > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> consulting
> > http://www.JSFCentral.com | @jsfcentral
> > +1 203-998-0403
> >
> > * Listen to the Enterprise Java Newscast: *http://
> > enterprisejavanews.com
> > *
> > * JSFCentral Interviews Podcast:
> > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > * Sign up for the JSFCentral Newsletter:
> http://oi.vresp.com/?fid=ac048d0e17
> >
> > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> >
> > > I trying to create a webapplication using request and/or viewscope
> instead
> > > of sessionscope, which I have always used... (Neved needed to concern
> > > myself with memory usage in the apps I have implemented.. :) )
> > > But I now have a problem using @ViewScoped..
> > > When I access index.xhtml which uses a managed bean in viewscope, the
> > > constructor is called multiple times. And the same with an init
> method, that
> > > should be called only once. I am using..:
> > >
> > > 
> > > 
> > > 
> > >
> > > ..
> > >
> > > to call the init method, but I have also tried using f:event
> prerenderView
> > > and also @PostConstruct but I am not able to make the bean call the
> init
> > > method only once...
> > >
> > > What am I missing?
> > >
> > >
> > > Regards,
> > >
> > > BTJ
> > > --
> > >
> > >
> ---
> > > Bjørn T Johansen
> > >
> > > b...@havleik.no
> > >
> > >
> ---
> > > Someone wrote:
> > > "I understand that if you play a Windows CD backwards you hear strange
> > > Satanic messages"
> > > To which someone replied:
> > > "It's even worse than that; play it forwards and it installs Windows"
> > >
> > >
> ---
> > >
>


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Bjørn T Johansen
2.2, like this.:

http://xmlns.jcp.org/xml/ns/javaee";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"; 
version="2.2">


No, javax.faces.PARTIAL_STATE_SAVING is set to true...


BTJ

On Fri, 7 Nov 2014 16:21:29 -0500
Kito Mann  wrote:

> OK. What version do you have in your faces-config.xml file? Also, do you
> have javax.faces.PARTIAL_STATE_SAVING set to false in web.xml?
> 
> ___
> 
> Kito D. Mann | @kito99 | Author, JSF in Action
> Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and consulting
> http://www.JSFCentral.com | @jsfcentral
> +1 203-998-0403
> 
> * Listen to the Enterprise Java Newscast: *http://
> enterprisejavanews.com
> *
> * JSFCentral Interviews Podcast:
> http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> * Sign up for the JSFCentral Newsletter: http://oi.vresp.com/?fid=ac048d0e17
> 
> On Fri, Nov 7, 2014 at 4:09 PM, Bjørn T Johansen  wrote:
> 
> > No bindings...  And using Myfaces 2.2.5
> >
> > BTJ
> >
> > On Fri, 7 Nov 2014 15:57:00 -0500
> > Kito Mann  wrote:
> >
> > > Hello Bjorn,
> > >
> > > Do you have component bindings in your page (i.e  > > binding="#{myBean.comp}"/>)? That causes the exact behavior you're
> > > describing in versions of JSF prior to 2.2. What version of MyFaces are
> > you
> > > using?
> > >
> > > ___
> > >
> > > Kito D. Mann | @kito99 | Author, JSF in Action
> > > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> > consulting
> > > http://www.JSFCentral.com | @jsfcentral
> > > +1 203-998-0403
> > >
> > > * Listen to the Enterprise Java Newscast: *http://
> > > enterprisejavanews.com
> > > *
> > > * JSFCentral Interviews Podcast:
> > > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > > * Sign up for the JSFCentral Newsletter:
> > http://oi.vresp.com/?fid=ac048d0e17
> > >
> > > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  wrote:
> > >
> > > > I trying to create a webapplication using request and/or viewscope
> > instead
> > > > of sessionscope, which I have always used... (Neved needed to concern
> > > > myself with memory usage in the apps I have implemented.. :) )
> > > > But I now have a problem using @ViewScoped..
> > > > When I access index.xhtml which uses a managed bean in viewscope, the
> > > > constructor is called multiple times. And the same with an init
> > method, that
> > > > should be called only once. I am using..:
> > > >
> > > > 
> > > > 
> > > > 
> > > >
> > > > ..
> > > >
> > > > to call the init method, but I have also tried using f:event
> > prerenderView
> > > > and also @PostConstruct but I am not able to make the bean call the
> > init
> > > > method only once...
> > > >
> > > > What am I missing?
> > > >
> > > >
> > > > Regards,
> > > >
> > > > BTJ
> > > > --
> > > >
> > > >
> > ---
> > > > Bjørn T Johansen
> > > >
> > > > b...@havleik.no
> > > >
> > > >
> > ---
> > > > Someone wrote:
> > > > "I understand that if you play a Windows CD backwards you hear strange
> > > > Satanic messages"
> > > > To which someone replied:
> > > > "It's even worse than that; play it forwards and it installs Windows"
> > > >
> > > >
> > ---
> > > >
> >



Re: ViewScoped bean created multiple times?

2014-11-07 Thread Thomas Andraschko
Constructor is called multiple times by design - thats how object
serialization works.
Serislization is enabled by default in myfaces to support
clustering/failover.

No clue about viewaction - i cant use jsf 2.2.

Am Freitag, 7. November 2014 schrieb Bjørn T Johansen :

> 2.2, like this.:
>
> http://xmlns.jcp.org/xml/ns/javaee";
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd";
> version="2.2">
>
>
> No, javax.faces.PARTIAL_STATE_SAVING is set to true...
>
>
> BTJ
>
> On Fri, 7 Nov 2014 16:21:29 -0500
> Kito Mann > wrote:
>
> > OK. What version do you have in your faces-config.xml file? Also, do you
> > have javax.faces.PARTIAL_STATE_SAVING set to false in web.xml?
> >
> > ___
> >
> > Kito D. Mann | @kito99 | Author, JSF in Action
> > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> consulting
> > http://www.JSFCentral.com | @jsfcentral
> > +1 203-998-0403
> >
> > * Listen to the Enterprise Java Newscast: *http://
> > enterprisejavanews.com
> > *
> > * JSFCentral Interviews Podcast:
> > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > * Sign up for the JSFCentral Newsletter:
> http://oi.vresp.com/?fid=ac048d0e17
> >
> > On Fri, Nov 7, 2014 at 4:09 PM, Bjørn T Johansen  > wrote:
> >
> > > No bindings...  And using Myfaces 2.2.5
> > >
> > > BTJ
> > >
> > > On Fri, 7 Nov 2014 15:57:00 -0500
> > > Kito Mann > wrote:
> > >
> > > > Hello Bjorn,
> > > >
> > > > Do you have component bindings in your page (i.e  > > > binding="#{myBean.comp}"/>)? That causes the exact behavior you're
> > > > describing in versions of JSF prior to 2.2. What version of MyFaces
> are
> > > you
> > > > using?
> > > >
> > > > ___
> > > >
> > > > Kito D. Mann | @kito99 | Author, JSF in Action
> > > > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> > > consulting
> > > > http://www.JSFCentral.com | @jsfcentral
> > > > +1 203-998-0403
> > > >
> > > > * Listen to the Enterprise Java Newscast: *http://
> > > > enterprisejavanews.com
> > > > *
> > > > * JSFCentral Interviews Podcast:
> > > > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > > > * Sign up for the JSFCentral Newsletter:
> > > http://oi.vresp.com/?fid=ac048d0e17
> > > >
> > > > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  > wrote:
> > > >
> > > > > I trying to create a webapplication using request and/or viewscope
> > > instead
> > > > > of sessionscope, which I have always used... (Neved needed to
> concern
> > > > > myself with memory usage in the apps I have implemented.. :) )
> > > > > But I now have a problem using @ViewScoped..
> > > > > When I access index.xhtml which uses a managed bean in viewscope,
> the
> > > > > constructor is called multiple times. And the same with an init
> > > method, that
> > > > > should be called only once. I am using..:
> > > > >
> > > > > 
> > > > > 
> > > > > 
> > > > >
> > > > > ..
> > > > >
> > > > > to call the init method, but I have also tried using f:event
> > > prerenderView
> > > > > and also @PostConstruct but I am not able to make the bean call the
> > > init
> > > > > method only once...
> > > > >
> > > > > What am I missing?
> > > > >
> > > > >
> > > > > Regards,
> > > > >
> > > > > BTJ
> > > > > --
> > > > >
> > > > >
> > >
> ---
> > > > > Bjørn T Johansen
> > > > >
> > > > > b...@havleik.no 
> > > > >
> > > > >
> > >
> ---
> > > > > Someone wrote:
> > > > > "I understand that if you play a Windows CD backwards you hear
> strange
> > > > > Satanic messages"
> > > > > To which someone replied:
> > > > > "It's even worse than that; play it forwards and it installs
> Windows"
> > > > >
> > > > >
> > >
> ---
> > > > >
> > >
>
>


Re: ViewScoped bean created multiple times?

2014-11-07 Thread Leonardo Uribe
Hi

In my opinion, you should use @PostConstruct annotation over init method.

But the code has an entry like this:

@ManagedProperty(value="#{priceController}")
private PriceController priceController;

Since this is inside a view scope bean, PriceController instance is saved
with
the view scope bean. It is a pitfall of JSF managed beans, solved in CDI
beans.

My suggestions is don't use @ManagedProperty inside the view scope bean
and instead use facesContext.getApplication().evaluateExpressionGet(...)
to get your beans, so you can always have the right instance without include
it into the state. The best strategy in my opinion is use request scope
beans
for encode behavior and view scope beans as data holders.

regards

Leonardo Uribe


2014-11-07 19:02 GMT-05:00 Thomas Andraschko :

> Constructor is called multiple times by design - thats how object
> serialization works.
> Serislization is enabled by default in myfaces to support
> clustering/failover.
>
> No clue about viewaction - i cant use jsf 2.2.
>
> Am Freitag, 7. November 2014 schrieb Bjørn T Johansen :
>
> > 2.2, like this.:
> >
> > http://xmlns.jcp.org/xml/ns/javaee";
> >   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> >   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> > http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd";
> > version="2.2">
> >
> >
> > No, javax.faces.PARTIAL_STATE_SAVING is set to true...
> >
> >
> > BTJ
> >
> > On Fri, 7 Nov 2014 16:21:29 -0500
> > Kito Mann > wrote:
> >
> > > OK. What version do you have in your faces-config.xml file? Also, do
> you
> > > have javax.faces.PARTIAL_STATE_SAVING set to false in web.xml?
> > >
> > > ___
> > >
> > > Kito D. Mann | @kito99 | Author, JSF in Action
> > > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> > consulting
> > > http://www.JSFCentral.com | @jsfcentral
> > > +1 203-998-0403
> > >
> > > * Listen to the Enterprise Java Newscast: *http://
> > > enterprisejavanews.com
> > > *
> > > * JSFCentral Interviews Podcast:
> > > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > > * Sign up for the JSFCentral Newsletter:
> > http://oi.vresp.com/?fid=ac048d0e17
> > >
> > > On Fri, Nov 7, 2014 at 4:09 PM, Bjørn T Johansen  > > wrote:
> > >
> > > > No bindings...  And using Myfaces 2.2.5
> > > >
> > > > BTJ
> > > >
> > > > On Fri, 7 Nov 2014 15:57:00 -0500
> > > > Kito Mann > wrote:
> > > >
> > > > > Hello Bjorn,
> > > > >
> > > > > Do you have component bindings in your page (i.e  > > > > binding="#{myBean.comp}"/>)? That causes the exact behavior you're
> > > > > describing in versions of JSF prior to 2.2. What version of MyFaces
> > are
> > > > you
> > > > > using?
> > > > >
> > > > > ___
> > > > >
> > > > > Kito D. Mann | @kito99 | Author, JSF in Action
> > > > > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and
> > > > consulting
> > > > > http://www.JSFCentral.com | @jsfcentral
> > > > > +1 203-998-0403
> > > > >
> > > > > * Listen to the Enterprise Java Newscast: *http://
> > > > > enterprisejavanews.com
> > > > > *
> > > > > * JSFCentral Interviews Podcast:
> > > > > http://www.jsfcentral.com/resources/jsfcentralpodcasts/
> > > > > * Sign up for the JSFCentral Newsletter:
> > > > http://oi.vresp.com/?fid=ac048d0e17
> > > > >
> > > > > On Fri, Nov 7, 2014 at 3:42 PM, Bjørn T Johansen  > > wrote:
> > > > >
> > > > > > I trying to create a webapplication using request and/or
> viewscope
> > > > instead
> > > > > > of sessionscope, which I have always used... (Neved needed to
> > concern
> > > > > > myself with memory usage in the apps I have implemented.. :) )
> > > > > > But I now have a problem using @ViewScoped..
> > > > > > When I access index.xhtml which uses a managed bean in viewscope,
> > the
> > > > > > constructor is called multiple times. And the same with an init
> > > > method, that
> > > > > > should be called only once. I am using..:
> > > > > >
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > >
> > > > > > ..
> > > > > >
> > > > > > to call the init method, but I have also tried using f:event
> > > > prerenderView
> > > > > > and also @PostConstruct but I am not able to make the bean call
> the
> > > > init
> > > > > > method only once...
> > > > > >
> > > > > > What am I missing?
> > > > > >
> > > > > >
> > > > > > Regards,
> > > > > >
> > > > > > BTJ
> > > > > > --
> > > > > >
> > > > > >
> > > >
> >
> ---
> > > > > > Bjørn T Johansen
> > > > > >
> > > > > > b...@havleik.no 
> > > > > >
> > > > > >
> > > >
> >
> ---
> > > > > > Someone wrote:
> > > > > > "I understand that if you play a Windows CD backwards you hear