【问题标题】:commandButton action method not executedcommandButton 操作方法未执行
【发布时间】:2014-06-30 01:38:19
【问题描述】:

我正在使用 jsf 和 primefaces 开发一个 Web 应用程序。

我的导航栏代码如下:

<p:layoutUnit position="north"  >
                <h:form>
                    <img src="resources/images/logo.png" alt="" />&nbsp;&nbsp;&nbsp;
                    <p:outputLabel value="Rechercher    " style="font-size: large"/>  &nbsp;&nbsp;&nbsp;
                    <p:inputText  value="#{acount.searchWord}" required="true" requiredMessage="Le titre est requit"/>&nbsp;&nbsp;&nbsp;
                    <p:commandButton value="Go" action="#{acount.rechercherLivre(acount.searchWord)}"  styleClass="btngo"  />
                    <h:link outcome="main.xhtml" value="Accueil"   style="margin-left: 400px;font-size: medium"/>&nbsp;&nbsp;
                    <h:link outcome="Contact.xhtml"  value="Contact" style="font-size: medium"/>&nbsp;&nbsp;
                    <h:link outcome="Info.xhtml" value="Info" style="font-size: medium"/>&nbsp;&nbsp;&nbsp;
                    <h:link outcome="Login.xhtml" value="Login" style="font-size: medium" rendered="#{!acount.connected}" /> &nbsp;&nbsp;
                    <h:link outcome="exe.xhtml" value="S'enregistrer" style="font-size: medium" rendered="#{!acount.connected}" /> &nbsp;&nbsp;

                    <p:menuButton value="Panier #{shopingCart.produits.size()}"   style="color: #045491;background: greenyellow;background-color: yellowgreen;font-size: medium">
                        <p:menuitem value="Afficher"    action="#{shopingCart.afficherPanier()}"/>
                        <p:separator />
                        <p:menuitem value="Homepage" url="http://www.primefaces.org" />
                    </p:menuButton>
                    <p:menuButton value="Options"   rendered="#{acount.connected}" style="color: #045491;background: greenyellow;background-color: yellowgreen;font-size: medium">
                        <p:menuitem value="Compte"   />
                        <p:menuitem value="Mes Commandes "  />
                        <p:menuitem value="Se deconnecter" action="#{acount.doLogout()}"  />
                        <p:separator />
                        <p:menuitem value="Homepage" url="http://www.primefaces.org" />
                    </p:menuButton>
                </h:form>
            </p:layoutUnit>

这段代码的图片是:

问题是,如果我没有在输入文本中添加任何内容,则不会执行 commandButton 的操作,如果我没有在 inputText 中添加内容,则不会执行 menuButton 中的操作方法。

我可以通过为每个操作方法放置一个表单来解决这个问题,但是我的导航栏变大了,看起来很值得。

我该如何解决这个问题?

【问题讨论】:

  • required="true" requiredMessage="Le titre est requit" 这不是很容易解释吗?
  • 谢谢你,我没有关注,因为消息从来没有发布过。
  • 我还有一个问题,如果你能帮助我,对于搜索功能,我刚刚实现了一个类似子字符串的功能,我想要一个更有可能搜索的功能,因为如果用户忘记了一个字母,不会有结果。这很糟糕

标签: html css jsf primefaces


【解决方案1】:

如果您不需要通过 commandButton 向 bean 发布任何值,则将 process 属性添加到 commandButton。我认为您正试图将一些输入留空并仍然发送请求,但问题是其中一个输入的 required 属性设置为“true”。从您的输入中删除所需的属性并将 process="@this" 添加到您的命令按钮。我希望我是对的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2022-06-17
    • 2012-10-30
    • 2015-02-11
    • 1970-01-01
    • 2016-01-12
    • 2012-07-25
    相关资源
    最近更新 更多