Notification of one bean from another in ICEFaces

I have an ICEFaces application. On one page there are two beans that display different things on the page.

I want to be able to notify one bean when another bean changes something to a bean so that the first bean updates its contents on the page.

Is this possible in ICEFaces? if so, how?

Thanks,

There

+3
source share
3 answers

What you can do is paste bean1 into bean2, so bean2 will have access to any method present in bean1.

If you use Spring, this can easily be done when defining beans:

<bean id="bean1" class="foo.bar.Bean1"/>
<bean id="bean2" class="foo.bar.Bean2">
    <property id="bean1" ref="bean1"/>
</bean>

and in bean2 java code:

public class Bean2 {

    private Bean1 bean1 = null;

    // The setter will be used by Spring to inject Bean1 in Bean2...
    public void setBean1(Bean1 bean1) {
        this.bean1 = bean1;
    }

    ...

    public void someMethod() {
        ...
        // Now, you can call the bean1 instance to update what you want...
        bean1.updateSomething();
    }

}

If you are not using Spring:

bean1 bean2 :

Bean1 bean1 = (Bean1) FacesContext.getCurrentInstance().getCurrentInstance()
    .getExternalContext().getSessionMap().get("bean1");
+5

, JSF . - faces-config.xml:

<managed-bean>
    <managed-bean-name>bean1</managed-bean-name>
    <managed-bean-class>org.icefaces.sample.Bean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>bean2</managed-bean-name>
    <managed-bean-class>org.icefaces.sample.Bean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>bean1</property-name>
        <value>#{bean1}</value>
    </managed-property>
</managed-bean>

, bean , . , ( , ), ICEfaces Ajax Push, . .

+3

, ICEFaces . .

0

Source: https://habr.com/ru/post/1716520/


All Articles