首先,無論選擇什麼,兩者都是一個不好的做法。另請參閱How does the 'binding' attribute work in JSF? When and how should it be used?
如果必須做出選擇,組件綁定肯定會更快,更便宜。從邏輯上講,完全意識到UIComponent#findComponent()
所做的樹掃描具有其性能影響。
事實上,支持bean持有組件綁定必須是請求範圍,但你可以輕鬆地將不同範圍的支持bean通過@ManagedProperty
持有它的業務邏輯。
更簡潔的方法是使用Map
作爲所有組件綁定的持有者。你只需要在以下條目添加到faces-config.xml
:
<managed-bean>
<managed-bean-name>components</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
這正好可以作爲
<h:inputSome binding="#{components.input1}" />
<h:inputSome binding="#{components.input2}" />
<h:inputSome binding="#{components.input3}" />
,並能在其他豆類
Map<String, UIComponent> components = (Map<String, UIComponent>) externalContext.getRequestMap().get("components");
這樣你可以得到不需要擔心指定單個屬性/ getter/setter。在上面的示例中,Map
將包含三個條目,其中鍵爲input1
,input2
和input3
,每個條目的值都爲UIComponent
。
無關的具體問題,如你在其他問題不是執行的操作方法的驗證(這實際上是糟糕的設計)描述有可能是一個更簡單的解決具體問題。我已經在那裏發佈了答案。
同樣的問題在[這個其他論壇](http://www.jguru.com/forums/view.jsp?EID = 1522894#),但很可惜,沒有答案;) – Louise