是的,它会。将UIComponent#encodeAll()
检查是否isRendered()
返回true
,然后再继续对其自身及其子项进行编码。
另一方面,这表明您在<f:selectItems>
. 否则,您根本不会担心它返回的情况,null
并且从来没有首先问过这个问题。getter 方法是执行业务逻辑的错误位置。您应该在 (post)constructor 或 (action)listener 方法中执行此操作。getter 应该只返回已经准备好的值。
因此,这是错误的:
public boolean isShouldRender() {
boolean shouldRender = // Some business logic...
// ...
return shouldRender;
}
public List<Agent> getAllAgents() {
List<Agent> allAgents = // Some business logic...
// ...
return allAgents ;
}
相反,你应该这样做
// Have properties which you initialize during an event.
private boolean shouldRender;
private List<Agent> allAgents;
public void someEventMethod() { // E.g. postconstruct, action, ajax behavior, value change, etc.
shouldRender = // Some business logic.
allAgents = // Some business logic.
}
// Keep the getters untouched!
public boolean isShouldRender() {
return shouldRender;
}
public List<Agent> getAllAgents() {
return allAgents;
}
也可以看看: