2014-04-10 25 views
1

我有一個JSF應用程序,其中有一個組合框。JSF訪問bean類中的html元素值

<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"); 
} 

而且我成功地這樣做。我通過組合框的ajax onchage事件調用此方法。

但是,如果我嘗試在不同的方法中獲得相同的組合框值,我會得到空值。

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

任何幫助!

回答

0

儘量把屬性過程和partialSubmit在你的Ajax調用的價值觀,你需要這樣的過程:

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

在這個過程中atrribute你可以把你需要更新的值來處理所有的IDS(如你在屏幕上看到

+0

我也這麼做過。仍爲空 –

+1

」上沒有'process'和'partialSubmit'屬性。 –

3

因爲Process EventsUpdate Model Values之前發生,你可以檢索從組件的價值,從UIViewRoot這樣的:

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