Hi,

I really dislike the forceId feature.

The core issue is that when a component is nested inside a "naming container", it gets the ids of its ancestor "naming container" components prefixed to its id. However using "forceId" to hard-wire an id regardless of the ancestry of the component risks name collisions. It's equivalent to using a special filesystem wrapper that makes every file on your disk appear as if it were in the root-level directory.

I use a naming convention to solve this instead; if a button needs to manipulate a checkbox then give the button an id eg "Foo" and the checkbox a derived id, eg "FooCheckbox". The javascript attached to the button then simply gets the id of the button (this.id) and concatenates "Checkbox" to get the id of the target HTML component to manipulate. This then works no matter what the naming container structure is.

Regards,

Simon


Gerald Müllan wrote:
Hi,

what about getting the dom node and doing an easy status check like
this in the script:

var domNode = document.getElementById("clientIdCheckbox");

if(domNode.checked == true)
{..}

If using MyFaces you can take advantage of the forceId="true"
attribute of the checkbox component in order to know the id on client.

cheers,

Gerald

On 11/10/06, Fraley, Taylor <[EMAIL PROTECTED]> wrote:
Thanks for the info.  Checking the client-side generated ids was
actually the first thing I tried, and for some reason, it's still not
working as expected.  That could very well be a problem with my
javascript, and I won't ask anyone to debug that for me -- I'll take
care of it :)  My only problem now is how to check the "checked" status
of the boolean checkbox from within the script.

Thanks,
Taylor


-----Original Message-----
From: Jeff Bischoff [mailto:[EMAIL PROTECTED]
Sent: Friday, November 10, 2006 12:22 PM
To: MyFaces Discussion
Subject: Re: JSF + Javascript question

Nebinger, David wrote:
 > Obviously there would be other ways to skin this cat, but it should
all work just fine...

He's right. If you use the right client-side id, it should work.
However, client ids in JSF can get real messy. I would highly recommend
the other ways. (to skin the cat - it makes some great soup!)

For example, you can use the "disabled" and "rendered" attributes on JSF
components to control their status. If you do not want to submit the
entire form, there are several ways around that: e.g. s:subForm or AJAX
frameworks like Ajax4jsf.

But if you're determined to stick with quick & dirty (hey so was I, when
I first started using JSF), you will need to be aware of those client
ids.

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.


Nebinger, David wrote:
> Without info re: falling flat, my guess is you're not accommodating
the real ID of the control on the HTML side.  Your javascript will
probably work just fine if you a) pass the real id (effectively the
client id on the JSF side), or b) iterate through the controls looking
for a control with the id that ends with your logically-assigned id.
Obviously there would be other ways to skin this cat, but it should all
work just fine...
>
> -----Original Message-----
> From: Fraley, Taylor [mailto:[EMAIL PROTECTED]
> Sent: Friday, November 10, 2006 2:01 PM
> To: MyFaces Discussion
> Subject: JSF + Javascript question
>
>
> Does anyone know a quick and dirty way to disable a set of JSF form
elements based on the checked status of a h:selectBooleanCheckbox?  I
have some Javascript that works great when using normal HTML elements,
but falls flat when I'm using faces.
>
> Thanks,
> Taylor
>
>
>






Reply via email to