• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Influence from JavaScript on FacesPortlet-Lifecycle

Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

Since seveal days I'm stumbling over strange Lifecycle-Problem which I don't understand, so perhaps anyone can explain it to me.

I've developed an Faces-Component which display an standard message-text to the user. Within my custom component I'm using an button, which action-attribute uses a method-binding and points to method of a backing bean. Because the button should be invisible, my custom component does also write some JavaScript which "clicks" in my invisible button and so activates the code of the backing bean method.

The strange behavior
At runtime I get an "duplicated component exception" that indicates that Faces tries to add my hidden button twice. The reason for this exception is that the encodeBegin()-method of my custom component is executed twice, and so the same button will be added a second time to my component tree. I'm not able to understand why encodeBegin() is executed twice, any suggestions?

1)The first point which affects the two executions of the encodeBegin()-method is my JavaScript-code inside my custom component. If I wrap the click()-action with an setTimeout(<buttonClick>, <1 Second>)-method, then is my encodeBegin()-method only executed ones and everything is working as expected. The problem on this workaround is that I don't want to wait 1 second, so I tried to minimize to delay to 10 milliseconds, which works also well. With an delay under 5 milliseconds I receive a strange scenario, sometimes the encodeBegin() method is called once and sometimes twice. Nice. I don't want to use this solution, because on my machine the critical delay is 5 milliseconds but on another machine its 20 or more milliseconds, and so my solution would be bugy.

2) Another approach is to modify the encodeBegin()-method of custom component. My first idea was to create a boolean variable which ensure that the code inside of my encodeBegin()-method is executed only once. The first time I access an page where the tag is used this works perfect, but when I try to see the page a second (or third) time (reload) then I see only a blank page..., because the component-code of my encodeBegin() isn't executed.

3) Ok, if option 2 doesn't work, then my next thought was to ensure that only the creation of the button-component inside my custom-component will be created once, so that no duplicated component id exception occurs. At runtime I see my wait-Text, but the the (action)-method of my backing bean is never executed. In debug-mode I see that the encodeBegin()-method is executed over and over, all time, nice endless-loop...

Any ideas or experiences?

Best regards,
Christian Nicoll
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic