【发布时间】:2014-04-28 14:41:31
【问题描述】:
有没有办法获取托管 bean 中特定 div 内容的所有客户端 ID 的列表?我有 div 的客户端 ID。我必须在 div 内的每个组件上调用 resetValue(...)。
FacesContext.getCurrentInstance().getViewRoot().findComponent(...) 如果我提供客户端 ID,将给我一个组件。我不想使用它,因为我在 div 中有很多组件,而这将有大约 100 行代码来重置一个 div。
有没有一种方法可以获取cient id 列表,以便我可以遍历该列表并重置所有组件?我也对其他方法持开放态度,只要我可以重置 div 内的所有组件。
我的 bean 由 Spring (scope("view")) 管理。我使用a4j:commandButton 向这个bean 提交值。当我再次加载页面时,我看到了之前提交的值,这是不正确的。提交后,我在 div 内的一个组件上尝试了resetValue(...),它确实重置了组件的值。
任何帮助表示赞赏。
代码示例:
xhtml:
<a4j:outputPanel id="EditSeaPage">
<a4j:outputPanel id="editSeaContainer"
rendered="#{seaBean.showEditSea}" layout="block"
styleClass="switch-section">
<h:panelGroup>
<h:outputLabel value="#{messageSource.sea_label}" />
<h:inputText id="updateSeaCode"
value="#{seaBean.seaUIDTO.seaCode}"
styleClass="user-detail">
<a4j:ajax />
</h:inputText>
</h:panelGroup>
<a4j:commandButton id="confirmUpdateSeaCode" execute="@this"
action="#{seaBean.updateSeaCode}" render="parentContainer"/>
</a4j:outputPanel>
</a4j:outputPanel>
父 xhtml:
<a4j:commandLink id="editSeaCode" value="edit" onclick="hideMe()" render="editPortContainer"/>
豆子:
public String updateSeaCode() {
//does update
UIInput input = (UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent("updateSeaCode");
input.resetValue();
//This works. But I have around 20 input components in the above XHTML and can't write the //above code for each component
}
我只是添加了我正在做的事情的骨架。如何确保通话结束时视图得到更新?为了给我更多细节,它是这样工作的:我有一个edit 链接,它是一个a4j:commandLink。单击此链接时,我隐藏链接并显示editSeaContainer。如果你看到有一个渲染属性。当我点击edit 链接时,我会使用jQuery 隐藏链接并创建a4j:jsFunction 以将布尔属性设置为true,以便呈现此页面。在a4j:jsFunction 之后,我调用了一个 fetch 方法来检索这个 xhtml 的内容。当方法完成时,布尔值被设置并且“render”属性呈现页面。到这里为止一切都很好。但是输入值不会随着获取的值而更新。
谢谢。
【问题讨论】:
-
如果您使用 Ajax(看起来是这样)并且在响应中呈现列表,只需清除 bean 中的映射值字段。这意味着
client.setValue("")。 -
如果您的意思是清除 bean 中的值,我已经这样做了,但这并没有帮助。这些值已正确填充到 bean 中,但视图仍显示旧值。
-
那是因为 ajax 调用结束时视图没有更新。但是由于您没有提供代码的进一步示例,因此我无法推断出了什么问题。
-
使用
a4j:commandButton的render属性: -
我刚刚编辑了这段代码,以便您更清楚地了解我在做什么。我使用了“render”属性,但这仅有助于渲染“div/a4j:outputPanel”。这仍然无助于更新输入组件值。