【发布时间】:2012-08-23 13:19:03
【问题描述】:
我有一个<p:inputText value="#{beans.text}" /> 和一个<p:commandButton actionlistener="#{beans.method}" />。
如何通过 inputText 中的“输入”从 Button 执行 actinoListener-Method?
感谢解答
出了点问题。这是代码-sn-p->
<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 的方法也是....
出了点问题。这是代码-sn-p->
<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'-event,regexSave-Method 将被执行。但是 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> ....
【问题讨论】:
-
问题中缺少一些单词。我猜你希望你说你有一个 inputText 和一个 commandButton
-
输入文本和命令按钮的格式一样吗?只有一个命令按钮?你为什么不包括你的 xhtml 的 sn-p 来澄清这一点?
-
同时我已经配置了我的代码。现在文本字段和按钮在我的表格的标题中。
标签: user-interface jsf-2 primefaces