Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 commandLink不调用操作侦听器,但commandButton工作正常_Jsf 2_Commandlink - Fatal编程技术网

Jsf 2 commandLink不调用操作侦听器,但commandButton工作正常

Jsf 2 commandLink不调用操作侦听器,但commandButton工作正常,jsf-2,commandlink,Jsf 2,Commandlink,我想通过Facelets的链接调用一个方法: 我的Facelets代码如下: <h:commandButton value="A" actionListener="#{customerData.searchedCustomerListA}" /> <h:commandLink value="A" actionListener="#{customerData.searchedCustomerListA}"/> public void searchedCustomerLi

我想通过Facelets的链接调用一个方法:

我的Facelets代码如下:

<h:commandButton value="A" actionListener="#{customerData.searchedCustomerListA}" />

<h:commandLink value="A" actionListener="#{customerData.searchedCustomerListA}"/>
public void searchedCustomerListA(ActionEvent ae){
    customerName = "A";
    leftCustomerListAvailable.clear();
    if(customerDataBean.getSearchedCustomerList(customerName)!= null)
        leftCustomerListAvailable =customerDataBean.getSearchedCustomerList("A");
}

相同的代码适用于
,但不适用于
。这是怎么造成的,我该如何解决它呢?

试试这个,这个应该有用

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:form>

    <h:commandLink type="button" action="#{testBean.tsetLink}"> 
          <h:outputText value="A" />
    </h:commandLink>

</h:form>
</html>

之间的技术区别在于链接使用JavaScript提交父表单。因此,如果在语法上等价的按钮正常工作时它不工作,那么这只能意味着浏览器中禁用了JavaScript,或者页面中不包括包含必需帮助函数的
jsf.js
文件(通过在浏览器内置开发者工具集的JS控制台中看到JS错误,您应该很容易注意到这一点)

所以,要解决这个问题,您需要验证浏览器中是否启用了JS,以及模板中是否有一个
组件而不是普通的HTML
,以便JSF能够自动包含
JSF.JS
文件


或者,如果您的应用程序的业务需求要求应用程序按照禁用JS的设计运行,那么您应该坚持使用
,并加入一些CSS,使其看起来像一个链接(例如,删除背景、填充、边框、插入等).

我的案例此问题的原因是配置不当的url重写筛选器。其中一个筛选器模式无意中匹配了
http://localhost:8080/mysite/javax.faces.resource/jsf.js.xhtml?ln=javax.faces
阻止加载jsf.js。请检查以下答案:。

您在浏览器的JavaScript控制台中看到任何错误吗呃当点击
commandLink
?尝试使用
action
而不是
actionListener
。嗨,pepuch,我也尝试了action,但没有得到结果。嗨,neni,我尝试了你的解决方案,但仍然没有得到结果。我也尝试了action而不是actionListener。但是结果是一样的。JSF版本有问题吗n?您使用的是哪个版本的JSF?您使用的是primefaces、rich faces等组件库吗?我使用的是JSF 2.0。我没有使用任何外部组件库。表单中是否包含commandLink?请参阅我的更新答案,它工作正常我已经在我的机器上进行了测试。
@ManagedBean
@RequestScoped
public class TestBean {

    public void tsetLink(){
    System.out.println("Link clicked!!!!!!!!!!!!");
    }
}