繁体   English   中英

JSF访问Bean类中的html元素值

[英]JSF access html element value in bean class

我有一个JSF应用程序,其中有一个组合框。

<h:selectOneMenu id="collectorType"
                           value="#{activityDataSource.object.type}"
                           rendered="#{empty activityDataSource.object.id}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           onchange="$('editForm:selectTypeButton').click();">
             <f:ajax event="change" 
                    execute="@this" 
                    render="dsTransformationRule dsCorrelationRule"
                    listener="#{activityDataSource.handleCollectorTypeChange}" />
            <f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
            <f:selectItems value="#{activityDataSource.collectorTypes}"/>
          </h:selectOneMenu>

我在bean类中获得该组合框的选定值,例如:

public void setSelectedTransformationRule(String transformationRule)
        throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

我这样做很成功。 我通过combobox的ajax onchage事件调用此方法。

但是,如果我尝试用不同的方法来获得相同的组合框值,则会得到空值。

public void handleCollectorTypeChange() throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

任何帮助!

因为Process Events发生在Update Model Values之前,所以您可以从组件中从UIViewRoot检索值,如下所示:

HtmlSelectOneMenu collectorTypeSelectMenu = (HtmlSelectOneMenu) FacesContext.getCurrentInstance().getViewRoot().findComponent("editForm:collectorType");
String collectorType = (String) collectorTypeSelectMenu.getValue();

尝试将属性process和partialSubmit放入您的ajax调用中,并使用所需的值,如下所示:

<f:ajax event="change" 
   execute="@this" 
   render="dsTransformationRule dsCorrelationRule"
   process="@this, collectorType"
   partialSubmit="true"
   listener="#{activityDataSource.handleCollectorTypeChange}" />

在处理过程中,您可以将需要处理的所有ID放入更新后的值中(就像在屏幕上看到的那样)。

暂无
暂无

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

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