You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Hubert Rabago <hr...@gmail.com> on 2006/05/05 23:17:05 UTC

Undocumented JSF trick? (was: Emulation of the action link being clicked)

Thanks for the responses, Andrew and Matthias.

My question actually isn't about an alternate way to do it, but rather
where is it stated that giving a particular hidden field some
particular value will result in some particular JSF behavior?  I mean,
other than going through the source code of both RI and MyFaces.

Since JSF is a spec, for a trick like this to work on all
implementations, it has to rely on something that all spec-compliant
implementations do.  How did the author know that setting this hidden
field's value to its id will do the trick in all JSF implementations? 
Is it written in the spec?

thanks,
Hubert

On 5/5/06, Andrew Robinson <an...@gmail.com> wrote:
> I went ahead and updated the WIKI [1] with the code I was talking about
>
> -Andrew
>
> [1] http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces
>
> On 5/5/06, Matthias Wessendorf <ma...@apache.org> wrote:
> > This wiki page contains some informations about JavaScript and Faces [1]
> >
> > HTH,
> > Matthias
> >
> > [1] http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces
> >
> > On 4/29/06, Hubert Rabago <hr...@gmail.com> wrote:
> > > I was looking at the sample application in
> > > http://www.jsftutorials.net/interface/jsf-popup.html.
> > >
> > > In it, the author has this form:
> > >
> > > <h:form id="placeList">
> > >     <h:commandLink id="find" action="showPlace" value=""/>
> > > </h:form>
> > >
> > > He has some Javascript that essentially sets the value of the command
> > > link equal to its id before submitting the form, also through
> > > javascript:
> > >   form['placeList:find'].value = 'placeList:find';
> > >
> > > with a comment that states "This is an emulation of the action link
> > > being clicked."
> > >
> > > Where is this fact documented?  I tried looking for it in the spec but
> > > couldn't find it.
> > >
> > > thanks,
> > > Hubert
> > >
> >

Re: Undocumented JSF trick? (was: Emulation of the action link being clicked)

Posted by Hubert Rabago <hr...@gmail.com>.
On 5/8/06, Craig McClanahan <cr...@apache.org> wrote:
> On 5/7/06, Hubert Rabago <hr...@gmail.com> wrote:
> > It's the documentation for this:
> >
> >       //This is an emulation of the action link being clicked.
> >       hform[form+':'+target].value=form+':'+target;
> >
> > I want to know how the author knew this trick would work in all JSF
> > implementations.
>
> Which component (or, more precisely, which renderer) is actually emitting
> this code?

That's the thing.  This code is produced by the page author, to submit
a form that uses only standard JSF components.  It's from [1] which I
referenced in my original post [2].

It's stuff like this that, to a newbie like me, is like "magic" if you
know what I mean.  ("Set some hidden field's value to the same value
as its name to emulate it being clicked.")  I just wanted to know
where people get this knowledge.  :)

Anyway, I found the renderkit docs you mentioned, so thanks for
pointing me to the right direction!

Hubert

[1] http://www.jsftutorials.net/interface/jsf-popup.html
[2] http://marc.theaimsgroup.com/?l=myfaces-user&m=114626564831588&w=2

Re: Undocumented JSF trick? (was: Emulation of the action link being clicked)

