如何在调用模板中更新菜单栏 [英] How do I update a menu bar in a calling template

查看:42
本文介绍了如何在调用模板中更新菜单栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为练习,我希望有一个菜单栏,该菜单栏在用户登录之前被禁用.当他登录时,我想调用一些会触发更新的内容.菜单栏位于master.xhtml模板文件

As an exercise I want to have a menu bar which is disabled until the user logs in. When he logs in I want to call something which will trigger an update. The menu bar is in the master.xhtml template file

<h:form >
  <p:menubar id="masterMenuBar">
  <p:menuitem disabled="#{backing.disableMenu}" value="List users" />
  </p:menubar>
</h:form>

作为登录的一部分,我有刷新表单的代码

As part of the login I have code to refresh the form

public void refreshForm() {
  RequestContext context = RequestContext.getCurrentInstance(); 
  context.update("form1"); 
  context.update("masterMenuBar");
}

我很幸运,尝试对定义的标签masterMenuBar进行上下文更新,但是RequestContext显然不包括我的调用模板形式(听起来很合理).

I tried my luck with calling a context update to my defined label of masterMenuBar but the RequestContext apparently doesn't include my calling template form (which sounds reasonable enough).

还有其他可以调用的上下文,其中包括菜单栏的上下文更新吗?也许我走在错误的道路上,并且有更好的方法可以实现相同的目标?

Is there some other context I can call which will include a context update to my menu bar? Perhaps I am on the wrong path, and there is a better way to achieve the same thing?

我确实注意到,即使调整浏览器的大小也不足以再次调用我的backing.disableMenu bean.显然,我需要一些足够坚固的东西才能使它第二次到达我的豆子.

I did notice that even resizing the browser wasn't reason enough to call again to my backing.disableMenu bean. Apparently I need something fairly strong to cause it to reach my bean a second time.

推荐答案

您需要传递绝对客户端ID,而不是相对客户端ID.如果右键单击并在浏览器中查看源代码,则会看到masterMenuBar元素具有其形式的(自动生成的)ID作为前缀.

You need to pass the absolute client ID, not the relative client ID. If you rightclick and view source in browser, then you'll see that the masterMenuBar element has the (autogenerated) ID of its form prefixed.

您需要提供菜单位于固定ID的表单

You need to give the form where the menu is sitting in a fixed ID

<h:form id="menuForm">
    <p:menubar id="masterMenuBar">
        ...

并传递绝对客户端ID.

and pass the absolute client ID instead.

context.update("menuForm:masterMenuBar");


更新:抱歉,它不应以:开头,而不是<p:commandButton>update属性.


Update: sorry, it shouldn't start with : in contrary to the update attribute of <p:commandButton>.

这篇关于如何在调用模板中更新菜单栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