You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Galen Dunkleberger <ga...@gmail.com> on 2005/04/12 16:35:54 UTC
How to get component id in jsp
Is there a good way to pull the client id of a particular component in
the jsp? What I'm trying to do is pass the id to javascript calls. I
know how to figure out the id manually but is would be nice to be able
to do something like this...
<h:someComponent
onclick="somejavascriptcall('<%=someothercomponent.getClientId()%>')"
/>
Anyone have any ideas how this might work?
Thanks,
Galen
Re: How to get component id in jsp
Posted by Heath Borders <he...@gmail.com>.
The component is called <j4j:idProxy />
You use it like this:
<h:inputText>
<j4j:idProxy id="myInput" />
</h:inputText>
Then, you get your component in javascript like this:
document.getElementById(document.getElementById('myInput').title);
We are using this tag all over our app because we needed a solution to the
problem long before forceId came around. As some point, hopefully we will
convert ourselves over to forceId.
On 4/13/05, Stefan Langer <my...@bettsockentraeger.de> wrote:
>
> Galen Dunkleberger wrote:
>
> >Is there a good way to pull the client id of a particular component in
> >the jsp? What I'm trying to do is pass the id to javascript calls. I
> >know how to figure out the id manually but is would be nice to be able
> >to do something like this...
> >
> ><h:someComponent
> >onclick="somejavascriptcall('<%=someothercomponent.getClientId()%>')"
> >/>
> >
> >Anyone have any ideas how this might work?
> > Thanks,
> > Galen
> >
> >
> A while back I found a component from someone else on jsfcentral.com<http://jsfcentral.com>
> that provides a proxytag for ids. I think it was call javascriptproxy
> but I'm not sure and can't seem to find it at the moment. Basically it
> provides a tag that can retrieve the id and assigns it to a defined
> javascript variable. The nice thing about it, it can be used with
> standard components also. The bad thing: more writing and it isn't as
> nicely integrated as forceid is.
> Maybe myfaces could provide some component like this for means of
> providing ids for standard components.
>
> Regards
> Stefan
>
>
--
-Heath Borders-Wing
hborders@mail.win.org
Re: How to get component id in jsp
Posted by Stefan Langer <my...@bettsockentraeger.de>.
Galen Dunkleberger wrote:
>Is there a good way to pull the client id of a particular component in
>the jsp? What I'm trying to do is pass the id to javascript calls. I
>know how to figure out the id manually but is would be nice to be able
>to do something like this...
>
><h:someComponent
>onclick="somejavascriptcall('<%=someothercomponent.getClientId()%>')"
>/>
>
>Anyone have any ideas how this might work?
> Thanks,
> Galen
>
>
A while back I found a component from someone else on jsfcentral.com
that provides a proxytag for ids. I think it was call javascriptproxy
but I'm not sure and can't seem to find it at the moment. Basically it
provides a tag that can retrieve the id and assigns it to a defined
javascript variable. The nice thing about it, it can be used with
standard components also. The bad thing: more writing and it isn't as
nicely integrated as forceid is.
Maybe myfaces could provide some component like this for means of
providing ids for standard components.
Regards
Stefan
Re: How to get component id in jsp
Posted by Sean Schofield <se...@gmail.com>.
Take a look at forceId as Heath suggests. I basically wrote it for
just such occassions. If you are writing a custom component there is
the option of having the component/renderer generate the javascript in
which case you would know the id. Take a look at the archives for
discussions on forceId for some of the lively debate we had on this
topic. There are pros and cons to each approach.
sean
On Apr 12, 2005 10:42 AM, Heath Borders <he...@gmail.com> wrote:
> If you're using the extendd component set for your component, you can use
> the forceId attribute, which will make the clientId equal to the id.
>
> However, if that's not an option the easiest way would probably be just to
> do a component-binding for the component whose clientId you need, and then
> expose the clientId wit a getter.
>
>
>
> On Apr 12, 2005 9:35 AM, Galen Dunkleberger <ga...@gmail.com>
> wrote:
> > Is there a good way to pull the client id of a particular component in
> > the jsp? What I'm trying to do is pass the id to javascript calls. I
> > know how to figure out the id manually but is would be nice to be able
> > to do something like this...
> >
> > <h:someComponent
> >
> onclick="somejavascriptcall('<%=someothercomponent.getClientId()%>')"
> > />
> >
> > Anyone have any ideas how this might work?
> >
> Thanks,
> >
> Galen
> >
>
>
>
> --
> -Heath Borders-Wing
> hborders@mail.win.org
Re: How to get component id in jsp
Posted by Heath Borders <he...@gmail.com>.
If you're using the extendd component set for your component, you can use
the forceId attribute, which will make the clientId equal to the id.
However, if that's not an option the easiest way would probably be just to
do a component-binding for the component whose clientId you need, and then
expose the clientId wit a getter.
On Apr 12, 2005 9:35 AM, Galen Dunkleberger <ga...@gmail.com>
wrote:
>
> Is there a good way to pull the client id of a particular component in
> the jsp? What I'm trying to do is pass the id to javascript calls. I
> know how to figure out the id manually but is would be nice to be able
> to do something like this...
>
> <h:someComponent
> onclick="somejavascriptcall('<%=someothercomponent.getClientId()%>')"
> />
>
> Anyone have any ideas how this might work?
> Thanks,
> Galen
>
--
-Heath Borders-Wing
hborders@mail.win.org