On 5/7/06, Hubert Rabago <[EMAIL PROTECTED]> wrote:
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
On 5/5/06, Craig McClanahan <[EMAIL PROTECTED]> 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

