h:commandButton无法正常工作

时间:2014-04-13 03:00:44

标签: java jsf-2

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

  • jsf-api-2.1.jar
  • JS​​F的参数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------------------");        
  }

}

2 个答案:

答案 0 :(得分:0)

乍一看,你有:

#viewEmployee.viewDetail(item)}

应该是:

#{viewEmployee.viewDetail(item)}

答案 1 :(得分:0)

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

in ui:repeat标签不要从get set方法调用值,调用direct方法。

例:

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


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