本文介绍了调用JSF方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击"Testscript"按钮时,应调用方法testscript.但这在我的bean中调用了另一种方法.以下是示例代码.

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>

请帮助

推荐答案

执行onclick ="getElementById"不会执行任何操作,而只是获取一个ID.因为它是一个按钮,所以您不会说"return false";您的表单是通过功能按钮提交的(如果呈现的页面上具有提交"类型).当然,在这种情况下,根本不会调用另一个按钮的动作侦听器(因为它与表单提交无关).

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).

您应该像这样在testScript按钮上调用click方法:onclick ="document.getElementById('myForm:testScript').click();".

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

最好有一个简单的< input type ="button"/>而不是feat:button,以确保该元素未调用submit.

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.

这篇关于调用JSF方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:38