JSF tutorial 2 managed beans

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.