Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

Call a JSF method

When user clicks the Testscript button, the method testscript should be called. But it calls a different method in my bean. Following is the sample code.

 <h:form id="myform">
<h:commandButton id="testScript" actionListener="# {ScriptedPolicyBean.testScript"} />
    <feat:Button onclick="document.getElementById("myForm:testScript")" />
     </h:form>                  

Please help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Doing onclick="getElementById" does nothing but simply gets an id. As it is a button and you do not say "return false;" your form is submitted by the feat button (if it has the type submit on the rendered page). Of course in this case the actionlistener of the other button is not called at all (as it has nothing to do with the form submit).

You should call the click method on the testScript button like this: onclick="document.getElementById('myForm:testScript').click();".

It would be nice to have a simple <input type="button" /> instead of the feat:button to be sure the submit is not called by that element.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...