【问题标题】:<h:CommandButton> action attribute not working in JSF 1.2<h:CommandButton> 动作属性在 JSF 1.2 中不起作用
【发布时间】:2013-04-03 03:17:20
【问题描述】:

我正在为我的应用程序使用 JSF 1.2。

在下面的代码中,Account Detailsbutton 的 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> 

我可能在代码中遗漏了一些愚蠢的东西,但无法弄清楚,为此浪费了很多时间,因此想到了发布。指针表示赞赏。

【问题讨论】:

  • 请排除这里列出的原因stackoverflow.com/questions/2118656/… 第一个嫌疑人:&lt;h:form&gt; 在哪里?如果没有表单,您将如何提交表单?然而,这在每个理智的 JSF 教程的第 1 章中都有显示,所以这有点表明缺乏对基本 HTML 的理解(你最好在深入 JSF 之前先学习它) JSF 最终基本上“只是”一个 HTML 代码生成器)。

标签: java jsp jsf jsf-1.2


【解决方案1】:

我没有看到您拥有的全部标记,但它可能只是您页面某处缺少&lt;form&gt; 标记吗? MyFaces Trinidad 中的 AFAIK,表单控件和按钮不执行任何操作,除非它们位于 &lt;tr:form&gt; 标记内。

希望能解决您的问题。

【讨论】:

  • 在回答这个问题之前我没有看到 BalusC 的评论......他的链接中的答案看起来包括厨房水槽在内的所有东西,所以去那里吧! :)
【解决方案2】:

如果在里面粘贴你的代码

<h:form>

仍然无法解决问题,然后尝试使用

<a4j:JsFunction>

它将解决 JSF 1.2 的问题

<h:form>
<h:commandbutton onclick = "clickme()" />
<a4j:JsFunction name = "clickme" action = "#{yourBean.YourMethod}"  /> 
</h:form>

【讨论】:

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