2012-11-22 51 views
1

我有與AJAX事件複選框,在改變值,該複選框會在我的豆改變一個布爾值。這個ajax事件也應該呈現一個屬性爲rendered="#{!*the bean's boolean*}"的panelGrid。這意味着panelGrid在未選中時應該可見,並在選中時可見。布爾值默認設置爲false(由@PostConstruct)。JSF:panelGrid中不會呈現

這是相應的代碼片斷:

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}"> 
    <f:ajax event="change" execute="useAddress" render="outputAddress" /> 
</h:selectBooleanCheckbox> 

<h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress}" columns="2" width="468px"> 
(...) 

此代碼段由<h:form />標籤包圍。 我getUseAddress()setUseAddress()將在valuechange執行。

我的問題是,爲什麼我panelGrid的始終可見

+2

相關:http://stackoverflow.com/questions/9010734/why-do-i-need-to-nest-a-component-with-rendered-some-in-another-component- w^ – BalusC

回答

3

請勿在rendered屬性的元素上指向f:ajax,因爲當這些元素不會被渲染時,f:ajax將無法​​找到它們。

f:ajax必須指出的元素出現在生成的HTML DOM樹,當一些JSF元素的rendered屬性等於false該元素不會甚至存在於HTML DOM樹

更改您的代碼到這個

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}"> 
    <f:ajax event="change" render="outputAddressWrapper" /> 
</h:selectBooleanCheckbox> 

無需對execute="useAddress"事業execute默認爲@this反正

<h:panelGroup id="outputAddressWrapper"> 
    <h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress} columns="2" width="468px"> 
     ... 

你說你panelGrid中始終可見,什麼是你的bean的範圍是什麼?使其至少@ViewScoped

+0

這將導致您所描述的問題,我想你的意思'AJAX render'的ID應該是外板和內面板上呈現的屬性上,對不對? – Aquillo

+0

是的,這是一個錯字....固定 – Daniel

+0

測試和工作,聽起來回想起來這樣的邏輯。 – Aquillo