下午好,
我有一个搜索页面,使用ajax呈现多个数据表而不刷新页面。 我必须为每个表调用一个方法作为监听器。 下面是第一个工作正常的数据表的片段。
要渲染第二个数据表,我需要调用方法#{evalController.prepareList}
作为ajax的监听器。问题是<f:ajax
“监听器”属性不会使用多个方法。
所以剩下的方法是多次调用<f:ajax
,每次使用不同的监听器,这是行不通的。有没有办法实现这个目标?
如果没有,我应该在托管Bean中创建一个方法来调用我需要的所有方法并将其用作一个侦听器吗?
提前感谢您的帮助。
<h:form id="searchform">
<h:panelGrid columns="3" >
<p:inputText value="#{ddnController.patientID}" id="pidinput" maxlength="7" size="7">
<f:ajax execute="@this" event="keyup" render="searchbutton ddntable" listener="#{ddnController.prepareList}"/>
</p:inputText>
<h:commandButton image="#{resource['images/search.png']}" id="searchbutton" value="#{bundle.Search}"
action="submit" actionListener="#{ddnController.prepareList}"
disabled="#{empty ddnController.patientID or ddnController.patientID.equals('0')}"/>
<p:panel><h:outputText value="Saisir 0 pour avoir tous les Patients" style="font-style: italic;"/></p:panel>
</h:panelGrid>
<p:dataTable id="ddntable" value="#{ddnController.items}" var="ddn" rendered="#{!empty ddnController.items}" paginator="true" >....
答案 0 :(得分:0)
我仍然不确定为什么复合方法在调用时没有效果。可能它不是在正确阶段之前或之后调用的(我稍后会对其进行分析)。无论如何,我找到了一个两条边的解决方案(解决我的问题但是让我牺牲了ajax的使用):
所以不要从每个托管bean调用 - 我用作监听器的方法(prepareList()):
private DataModel items = null; // Getter to retrieve items
// ......
public String prepareList() {
recreatemodel();
return "List";
}
private void recreatemodel(){
items=null;
}
(顺便说一句,此方法将数据模型设置为NULL
以刷新它,这就是我的数据表刷新的方式)。
在命令按钮内我嵌套了属性动作监听器:
<h:commandButton image="#{resource['images/search.png']}" id="searchbutton" value="#{bundle.Search}"
action="submit"
disabled="#{empty ddnController.patientID or ddnController.patientID.equals('0')}">
<f:PropertyActionListener target="#{ddnController.items}" value="#{null}" />
<f:PropertyActionListener target="#{evalController.items}" value="#{null}" />
<f:PropertyActionListener target="#{corController.items}" value="#{null}" />
<!--...etc -->
</h:commandButton>
我希望<f:PropertyActionListener />
可以嵌套在<h:ajax/>.
如果某人有一个允许使用属性操作侦听器和 ajax 的解决方案以避免使用按钮提交表单,则欢迎他/她。我会接受他/她的回答。