简体   繁体   English

使用JSF处理ajax请求(Primefaces)

[英]Handle ajax requests with JSF (Primefaces)

I have this code : 我有这个代码:

<p:selectBooleanCheckbox id="locationChoice1" value="#{login.locationChoice1}">
    <p:ajax listener="#{login.chooseLocationType1}" update="locationChoice1 locationChoice2 positionChoice" />          
</p:selectBooleanCheckbox>

I would like to launch conditionnal update of selectOneMenu component if and only if the selectBooleanCheckbox is checked. 我仅在选择了selectBooleanCheckbox情况下,才想启动selectOneMenu组件的条件更新。 I want to update it via ajax request. 我想通过ajax请求对其进行更新。

To summarize, I want to link actions between ajax requests. 总结一下,我想在ajax请求之间链接动作。 When my ajax request above is finished, I want to launch another conditionnal ajax request based on selectBooleanCheckbox boolean value. 当我上面的ajax请求完成时,我想基于selectBooleanCheckbox布尔值启动另一个有条件的ajax请求。

How can I do this please ? 请问我该怎么做?

Well, I´ve never seen an ajax beeing sent(or not) due to a conditional state of an element native in JSF 好吧,由于JSF本地元素的条件状态,我从未见过发送过(或不发送过)ajax蜂

I would implement what you want adding an ajax inside my selectBoolean 我将实现您想要在selectBoolean内添加ajax的功能

<p:ajax event="change" listener="#{login.chooseLocationType1()}" update="element"/>

then in the method chooseLocationType1 you could already handle the condition of the checkbox. 那么在方法chooseLocationType1中,您已经可以处理复选框的条件。

If you really want to send or not the post one thing you can do is to handle it using javascript. 如果您真的想发送或不发送帖子,您可以做的一件事就是使用javascript处理它。 if you add oncomplete="" inside your p:ajax you can call a method in javascript and test if your checkbox is checked or not and then make a post using jquery or js 如果在p:ajax内添加oncomplete =“” ,则可以在javascript中调用方法并测试是否选中了复选框,然后使用jquery或js发表文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM