【问题标题】:h:commandButton not working actionh:commandButton 不起作用
【发布时间】:2014-04-14 15:45:40
【问题描述】:

我不知道我错过了什么,但 h:commandButton 不起作用,我无法调用方法“viewDetail”。

  • jsf-api-2.1.jar
  • jsf-impl-2.1.jar

default.xhtml(模板页面)

<html lang="en" class="no-js" 
      xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core" 
      >
<h:head></h:head>
<h:body>
<h:form>
 <ui:insert name="content">Template content will be inserted here.</ui:insert>
</h:form>
</h:body>

loadData.xhtml(子页面)

<ui:composition>
<ui:define name="content">
<ui:repeat id="dtbEmployee" var="item" value="#{viewEmployee.mxoEmployeeDtos}" varStatus="status">
 <a onclick="document.getElementById('dtbEmployee:#{status.index}:btnView').click();">
Click to view data</a>
<h:commandButton id="btnView" style="display: none" immediate="true">
   <f:ajax event="click" render="dtbEmployee" execute="dtbEmployee" listener="#{viewEmployee.viewDetail(item)}" />
</h:commandButton> 

</ui:repeat>
</ui:define>

</ui:composition>

viewEmployee.java(调用方法页面)

import javax.inject.Named;
import javax.enterprise.context.RequestScoped;

@Named
@RequestScoped

public class ViewEmployee implements Serializable {

  private static final long serialVersionUID = 1L;

  public void viewDetail(EmployeeDto employeeDTO) {
        log.info("------------Call detail------------------");        
  }

}

【问题讨论】:

  • 无法调用方法”究竟是什么意思?
  • 表示单击按钮时未调用 viewDetail 方法

标签: java jsf-2


【解决方案1】:

乍一看你有:

#viewEmployee.viewDetail(item)}

它应该是:

#{viewEmployee.viewDetail(item)}

【讨论】:

  • 谢谢,这是我复制时的错误,但我的项目仍然是正确的标准EL
  • 我发现问题来自于 ui:repeat 标签,仍然发现发生了什么...
【解决方案2】:

我已经解决了我的奇怪问题...

在 ui:repeat 标记中不要从 get set 方法调用值,调用直接方法。

例如:。

viewCustomer.java
public List<CustomerDto> listCustomer() {
        return listCustomerDto;
}


view.xhtml
<ui:repeat value="#{viewCustomer.listCustomer()}" var="item" varStatus="status">

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 2012-07-06
    • 2015-09-26
    相关资源
    最近更新 更多