0

我需要在网页上的两个面板之间切换显示。最初将显示带有 p:commandButton "First" 的第一个面板。单击第一个按钮将发送 ajax 请求并显示带有 p:commandButton "Second" 的第二个面板。单击“第二个”按钮显示“第一个面板。但是,第二个面板视图状态未更新,因此 p:commandButton“第二个”无法触发事件。

<h:form id="firstForm" >
<h:panelGroup id="filterPanel" rendered="#{not filter.accepted}" >
<div id="menu">
<p:commandButton value="First" action="#{filter.action1}" update=":firstForm" >
</p:commandButton>
</div>
</h:panelGroup>

<h:panelGroup id="reportPanel" rendered="#{filter.accepted}" >
<div id="menu2">
<p:commandButton value="Second" action="#{filter.action2}" update=":firstForm">
</p:commandButton>
</div>
</h:panelGroup>
</h:form>

豆子代码:

private boolean accepted;
public void action1(){
System.out.println("Filter Button");
accepted = true;
}

public void action2(){
System.out.println("Report Button");
accepted = false;
}

public boolean isAccepted() {
System.out.println(accepted);
return accepted;
}

第一个面板 p:commandButton "First" 调用 action1 并打印 "Filter Button"。第二个面板 p:commandButton "Second" 不会调用 action2 函数,因为它的视图状态不可用。有什么解决办法。

我浏览了类似的页面,它对我也 不起作用 JSF2: Form ajax action makes another form's view state to be lost

谢谢

韩国开发银行

4

0 回答 0