2011-02-08 51 views
2

我有一個<h:selectOneMenu>裏面寫<a4j:support>。 我必須通過<a4j:support>將當前選定的值作爲參數傳遞給操作。 我該怎麼做?如何通過選定的值作爲傳遞參數a4j:支持

<rich:modalPanel> 

<a4j:form> 
<rich:dataTable value="#{factoryCollectionOfUsers}" var="foo"> 
<h:selectOneMenu name="role"> 
         <s:selectItems 
          value="#{userAction.roleArray}" 
          var="role" label="#{role}" 
          noSelectionLabel="Please select" /> 
         <a4j:support event="onchange" ajaxSingle="true" 
          action="#{userAction.setSelection}"> 
         </a4j:support> 
         <s:convertEnum /> 

       </h:selectOneMenu> 
    </rich:dataTable> 
</a4j:form> 
</rich:modalPanel> 
+1

爲什麼你必須使用一個:支持?爲什麼不使用監聽器? – 2011-02-08 15:41:30

回答

0

嘗試這樣:

<h:form> 
    <h:selectOneMenu value="#{foo.theChosenValue}" 
    required="true" valueChangeListener="#{foo.processValueChange}" 
    onchange="this.form.submit();"> 
     <s:selectItems 
         value="#{userAction.roleArray}" 
         var="role" label="#{role}" 
         noSelectionLabel="Please select" /> 
    <s:convertEnum /> 
    </h:selectOneMenu> 
</h:form> 

你的組件應該然後:

@Name("foo") 
public class Foo { 
    @Getter @Setter Enum theChosenValue; //I don't know your type 

    public void processValueChange(ValueChangeEvent value) throws AbortProcessingException { 
     if (value != null) { 
      if (value.getNewValue() instanceof Enum) { 
       this.theChosenValue = (Enum) value.getNewValue(); 
      } 
     } 
    } 
}