users@woodstock.java.net

Re: setProps invokes handling function value

From: Dan Labrecque <Dan.Labrecque_at_Sun.COM>
Date: Fri, 22 Feb 2008 20:09:24 -0500

I believe the alert is being evaluated immediately as an object literal
value -- before the call to setProps is ever made. Here is my test case,
which works fine on Firefox 2.0.0.12 and IE 7.

<script type="text/javascript">
  function test() {
    alert('Test two');
  }
  function initTest() {
    var domNode = document.getElementById('form1:test2');
    domNode.setProps({
     onClick: test
    });
  }
</script>
<webuijsf:button id="test1" text="Init onClick"
onClick="initTest();return false;"/>
<webuijsf:button id="test2" text="Test" onClick="alert('Test
one');return false;"/>

You can also take the above code and make it work for your example, like
so. Just don't execute an alert inside a JSON object.

<input type="button" value="Register"
onClick="document.getElementById('form1:test2').setProps({onClick:
test});return false"/>

Dan

Kenneth Suter wrote:
> Hello,
>
> I am trying to replace the onClick handler of a Woodstock 4.2 button
> by calling the button's setProps() function. I am surprised to find
> that when I do this the handler itself is invoked. So for instance in
> this example clicking the "Register" button causes an alert to pop up:
>
> <webuijsf:button id="testB1" text="Test"/>
>
> <input type="button" value="Register"
> onClick="document.getElementById('form1:testB1').setProps({onClick:
> alert('hi there')});return false"/>
>
>
> Is this behavior expected? Is there a way to avoid the handling
> function from being invoked?
>
> Thanks,
>
> -Kenneth
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_woodstock.dev.java.net
> For additional commands, e-mail: users-help_at_woodstock.dev.java.net
>