我正在为我的应用程序使用 JSF 1.2。
在下面的代码中,Account Details
按钮的 action 属性不起作用,即方法没有被调用,当我单击按钮时没有任何反应。
<h:panelGrid columns="2">
<h:outputLabel id="lblCustomerDetails" value="Details of CustomerId: "></h:outputLabel>
<h:outputText id="txtCustomerId" value="#{customerInfo.customerId }"></h:outputText>
<h:outputLabel id="lblCustomerName" value="Customer name: "></h:outputLabel>
<h:outputText id="txtCustomerName" value="#{customerInfo.customerNAme }"></h:outputText>
<h:outputLabel id="lblAccounts" value="Accounts: "></h:outputLabel>
<h:selectOneMenu id="drpdownAccounts">
<f:selectItems value="#{customerInfo.accounts }"/>
</h:selectOneMenu>
<h:outputLabel id="lblEmail" value="Email: "></h:outputLabel>
<h:outputText id="txtEmail" value="#{customerInfo.email }"></h:outputText>
<h:outputLabel id="lblAccountDetails" value="Select an account no. for details"></h:outputLabel>
<h:commandButton id="btnAcountDetails" value="Account Details" action="#{accountBean.accountDetails }"></h:commandButton>
<h:messages></h:messages>
</h:panelGrid>
下面是AccountBean
:
public class AccountBean {
private int accountNo;
private String customerName;
private double accountBalance;
private String accountType;
//Getters and setters
public String accountDetails(){
//Some logic and return
return "success";
}
}
这是 faces-config 文件中存在的托管 bean:
<managed-bean>
<managed-bean-name>customerInfo</managed-bean-name>
<managed-bean-class>com.bean.CustomerInfo</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>accountBean</managed-bean-name>
<managed-bean-class>com.bean.AccountBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
我可能在代码中遗漏了一些愚蠢的东西,但无法弄清楚,为此浪费了很多时间,因此想到了发布。指针表示赞赏。