导航到页面时如何首先初始化某个 MBean

发布于 2024-11-14 21:09:27 字数 464 浏览 3 评论 0原文

我的页面分为 3 部分。第一部分是绑定到 mBean (MLeft) 的链接列表,第二部分是当前的 mBean (MCenter)我所在的页面。MCenter 将数据插入到 MLeft 中,以便第一部分中的链接是我当前所在页面的自定义链接。问题是,当呈现页面并评估链接时 MLeft 是在 MCenter 之前创建 (因为在页面的前面找到)并且 MCenter 没有机会在 MLeft 中插入链接,因此不会显示任何链接。我在链接之前使用引用 dummy 属性的输出文本调用 MCenter,该属性是一个空字符串
我不喜欢这种解决方法,我过去也曾使用 Seam@Out 遇到过这个问题,我这样解决了它。有更好的方法吗?

I have a page split in 3. First part is a list of links which is bound to a mBean (MLeft), and the second is the current mBean (MCenter) of the page I'm in. MCenter inserts data into MLeft so that the links from the first part are custom to the page I'm currently in. The thing is that when the page is rendered and the links are evaluated MLeft is created before MCenter (because is found earlier in the page) and MCenter doesn't get the chance to insert the links in MLeft, so no links are displayed. I put a call to MCenter before the links using an output text referring a dummy property which is an empty string.
I don't like this workaround, I had this problem in the past too with Seam and @Out and I solved it like this. Is there a better approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过期情话 2024-11-21 21:09:27

也许您可以使用 follow 方法:

 <f:view beforePhase="#{userMB.verifyUser}" />

该方法将在页面加载时被调用

Maybe you can use follow method:

 <f:view beforePhase="#{userMB.verifyUser}" />

the method will be invoked when the page be loaded

如梦亦如幻 2024-11-21 21:09:27

我认为您需要使用模板:

template.xhtml

<ui:composition>
   <h:head>
       <title>
           <ui:insert name="title" />
       </title>
       <h:outputStylesheet name="css/haleczander.css" />
   </h:head>
   <h:body>
       <div class="left">
          <ui:include src="static_links.xhtml />
          <ui:repeat value="#{links}" var="link">
              <h:outputLink value="#{link}">#{link}</h:outputLink>
          </ui:repeat>
       </div>
       <div class="center">
          <ui:insert name="content" />             
       </div>
    </h:body>
</ui:composition>

content1.xhtml

<ui:composition template="template.xhtml">
        <ui:define name="title">
             Content page 1
        </ui:define>
        <ui:param name="links" value="#{middle.links}" />
        <ui:define name="content">
             Blah blah 1
        </ui:define>
</ui:composition>   

我假设 links 是一个列表或字符串数​​组,但您可以对其进行任何操作:自定义 MyLink 对象的列表,...(只要有一个合适的 getter)

您也可以将 middle.links 替换为您喜欢的任何内容,事件调用如 #{middle.getLinks(page1)}

I think you need to use templates:

template.xhtml

<ui:composition>
   <h:head>
       <title>
           <ui:insert name="title" />
       </title>
       <h:outputStylesheet name="css/haleczander.css" />
   </h:head>
   <h:body>
       <div class="left">
          <ui:include src="static_links.xhtml />
          <ui:repeat value="#{links}" var="link">
              <h:outputLink value="#{link}">#{link}</h:outputLink>
          </ui:repeat>
       </div>
       <div class="center">
          <ui:insert name="content" />             
       </div>
    </h:body>
</ui:composition>

content1.xhtml

<ui:composition template="template.xhtml">
        <ui:define name="title">
             Content page 1
        </ui:define>
        <ui:param name="links" value="#{middle.links}" />
        <ui:define name="content">
             Blah blah 1
        </ui:define>
</ui:composition>   

I'm assuming links is a list or an array of strings, but you could make anything of it: a list of custom MyLink object, ... (as long as there is an appropriate getter)

You could also replace middle.links with whatever you like, event a method call like #{middle.getLinks(page1)}

少女七分熟 2024-11-21 21:09:27

只需将 Center 设为 Left 的托管属性即可。例如

@ManagedBean
@RequestScoped
public class Left {

    @ManagedProperty(value="#{center}")
    private Center center;

    @PostConstruct
    public void init() {
        // Initialize links based on Center here.
    }

    // ...
}

Just make Center a managed property of Left. E.g.

@ManagedBean
@RequestScoped
public class Left {

    @ManagedProperty(value="#{center}")
    private Center center;

    @PostConstruct
    public void init() {
        // Initialize links based on Center here.
    }

    // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文