java - Passing data between managed components in JSF -


Is it really possible to pass any data between managed components in JSF? If yes, how to get it?

Can anyone provide a sample?

There are several ways if managed beans are related to each other, then the property injection will be managed in a clean way . Suppose that there is only one scope in Bean 1 or there is a wide scope compared to Bean 2. First bean 2a bean 1 property:

  public square bean 2 {private bean 1 bean 1; // + getter + setter}  

to become a managed asset of Bean2 then declare Bean 1 in faces-config.xml :

< Pre> & lt; Managed-beep & gt; & Lt; Managed-name names & gt; Bean1 & lt; / Managed-name names & gt; & Lt; Successful bean category & gt; Com.example.Bean1 & lt; / Successful bean category & gt; & Lt; Realm of managed-beams & gt; Session & lt; / Managed-beans scope & gt; & Lt; / Successful bean> & Lt; Successful Bean & gt; & Lt; Managed-name names & gt; Bean2 & lt; / Managed-name names & gt; & Lt; Successful bean category & gt; Com.example.Bean2 & lt; / Successful bean category & gt; & Lt; Realm of managed-beams & gt; Request & lt; / Managed-beans scope & gt; & Lt; Managed-asset & gt; & Lt; Asset-name & gt; Bean1 & lt; / Property-name & gt; & Lt; Price & gt; # {Bean1} & lt; / Pricing & gt; & Lt; / Managed-properties & gt; & Lt; / Successful bean>

In this way there is quick access to bean 2 example bean 1 example.

If you do not want to use managed property injection for some reasons, you can also get it through the program. Here is an example of how to get back to Bean 1 in Bean 2:

  FacesContext reference = FacesContext.getCurrentInstance (); Bean 1 bean 1 = (Bean 1) reference. Gate app (). Evaluate ExpressOGet (Reference, "# {Bean 1}", Bean 1. Class);  

Bean 1 should be declared in the already managed Been Bean 1 as faces-config.xml .

For more information and hints about the surrounding data of JSF, you can find useful.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -