简体   繁体   English

选择器菜单的Primefaces RequestContext.getCurrentInstance()。reset

[英]Primefaces RequestContext.getCurrentInstance().reset for selectonemenu

I use Primefaces 5 and I would like reset a selectonemenu to default value. 我使用Primefaces 5,我想将selectonemenu重置为默认值。

I have a paging structure so: 我有一个分页结构,所以:

    <p:fragment>

    <p:tabView id="tabview1" cache="false" dynamic="true" >
        <p:tab title="One" id="tab1">
            <ui:include src="tab1.xhtml" />
        </p:tab>
        <p:tab title="Two" id="tab2" >
            <ui:include src="tab2.xhtml"/>
        </p:tab>
    </p:tabView>
</p:fragment> 

Then, tab1.xhtml for example is this: 然后,以tab1.xhtml为例:

<h:form id="frm1">
    <table id="tbl1">          
        <tr>
            <td>
                <p:selectOneMenu id="select1"
                                 value="#{bean.test}" 
                                 valueChangeListener="#{bean.setXXX}"
                                 var="var1" >
                    <f:selectItem itemLabel="Select..." 
                                  itemValue="#{null}" />
                    <f:selectItems  var="var2"
                                    value="#{bean.list}" 
                                    itemLabel="#{var2.label}"
                                    itemValue="#{var2}"/>
                    <p:ajax process="@this" event="change" update="@this"/>
                </p:selectOneMenu>
            </td>
        </tr>
    </table>
</h:form>

I believe that for reset my selectonemenu I can write in my setXXX method: RequestContext.getCurrentInstance().reset("tabView1:tab1:frm1:tbl1:select1"); 我相信要重置我的selectone菜单,可以在setXXX方法中编写:RequestContext.getCurrentInstance()。reset(“ tabView1:tab1:frm1:tbl1:select1”);

Doesn't work and I have excpetion "Caused by: java.lang.IllegalArgumentException" 不起作用,我很抱歉“由:java.lang.IllegalArgumentException引起”

Any idea? 任何想法? What is correct path for reset? 什么是重置的正确路径?

Thanks 谢谢

As far as i understand what you mean by reset is to establish again the default value to the select menu, don't you? 据我了解,重置的含义是再次为选择菜单建立默认值,不是吗?

In that case the thing is very simple. 在那种情况下,事情很简单。 You just need to modify the current value of the selected item. 您只需要修改所选项目的当前值即可。 So, in your Backing Bean "bean", in the setXXX method just reset the original value of the attribute="#{bean. test }". 所以,在您的支持bean“豆”,在方法的setXXX只是重置属性=“#{豆。 测试 }”的原始值。

When ajax updates the combo it will refresh the recent default value test. 当ajax更新组合时,它将刷新最近的默认值测试。

You are referring the component using tabView1:tab1:frm1:tbl1:select1 . 您正在使用tabView1:tab1:frm1:tbl1:select1引用组件。

There are 2 errors in it. 其中有2个错误。

In JSF/Primefaces the components which implement javax.faces.component.NamingContainer are the only components that attach their id to the inner components. 在JSF / Primefaces中,实现javax.faces.component.NamingContainer的组件是将其ID附加到内部组件的唯一组件。

So p:tab and table (not a JSF component at all) are not one of those components. 因此p:tabtable (根本不是JSF组件)不是那些组件之一。

From your code only component that implement javax.faces.component.NamingContainer are p:tabView and h:form . 从您的代码中,仅实现javax.faces.component.NamingContainer组件是p:tabViewh:form

So your p:selectOneMenu id will be just be tabview1:frm1:select1 因此,您的p:selectOneMenu ID将为tabview1:frm1:select1

RequestContext.getCurrentInstance().reset("tabview1:frm1:select1");

This you can look it up from your Browser's Inspect Element. 您可以从浏览器的检查元素中查找它。

在此处输入图片说明

and Remember to update the component once you reset , which you can do it from ManagedBean itself using Requestcontext 并记住在reset更新组件,您可以使用Requestcontext从ManagedBean本身进行Requestcontext

RequestContext.getCurrentInstance().update("tabview1:frm1:select1");

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

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