2012-08-23 27 views
0

我有一个<p:inputText value="#{beans.text}" />和一个<p:commandButton actionlistener="#{beans.method}" />。 如何从输入文本中的“输入”按钮执行按钮的actinoListener-Method?在InputText上为CommandButton监听器输入事件

感谢答案

财产以后出了问题。这里是代码片段 - >

<h:panelGrid columns="2"> 
<p:commandButton actionListener="#{hoursView.saveOrUpdateHour}" /> 
<p:commandButton actionListener="#{hoursView.onFilterChange()}" oncomplete="dlgHoursFilter.show()" immediate="true" update=":hoursFilter" /> 
</h:panelGrid> 
</h:panelGrid> 
<h:panelGrid columns="4" class="buttonContent" id="buttonView"> 
<p:commandButton ajax="false" actionListener="#{hoursView.showDay()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showWeek()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showMonth()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showAll()}" immediate="true" update="hoursList" /> 
</h:panelGrid> 
     <h:panelGrid columns="3" id="tableGrid"> 
      <p:dataTable id="hoursList" value="#{hoursView.listHours}" 
       var="hours" widgetVar="hoursTable" resizableColumns="true" 
       emptyMessage="#{msg.noData}" rowKey="#{hours.id}" 
       selection="#{hoursView.selected}" selectionMode="single"> 

       <p:ajax event="rowDblselect" update=":hourEditDialog" 
        listener="#{hoursView.onHourSelect}" 
        oncomplete="dlgHourEdit.show()" /> 

       <f:facet name="header"> 
        <h:panelGrid columns="3" class="buttonContent" id="regexContent"> 
         <h:outputText value="#{msg.regexHour}" /> 
         <p:inputText value="#{hoursView.regex}" id="regex"> 
         </p:inputText> 
         <p:commandButton icon="addButton" id="regexSave" 
          process="regexContent" actionListener="#{hoursView.regexSave}" 
          update=":editContent:hoursList,:editContent:growl,regex"> 
          <p:defaultCommand target="regexSave" scope="regexContent" /> 
         </p:commandButton> 
         <p:tooltip for="regexSave" value="#{msg.regexSave}" 
          showEffect="fade" hideEffect="fade" /> 
        </h:panelGrid> 
       </f:facet> 

如果我激发'enter'-event regexSave-Method将被执行。但是SaveOrUpdateHour的方法也是如此......


出错了。这里是代码snippet->

<h:panelGrid columns="2"> 
<p:commandButton actionListener="#{hoursView.saveOrUpdateHour}" /> 
<p:commandButton actionListener="#{hoursView.onFilterChange()}" oncomplete="dlgHoursFilter.show()" immediate="true" update=":hoursFilter" /> 
</h:panelGrid> 
</h:panelGrid> 
<h:panelGrid columns="4" class="buttonContent" id="buttonView"> 
<p:commandButton ajax="false" actionListener="#{hoursView.showDay()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showWeek()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showMonth()}" immediate="true" update="hoursList" /> 
<p:commandButton ajax="false" actionListener="#{hoursView.showAll()}" immediate="true" update="hoursList" /> 
</h:panelGrid> 
<h:panelGrid columns="3"> 
<h:outputText value="#{msg.regexHour}" /> 
<p:inputText value="#{hoursView.regex}" id="regex"> 
<p:ajax event="change" update="hoursList, growl" listener="#{hoursView.regexSave}" /> 
</p:inputText> 
<p:commandButton actionListener="#{hoursView.regexSave}" update="hoursList, growl" /> 
</h:panelGrid> 

如果我火“enter'事件的regexSave法会付诸行动。但方法saveOrUpdateHour,太...

同时我已经配置我的代码一点。现在文本框和按钮位于我桌子的标题中。

<h:panelGrid columns="3" id="tableGrid"> 
      <p:dataTable id="hoursList" value="#{hoursView.listHours}" 
       var="hours" widgetVar="hoursTable" resizableColumns="true" 
       emptyMessage="#{msg.noData}" rowKey="#{hours.id}" 
       selection="#{hoursView.selected}" selectionMode="single"> 

       <p:ajax event="rowDblselect" update=":hourEditDialog" 
        listener="#{hoursView.onHourSelect}" 
        oncomplete="dlgHourEdit.show()" /> 

       <f:facet name="header"> 
        <h:panelGrid columns="3" class="buttonContent" id="regexContent"> 
         <h:outputText value="#{msg.regexHour}" /> 
         <p:inputText value="#{hoursView.regex}" id="regex"> 
         </p:inputText> 
         <p:commandButton icon="addButton" id="regexSave" 
          process="regexContent" actionListener="#{hoursView.regexSave}" 
          update=":editContent:hoursList,:editContent:growl,regex"> 
          <p:defaultCommand target="regexSave" scope="regexContent" /> 
         </p:commandButton> 
         <p:tooltip for="regexSave" value="#{msg.regexSave}" 
          showEffect="fade" hideEffect="fade" /> 
        </h:panelGrid> 
       </f:facet> .... 
+0

中有一些问题,缺的词..我想你想你说你有一个的inputText和一个命令 – Damian

+0

输入文本与命令按钮的形式相同?只有一个命令按钮?为什么你不包含你的xhtml的片段来澄清这一点? – Damian

+0

同时我已经配置我的代码了一点。现在文本框和按钮位于我桌子的标题中。 – Sandy

回答

3

可以使用p:inputTextonkeypress和jquery的呼叫按钮所处的.click()的帮助下,注意return false;将确保没有(p:ajax for example)将被称为输入将被压后

这样的:

<p:commandButton id="myButtonID" actionlistener="#{beans.method}" /> 


<p:inputText value="#{beans.text}" onkeypress="if (event.keyCode == 13) { jQuery('#myButtonID').click(); return false;}"/> 

更新 而不是:editContent:hoursList尝试update="tableGrid"(参考表包装器),或者如果你正在使用primefaces 3.4尝试update="hoursList"

+0

我已经测试过了。而且它只有在删除命令按钮的更新中的“:editContent:hoursList”时才起作用...如果我删除了我的表格,将不会用新数据刷新... – Sandy

+0

什么表?你应该在问题中更新你的代码,然后......从你更新表的地方看不到任何':editContent:hoursList'? – Daniel

+0

我有问题的代码有问题,第一篇文章 – Sandy