调用吸气剂后执行业务逻辑 [英] Perform business logic after getters are called

查看:96
本文介绍了调用吸气剂后执行业务逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两次调用getter和setter之后写我的业务逻辑, 因为我在业务逻辑中使用了它们的对象值. 但是,在吸气剂之前调用了Construct,Post构造,actionevents ..

I would like to write my business logic after the getters and setters are called (twice), because I use their object values inside the business logic. However Construct, Post construct, actionevents,.. are called before the getters.

那么如果我不想在内部获取业务逻辑,该如何使用它们的值呢?

So how can I use the values of the getters if I don't want to write business logic inside them?

推荐答案

我想导航到该站点并从显示在outputText中的数据库中获取数据.

在bean的(后)构造函数中完成该工作.

Do the job in (post)constructor of the bean.

@ManagedBean
@RequestScoped
public class Bean {

    private String data;

    @EJB
    private SomeService service;

    @PostConstruct
    public void init() {
        data = service.load();
    }

    // Getter.
}

使用

<h:outputText value="#{bean.data}" />


当我更改(primefaces)selectOneMenu值时,bean将获取selectOneMenu的值并在数据库中对该值进行查询,并将查询结果写入outputText中.

使用附加到输入组件的change事件的bean的ajax侦听器方法完成该工作.

Do the job in the ajax listener method of the bean which is attached to input component's change event.

@ManagedBean
@ViewScoped
public class Bean {

    private String selectedItem;
    private String result;

    @EJB
    private SomeService service;

    public void changeSelectedItem(AjaxBehaviorEvent event) {
        result = service.find(selectedItem);
    }

    // Getters+setter.
}

使用

<p:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems ... />
    <p:ajax listener="#{bean.changeSelectedItem}" update="result" />
</p:selectOneMenu>
<h:outputText id="result" value="#{bean.result}" />


在调用吸气剂之后 进行操作将为时已晚.到那时,JSF已经完成了呈现HTML输出的工作.之后,您将无法更改HTML输出.


Doing it after the getters are called would be too late. JSF would at that point already be finished with rendering the HTML output. You can't change the HTML output afterwards.

这篇关于调用吸气剂后执行业务逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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