仅当元素存在时才进行Ajax渲染

问题描述:

我有以下用例:我在屏幕上有一个按钮,可重新渲染其他元素.

I have the following usecase: I have a button on the screen which rerenders an other element.

<h:commandButton value="button">
  <f:ajax  execute="@this" render="toBeRendered" />
</h:commandButton>
......
<h:outputPanel id="toBeRendered"/>

我的问题是,另一个元素(toBeRendered)并不总是存在,因为它位于页面上的ui组成内,因此JSF在构建视图时失败,并且无法在f的render属性中找到该元素:ajax标记.我知道此验证不再存在于较新版本的mojarra中,但不能选择进行更新.是否有人有变通办法,使其仅在其他元素存在时才会呈现?

My problem is that this other element (toBeRendered) does not always exists because it is within an ui compostion on the page so JSF fails when it builds the view and can't find the element thats in the render attribute of the f:ajax tag. I know that this validation is no longer there in newer version of mojarra but updating is not an option. Does anybody has a workaround that so that it would only render when the other element exists?

使用

请注意,#{component}是引用当前UIComponent实例的隐式EL对象.因此,代码按原样完整.

Note that #{component} is an implicit EL object referring the current UIComponent instance. So the code is complete as-is.

无关与具体问题无关,应指出的是,根据

Unrelated to the concrete problem, noted should be that the missing <f:ajax> validation in Mojarra 2.2.5+ will come back later as per issue 1372. It's namely confusing to many starters.