简体   繁体   English

使用Primefaces更新JSF组件

[英]Update JSF Component with Primefaces

I know this has been asked many times, but mainly with ajax. 我知道这个问题已经被问过很多次了,但是主要是关于ajax的。 I can't use ajax in my project. 我不能在项目中使用ajax。

I want to create an event on selectOneMenu A and update selectOneMenu B. 我想在selectOneMenu A上创建一个事件并更新selectOneMenuB。

<p:selectOneMenu id="A" binding="#{bean.slmA}" >
    <f:selectItems value="#{bean.itemsA}"/>
</p:selectOneMenu>

<p:selectOneMenu id="B" binding="#{bean.slmB}">
    <f:selectItems value="#{bean.itemsB}"/>
</p:selectOneMenu>

I already used the valueChangeListener with a method that adds elements to itemsB (also onchange ="submit()") but slmB doesn't update. 我已经使用了valueChangeListener和将元素添加到itemsB的方法(也onchange =“ submit()”),但是slmB不会更新。

Should it be updated after adding elements to itemsB list? 将元素添加到itemsB列表后是否应该更新?

Without ajax I guess one option would be to use a hidden commandButton to do a full request (I'd guess there are other options too): 如果没有ajax,我猜一个选择是使用一个隐藏的commandButton来执行一个完整的请求(我想也有其他选择):

<h:form id="form">
    <p:selectOneMenu id="A" value="#{bean.slmA}" onchange="$('#form\\:cb').click()">
        <f:selectItems value="#{bean.itemsA}"/>
    </p:selectOneMenu>

    <p:selectOneMenu id="B" value="#{bean.slmB}">
        <f:selectItems value="#{bean.itemsB}"/>
    </p:selectOneMenu>

    <p:commandButton id="cb" ajax="false" style="display: none" value="button" action="#{bean.functionThatFillInformationOfListB()}" />
</h:form>

Bean must be at least @ViewScoped and functionThatFillInformationOfListB() return either void or null. Bean必须至少为@ViewScoped并且functionThatFillInformationOfListB()返回void或null。 Note I changed binding to value in the selectOneMenu 's, but if you are in fact creating the selectOneMenu 's on the bean just disregard that (I think it will still work). 注意,我在selectOneMenuvalue中将binding更改为value ,但是如果实际上是在bean上创建selectOneMenuselectOneMenu理会(我认为它仍然可以工作)。

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

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