Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...