Lor*_*ic- 3 jsf render commandbutton
我阅读了很多关于 f:ajax 与其他 jsf 或 html 标签一起工作的内容,但这似乎还不够!
我的页面中有一个带有(必需的?)f:ajax 标记的 commandButton,并且该操作永远不会被触发。这是代码。
<html>
<h:head>
</h:head>
<h:body>
<h:form>
<h:commandButton action="#{bean.myFirstFunction}" value="Submit">
<f:ajax render=":wrap" />
</h:commandButton>
</h:form>
<h:panelGroup id="wrap">
<h:panelGroup id="content" rendered="#{bean.myVariable != null}">
<h:form>
<h:commandButton action="#{bean.mySecondFunction}" value="Submit">
<f:ajax render=":wrap" />
</h:commandButton>
</h:form>
</h:panelGroup>
</panelGroup>
<h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以像上面一样,我有两个按钮,第一个从包装中工作,它必须显示隐藏在开头的包装面板。第二个是在包装中,必须启动一个完全不同的动作。(包装必须保持显示)
这是豆子。
@ManagedBean(name = "bean")
@ViewScoped
public class myBean {
private Object myVariable;
public void setMyVariable(Object o) { ... }
public Object getMyVariable() { ... }
@PostConstruct
public void init() {
this.myVariable = null;
}
public void myFirstFonction() {
this.myVariable = new Object();
}
public void mySecondAction() {
System.out.println("here");
}
}
Run Code Online (Sandbox Code Playgroud)
当我启动时,我看到第一个按钮。我点击它,第二个出现。(因此调用第一个函数,实例化对象并使用 ajax 标记呈现包装。但是,当单击第二个按钮时,什么也没有发生。
我只写了一部分代码,希望错误就在这里。
我认为这是关于面板组的渲染选项,但我无法准确定位它。
谢谢
根据commandButton/commandLink/ajax action/listener 方法的第9 点未调用或输入值未设置/更新,您是JSF 规范问题 790 的受害者。当你 ajax-update 一些内容又包含一个表单时,它会失去它的视图状态。作为一种快速解决方法,只需为要更新的表单提供一个 ID 并明确引用它<f:ajax render>。
<h:body>
<h:form>
<h:commandButton action="#{bean.myFirstFunction}" value="Submit">
<f:ajax render=":wrap :wrapForm" />
</h:commandButton>
</h:form>
<h:panelGroup id="wrap">
<h:panelGroup id="content" rendered="#{bean.myVariable != null}">
<h:form id="wrapForm">
<h:commandButton action="#{bean.mySecondFunction}" value="Submit">
<f:ajax render=":wrap" />
</h:commandButton>
</h:form>
</h:panelGroup>
</panelGroup>
<h:body>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8173 次 |
| 最近记录: |