facelets_不要在facelets中重复表情
生活随笔
收集整理的這篇文章主要介紹了
facelets_不要在facelets中重复表情
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
facelets
您是否曾經在JSF中看到過像這樣的重復EL表達式?
usw。 另一個例子:
<ui:include src="/include/somesnippet.xhtml"><ui:param name="age" value="#{someBean.isMan(person) ? 63 : 60}"/><ui:param name="money" value="#{someBean.isMan(person) and someBean.getCountry(person) eq 'de' ? 1000 : 900}"/><ui:param name="big" value="#{someBean.getCountry(person) eq 'zh' or someBean.getCountry(person) eq 'ru' ? true : false}"/> </ui:include>#{anotherBean.showPerson},#{someBean.isMan(person)},#{someBean.getCountry(person)}重復多次。 如何優化它們? 好了,您可以像以下代碼片段一樣使用JSTL的c:set:
<c:set var="showPerson" value="#{anotherBean.showPerson}"/><h:inputText value="#{oneBean.name}" rendered="#{showPerson}"/> <h:inputText value="#{oneBean.birthday}" rendered="#{showPerson}"/> <h:selectOneMenu value="#{oneBean.children}" style="#{showPerson ? 'display:block' : 'display:none'}"/><c:set var="man" value="#{someBean.isMan(person)}"/> <c:set var="country" value="#{someBean.getCountry(person)}"/><ui:include src="/include/somesnippet.xhtml"><ui:param name="age" value="#{man ? 63 : 60}"/><ui:param name="money" value="#{man and country eq 'de' ? 1000 : 900}"/><ui:param name="big" value="#{country eq 'zh' or country eq 'ru' ? true : false}"/> </ui:include>如果您擔心JSTL的陷阱(因為您聽說過JSTL并不總是對JSF友好!),則有另一種簡單的方法– ui:param。 TagHandler ui:param使用JSF的VariableMapper將EL表達式保存在地圖中。 該映射將頁面上的EL變量及其關聯的EL表達式映射。 在這里,您去:
<ui:param name="showPerson" value="#{anotherBean.showPerson}"/><h:inputText value="#{oneBean.name}" rendered="#{showPerson}"/> <h:inputText value="#{oneBean.birthday}" rendered="#{showPerson}"/> <h:selectOneMenu value="#{oneBean.children}" style="#{showPerson ? 'display:block' : 'display:none'}"/><ui:param name="man" value="#{someBean.isMan(person)}"/> <ui:param name="country" value="#{someBean.getCountry(person)}"/><ui:include src="/include/somesnippet.xhtml"><ui:param name="age" value="#{man ? 63 : 60}"/><ui:param name="money" value="#{man and country eq 'de' ? 1000 : 900}"/><ui:param name="big" value="#{country eq 'zh' or country eq 'ru' ? true : false}"/> </ui:include>該代碼更具可讀性,尤其是當您具有非常復雜且很長的表達式時。 注意:我們在這里談論的是可讀代碼,而不是性能優化,因為JSF TagHandlers不評估EL表達式。
翻譯自: https://www.javacodegeeks.com/2014/11/dont-repeat-expressions-in-facelets.html
facelets
總結
以上是生活随笔為你收集整理的facelets_不要在facelets中重复表情的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mcgs和plc连接(c连接linux)
- 下一篇: 竣工备案后面是什么(竣工备案后面)