在我的代码中,我正在扩展左框架中的树节点,该树节点是通过右框架中存在的导航链接选择的。它有效,但每次我单击右框架上的链接时,我都必须手动刷新右框架。我尝试使用 javascript 代码从支持 bean 重新加载页面,但它不起作用。谁能帮我弄清楚为什么它没有被执行。
预先感谢您帮助我。
下面是我正在使用的代码。
public void expandTreeView( TreeNode selectedNode )
{
if ( selectedNode != null )
{
selectedNode.getParent().setExpanded( true );
}
RequestContext rc = RequestContext.getCurrentInstance();
rc.execute("window.location.reload(true)");
}
您需要将 JS 函数与 RemoteCommand 结合起来,它将如下所示:
myHTML.xhtml
<p:commandLink id="commandLink" onclick="myFunction(nodeSelected)" >
...
</p:commandLink>
还添加一个JS函数
<script type="text/javascript">
function myFunction(x) {
...
}
</script>
最后将其与p:remoteCommand
它允许您从 JS 函数调用 ManagedBean 方法
你可以看到Primefaces 远程命令示例 https://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml或者只是看看这个SO帖子通过 JavaScript 函数调用 p:remoteCommand,通过“oncomplete”处理程序将该函数本地的消息传递给另一个函数 https://stackoverflow.com/questions/32377522/invoking-a-premotecommand-via-a-javascript-function-passing-a-message-local-to
希望对您有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)