Render和visible----------ADF Faces入門(文檔閱讀)

 所有的ADF Faces顯示組件組件都會有兩個屬性用來控制這個組件是否顯示在頁面中讓用戶瞧見,這兩哥們就是rendered 和visible。那咱們來看看它哥兩各自的特點。

rendered屬性有着嚴格的意義,也可以這麼說,這哥特死板。當rendered屬性設置爲false的時候,在不和服務器交互的情況下,你沒有辦法在客戶端顯示這個組件。爲了支持動態隱藏以及顯示,RCF增加了visible屬性(也就是rendered的弟弟,天空一聲巨響,小子閃亮登場),當這屬性設置爲false的時候,在客戶端這個組件標記是可用的,只是它不顯示出來而已,所以只要調用setVisible(true)或者是setVisible(false) 你就可以讓它顯示或者是隱藏,前提是它哥哥是true(rendered),這個方法在JS,java中都可以調用。只有當你確切在無和服務器交互的情況下切換組件的可見性,例如在JS中切換,你應該使用visible,設置visible爲false。此時,不可見的組件仍然要通過組件的聲明週期,包括驗證。如果你不需要在客戶端切換組件的可見性,你應該選擇大哥(rendered)。使用大哥可以提高服務器的性能以及客戶端的響應時間,因爲這個組件在客戶端沒有客戶端的表現,以及不會通過該組件的聲明週期。

大哥(rendered)的例子:

  1. <af:panelGroupLayout layout="horizontal">
  2. <af:inputText label="Input some text" id="input"
  3. value="#{myBean.inputValue}"/>
  4. <af:commandButton text="Enter"/>
  5. </af:panelGroupLayout>
  6. <af:panelGroupLayout layout="horizontal">
  7. <af:outputLabel value="You entered:"/>
  8. <af:outputText value="No text entered" id="output1"
  9. rendered="#{myBean.inputValue==null}"/>
  10. <af:outputText value="#{myBean.inputValue}"
  11. rendered="#{myBean.inputValue !=null}"/>
  12. </af:panelGroupLayout>

弟弟的例子(visible):

  1. <af:panelGroupLayout layout="horizontal">
  2. <af:inputText label="Input some text" id="input"
  3. value="#{myBean.inputValue}"/>
  4. <af:commandButton text="Enter"/>
  5. </af:panelGroupLayout>
  6. <af:panelGroupLayout layout="horizontal">
  7. <af:outputLabel value="You entered:"/>
  8. <af:outputText value="No text entered" id="output1"
  9. visible="#{myBean.inputValue==null}"/>
  10. <af:outputText value="#{myBean.inputValue}"
  11. visible="#{myBean.inputValue !=null}"/>
  12. </af:panelGroupLayout>

如何在客戶端使用JavaScript操作visible,例子:

  1. <f:view>
  2. <af:resource>
  3. function showText()
  4. {
  5. var output1 = AdfUIComponent.findComponent("output1")
  6. var output2 = AdfUIComponent.findComponent("output2")
  7. var input = AdfUIComponent.findComponent("input")
  8. if (input.value == "")
  9. {
  10. output1.setVisible(true);
  11. }
  12. else
  13. {
  14. output2.setVisible(true)
  15. }
  16. }
  17. </af:resource>
  18. <af:document>
  19. <af:form>
  20. <af:panelGroupLayout layout="horizontal">
  21. <af:inputText label="Input some text" id="input"
  22. value="#{myBean.inputValue}" clientComponent="true"
  23. immediate="true"/>
  24. <af:commandButton text="Enter" clientComponent="true">
  25. <af:clientListener method="showText" type="action"/>
  26. </af:commandButton>
  27. </af:panelGroupLayout>
  28. <af:panelGroupLayout layout="horizontal">
  29. <af:outputLabel value="You entered:" clientComponent="false"/>
  30. <af:outputText value="No text entered" id="output1"
  31. visible="false" clientComponent="true"/>
  32. <af:outputText value="#{myBean.inputValue}" id="output2"
  33. visible="false" clientComponent="true"/>
  34. </af:panelGroupLayout>
  35. </af:form>
  36. </af:document>
  37. </f:view>

最後小提下,Visible和isShowing函數

如果一個組件的visible屬性設置爲false,當針對於它的一個子組件的isVisivle函數跑的時候,由於這個自組件是visible是設置爲true的,因此這時候返回的是true,但是這個子組件實際上是不顯示的。顯而易見,這樣是不合理的,因此RCF提供了isShowing()這個函數來解決這個問題。

本文轉自:http://blog.csdn.net/com_d_d/article/details/6153624

發佈了47 篇原創文章 · 獲贊 6 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章