Posted by Craig McClanahan <cr...@apache.org>.
On 5/7/06, Hubert Rabago <hr...@gmail.com> wrote:
>
> On 5/5/06, Craig McClanahan <cr...@apache.org> wrote:
> > > My question actually isn't about an alternate way to do it, but rather
> > > where is it stated that giving a particular hidden field some
> > > particular value will result in some particular JSF behavior?
> > > How did the author know that setting this hidden
> > > field's value to its id will do the trick in all JSF implementations?
> >
> >
> > The behavior of all the standard component renderers are documented in
> the
> > "render kit docs" that come with the RI ... and, indeed, the fact that
> > clicking on an <h:commandLink> must cause the form to be submitted is
> part
> > of the required behavior.  The precise technique used is not mandated,
> but
> > it's certainly going to involve some sort of JavaScript.
>
> Thanks, Craig.  I'll look for said render kit docs.  Again, it's not
> the use of javascript or submission of the form I'm looking for.  It's
> the documentation for this:
>
>                         //This is an emulation of the action link being
> clicked.
>                         hform[form+':'+target].value=form+':'+target;
>
> I want to know how the author knew this trick would work in all JSF
> implementations.  Unlike something like Struts, where I can just read
> the source code to know what tricks will work, with JSF, I can't just
> read the MyFaces source code, or the RI (when it even has source code,
> cause some of it doesn't), to know the code I'll write will always
> work.


Which component (or, more precisely, which renderer) is actually emitting
this code?  If it's the code emitted by the MyFaces renderer for
<h:commandLink>, than presumably the MyFaces folks would have ensured that
the rendered code actually submits the form.  On the other hand, if it is
the RI version of the <h:commandLink> renderer, you'll see that it uses a
similar trick ... but the *user* of the APIs can be assurred that the
standard renderer for that component works as expected, even if the details
of implementation vary.

On the other hand, if you are  a third party component, then it is up to you
to make sure you render the correct stuff to work inside *any* JSF
implementation.  Fortunately, that's actually pretty easy.  Your renderer
knows what hidden variable it emitted along with the hyperlink, and
therefore it knows what hidden variable name to look for in the decode()
method when the form is submitted.  (Philosophically, this is why we linked
decoding and encoding together in the API.)  In this particular case, it
will always work as long as:

* The renderer emits a hidden variable whose name
  is calculated according to this formula

* The renderer's decode method looks for a request
  parameter of this name (and perhaps value) to determine
  whether this was the component that submitted the form

* No other HTML element on the entire page has the same
  id as this one (the convention of prefixing with the id of
  the parent component aims at this goal -- although you don't
  specify in your code clip how "form" was found.

* The component is actually embedded inside a form component.


Craig


thanks,
> Hubert
>

Re: Undocumented JSF trick? (was: Emulation of the action link being clicked)

Posted by Hubert Rabago <hr...@gmail.com>.
On 5/5/06, Craig McClanahan <cr...@apache.org> wrote:
> > My question actually isn't about an alternate way to do it, but rather
> > where is it stated that giving a particular hidden field some
> > particular value will result in some particular JSF behavior?
> > How did the author know that setting this hidden
> > field's value to its id will do the trick in all JSF implementations?
>
>
> The behavior of all the standard component renderers are documented in the
> "render kit docs" that come with the RI ... and, indeed, the fact that
> clicking on an <h:commandLink> must cause the form to be submitted is part
> of the required behavior.  The precise technique used is not mandated, but
> it's certainly going to involve some sort of JavaScript.

Thanks, Craig.  I'll look for said render kit docs.  Again, it's not
the use of javascript or submission of the form I'm looking for.  It's
the documentation for this:

			//This is an emulation of the action link being clicked.
			hform[form+':'+target].value=form+':'+target;

I want to know how the author knew this trick would work in all JSF
implementations.  Unlike something like Struts, where I can just read
the source code to know what tricks will work, with JSF, I can't just
read the MyFaces source code, or the RI (when it even has source code,
cause some of it doesn't), to know the code I'll write will always
work.

thanks,
Hubert

Re: Undocumented JSF trick? (was: Emulation of the action link being clicked)

Posted by Craig McClanahan <cr...@apache.org>.
On 5/5/06, Hubert Rabago <hr...@gmail.com> wrote:
>
> Thanks for the responses, Andrew and Matthias.
>
> My question actually isn't about an alternate way to do it, but rather
> where is it stated that giving a particular hidden field some
> particular value will result in some particular JSF behavior?  I mean,
> other than going through the source code of both RI and MyFaces.
>
> Since JSF is a spec, for a trick like this to work on all
> implementations, it has to rely on something that all spec-compliant
> implementations do.  How did the author know that setting this hidden
> field's value to its id will do the trick in all JSF implementations?
> Is it written in the spec?


The behavior of all the standard component renderers are documented in the
"render kit docs" that come with the RI ... and, indeed, the fact that
clicking on an <h:commandLink> must cause the form to be submitted is part
of the required behavior.  The precise technique used is not mandated, but
it's certainly going to involve some sort of JavaScript.

thanks,
> Hubert


Craig


On 5/5/06, Andrew Robinson <an...@gmail.com> wrote:
> > I went ahead and updated the WIKI [1] with the code I was talking about
> >
> > -Andrew
> >
> > [1] http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces
> >
> > On 5/5/06, Matthias Wessendorf <ma...@apache.org> wrote:
> > > This wiki page contains some informations about JavaScript and Faces
> [1]
> > >
> > > HTH,
> > > Matthias
> > >
> > > [1] http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces
> > >
> > > On 4/29/06, Hubert Rabago <hr...@gmail.com> wrote:
> > > > I was looking at the sample application in
> > > > http://www.jsftutorials.net/interface/jsf-popup.html.
> > > >
> > > > In it, the author has this form:
> > > >
> > > > <h:form id="placeList">
> > > >     <h:commandLink id="find" action="showPlace" value=""/>
> > > > </h:form>
> > > >
> > > > He has some Javascript that essentially sets the value of the
> command
> > > > link equal to its id before submitting the form, also through
> > > > javascript:
> > > >   form['placeList:find'].value = 'placeList:find';
> > > >
> > > > with a comment that states "This is an emulation of the action link
> > > > being clicked."
> > > >
> > > > Where is this fact documented?  I tried looking for it in the spec
> but
> > > > couldn't find it.
> > > >
> > > > thanks,
> > > > Hubert
> > > >
> > >
>