aspose file tools*
The moose likes JSF and the fly likes Influence from JavaScript on FacesPortlet-Lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Influence from JavaScript on FacesPortlet-Lifecycle" Watch "Influence from JavaScript on FacesPortlet-Lifecycle" New topic
Author

Influence from JavaScript on FacesPortlet-Lifecycle

Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
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.

Situation
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?

Workarounds?
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


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Influence from JavaScript on FacesPortlet-Lifecycle
 
Similar Threads
HtmlCommandLink in a custom component
getCurrentValue() returning an old value! a4j and JSF 1.2. Help needed ASAP!
JSF Login problem
JSF Custom Component ,IBM Portal 7
help required on a4j commandButton