【发布时间】: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 方法