【问题标题】:JSF - How to update the <h:selectOneMenu> value from the backing beanJSF - 如何从支持 bean 更新 <h:selectOneMenu> 值
【发布时间】:2014-03-25 09:23:29
【问题描述】:

这是我的&lt;h:selectOneMenu&gt; 代码。
在分配支持 bean execdirectorRC="XXXvalue" 中的值后,我正在尝试从支持 bean 更新它的值。 在这里,executivedirectorslist 确实有一个列表值。

这是表单中的代码

<h:form id="ipdpform">
  <h:selectOneMenu id="exedirectors" value="#{Bean.execdirectorRC}">
    <f:selectItems value="#{Bean.executivedirectorslist}"
       var="s" itemLabel="#{s.label}" itemValue="#{s.value}" />
    <p:ajax listener="#{Bean.getDirectReporters}"
       update="rpt2 :growl :error" execute="@this"
       partialSubmit="true" />
    <f:param name="rpt1" value="rpt1" />
  </h:selectOneMenu>
</h:form >

这是我试图从支持 bean 更新值的代码

RequestContext context = RequestContext.getCurrentInstance();
                execdirectorRC = "XXX,Name";
                context.update("ipdpform:exedirectors");


我的问题是 &lt;h:selectOneMenu&gt;. 中的值“XXX,Name”没有得到更新,而 Bean.executivedirectorslist 中的值已经可用。如何从支持 bean 更新它?

【问题讨论】:

    标签: jakarta-ee jsf-2 selectonemenu backing-beans


    【解决方案1】:

    您可以使用如下静态实用程序函数。

    public static void addWillBeUpdatedComponent(final String componentId) {
            FacesContext.getCurrentInstance().getPartialViewContext()
                    .getRenderIds().add(componentId);
        }
    
    public static void removeWillBeUpdatedComponent(final String componentId) {
            FacesContext.getCurrentInstance().getPartialViewContext()
                    .getRenderIds().remove(componentId);
    }
    

    componentId 必须采用这种格式 form:componentId 而不是 :form:componentId

    【讨论】:

    • 谢谢erk。但是除了上面提到的方法之外,还有其他方法吗?context.update("ipdpform:exedirectors"); ?
    • 谢谢erk。但是代码不是以这种方式工作的吗?RequestContext context = RequestContext.getCurrentInstance(); execdirectorRC = "XXX,姓名"; context.update("ipdpform:exedirectors");
    猜你喜欢
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2011-04-07
    • 2015-04-30
    • 1970-01-01
    • 2011-06-26
    • 2014-03-20
    • 2011-06-29
    相关资源
    最近更新 更多