1) Configure in Web. xml
<Web-app>
<Context-param>
<Param-Name> javax. Faces. config_files </param-Name>
<Param-value>/WEB-INF/faces-config.xml </param-value> there are many separated by commas
</Context-param>
...
</Web-app>
2) If you want to retrieve bean objects in other categories, You can first obtain
Javax. Faces. Context. facescontext, which represents the current execution environment object of JSF.
Obtain the javax. Faces. El. valuebinding object and obtain the specified bean object. For example:
Facescontext context = facescontext. getcurrentinstance ();
Valuebinding binding = context. getapplication (). createvaluebinding ("# {user }");
Userbean user = (userbean) binding. getvalue (context );
If you only want to obtain a bean attribute, you can:
Facescontext context = facescontext. getcurrentinstance ();
Valuebinding binding =
Context. getapplication (). createvaluebinding ("# {user. name }");
String name = (string) binding. getvalue (context );
3) * if it is necessary to automatically set the initial attribute values when bean is started, you can set the attributes as follows:
<Managed-bean>
<Managed-bean-Name> User </managed-bean-Name>
<Managed-bean-class>
Onlyfun. Caterpillar. userbean
</Managed-bean-class>
<Managed-bean-scope> session </managed-bean-scope>
<Managed-property>
<Property-Name> name </property-Name>
<Value> caterpillar </value>
</Managed-property>
<Managed-property>
<Property-Name> password </property-Name>
<Value> 123456 </value>
</Managed-property>
</Managed-bean>
If you want to set the attribute to null, you can use the <null-value/> label, for example:
<Managed-property>
<Property-Name> name </property-Name>
<Null-value/>
</Managed-property>
Other Types
<Managed-property>
<Property-Name> User </property-Name>
<Value >#{ user} </value>
</Managed-property>
<Managed-property>
<Property-Name> someproperty </property-Name>
<! -- List --> <list-entries>
<Value-class> JAVA. Lang. Integer </value-class>
<Value> 1 </value>
<Value> 2 </value>
<Value> 3 </value>
</List-entries>
</Managed-property>
<Managed-property>
<Property-Name> someproperty </property-Name>
<Map-entries>
<Value-class> JAVA. Lang. Integer </value-class>
<Map-entry>
<Key> somekey1 </key>
<Value> 100 </value>
</Map-entry>
<Map-entry>
<Key> somekey2 </key>
<Value> 200 </value>
</Map-entry>
</Map-entries>
</Managed-property>