简体   繁体   English

加载JSF页面时命令执行方法

[英]Order to execute method while loading JSF page

I've got 2 Controllers. 我有2个控制器。

FirstController FirstController

One will go to the DB and make a count(*) to see how many messages are unread. 一个将进入数据库并进行计数(*),以查看有多少未读消息。

SecondController SecondController

The other will open the message and when it opens, if it is unread, it'll be marked as read. 另一个将打开该消息,当它打开时,如果未读,则将其标记为已读。


The problem that i'm facing is that when I open the JSF page, it executes first the firstcontroller and then the second one. 我面临的问题是,当我打开JSF页面时,它首先执行第一个控制器,然后执行第二个控制器。 So it does not refresh how many messages I still have unread. 因此,它不会刷新我还有多少未读的邮件。

Is it possible to set an order to execute methods while opening the page? 打开页面时可以设置执行方法的顺序吗?

The page looks like a left side menu, that contains how many messages are unread, and in the center will open the message. 该页面看起来像一个左侧菜单,其中包含未读邮件的数量,并在中心打开该邮件。

How can I do it? 我该怎么做?

You didn't exactly give any details on how "JSF executes the firstcontroller". 您没有提供有关“ JSF如何执行firstcontroller”的任何详细信息。 Is this via a preRenderViewEvent handler, a @PostConstuct method, or what? 这是通过preRenderViewEvent处理机, @PostConstuct方法,还是什么?

From you problem description, it sounds like the order already happens to be correct? 从您的问题描述中,听起来顺序已经正确了吗? You say that the firstcontroller is executed, and this FirstController checks for unread messages. 您说firstcontroller已执行,并且此FirstController检查未读消息。 So messages are being 'refreshed'. 因此消息被“刷新”。 But then you say that it does not refresh the unread messages, so which is it? 但是然后您说它不刷新未读的消息,那是什么?

Regardless, a single JSF view (page) is best backed by a single backing bean. 无论如何,单个JSF视图(页面)最好由单个支持bean支持。 This single backing bean orchestrates calls to different services (eg EJB beans) and prepares all required data. 单个后备bean协调对不同服务(例如EJB bean)的调用,并准备所有必需的数据。 The view then binds to this backing bean only to fetch its data. 然后,视图绑定到该支持Bean,仅获取其数据。

With this setup you won't run in any execution order problems at all. 使用此设置,您根本不会遇到任何执行顺序问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM