Titi Wangsa wrote:
i'm new to jsf, i'm using the myfaces 1.1.5 and somehow there is
javascript code in my commandbutton, did i do something wrong
the code is something like this
<h:commandButton id="autoRegisterJobseekerFormSubmit"
action="registerProfile" />
gets rendered as
<input id="autoRegisterJobseekerForm:autoRegisterJobseekerFormSubmit"
name="autoRegisterJobseekerForm:autoRegisterJobseekerFormSubmit"
type="submit" onclick="if(typeof
window.clearFormHiddenParams_autoRegisterJobseekerForm!='undefined'){clearFormHiddenParams_autoRegisterJobseekerForm('autoRegisterJobseekerForm');}"
/>
more javascript functrions, 2 or more follows
function clear_autoRegisterJobseekerForm()
{
clearFormHiddenParams_autoRegisterJobseekerForm('autoRegisterJobseekerForm');
}
function clearFormHiddenParams_autoRegisterJobseekerForm(currFormName)
{
var f = document.forms['autoRegisterJobseekerForm'];
f.elements['autoRegisterJobseekerForm:_idcl'].value='';
f.elements['autoRegisterJobseekerForm:_link_hidden_'].value='';
f.target='';
}
clearFormHiddenParams_autoRegisterJobseekerForm();
This code is not *submitting* using javascript, it is just clearing a
few variables. Even if javascript is disabled in the client browser the
submit should still happen ok.
This code is a little different from 1.1.3 (which is what I'm currently
using) but it seems clear enough. The normal way to submit a form in
HTML is via a button. However JSF offers an additional feature:
h:commandLink which allows a form to be submitted via a link.
Unfortunately HTML doesn't support this directly so the only way to
implement this is by attaching javascript to a link that sets a hidden
field then submits the form. All this code is doing is clearing out any
data left behind by this. Clearly if the browser doesn't have javascript
enabled then these hidden fields can never be set, so the fact that they
are never cleared doesn't matter.
I agree the output looks far from optimal; I would have thought that the
input control could look like:
<input ... onclick="return _myfaces_tidyup(this);"/>
Even better the page could contain some javascript that automatically
searches for tags rendered from JSF components and dynamically attach
the tidyup script, although that might have problems with race
conditions as users can click on buttons before the page is completely
rendered. However if we want this, we need to submit code patches!
Cheers,
Simon