Võ Văn Hải's blog

Chỉ có một điều tuyệt đối đó là mọi thứ đều tương đối…

Đăng ký các managed bean và định nghĩa các navigation rules

Managed Beans được tạo cho ứng dụng được yêu cầu đăng ký trong tập tin faces-config.xml. Tên của Managed bean và lớp thực sự chứa nó được định nghĩa bên trong thẻ “managed-bean” và các luật chuyển trang được định nghĩa trong thẻ “navigation-rule”.

Bạn tạo các managed bean trong eclipse bằng cách mở file faces-config.xml, giao diện như sau
https://vovanhai.files.wordpress.com/2008/11/logreg_18.png

Tương tữ bạn tiến hành thêm các bean khác.
Navigation rules được cho như hình sau:
https://vovanhai.files.wordpress.com/2008/11/logreg_19.png

Nội dung file faces-config.xml như sau:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE faces-config PUBLIC “-//Sun Microsystems, Inc.//DTD JavaServer Faces
Config 1.1//EN”
http://java.sun.com/dtd/web-facesconfig_1_1.dtd”&gt;
<faces-config>

<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>

<managed-bean>
<managed-bean-name>LoginForm</managed-bean-name>
<managed-bean-class>vovanhai.wordpress.bean.LoginForm</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>RetrievePassword</managed-bean-name>
<managed-bean-class>vovanhai.wordpress.bean.RetrievePassword</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>userForm</managed-bean-name>
<managed-bean-class>vovanhai.wordpress.bean.UserForm</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
<from-view-id>/user/login.jsp</from-view-id>
<navigation-case>
<from-action>#{LoginForm.validUser}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/user/success.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{LoginPage.validUser}</from-action>
<from-outcome>failure</from-outcome>
<to-view-id>/user/login.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>forgotpassword</from-outcome>
<to-view-id>/user/forgotpassword.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>useraccount</from-outcome>
<to-view-id>/user/useraccount.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/user/forgotpassword.jsp</from-view-id>
<navigation-case>
<from-action>#{RetrievePassword.check}</from-action>
<from-outcome>passwordsendingsuccess</from-outcome>
<to-view-id>/user/successpwdsend.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{RetrievePassword.check}</from-action>
<from-outcome>passwordsendingfail</from-outcome>
<to-view-id>/user/forgotpassword.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/user/success.jsp</from-view-id>

<navigation-case>
<from-action>#{LoginForm.logout}</from-action>
<from-outcome>logoutsuccess</from-outcome>
<to-view-id>/user/logout.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{userForm.editProfile}</from-action>
<from-outcome>editSuccess</from-outcome>
<to-view-id>/user/useraccount.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>changePassword</from-outcome>
<to-view-id>/user/changepassword.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/user/changepassword.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/user/changepasswordsuccess.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/user/changepassword.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>gotomain</from-outcome>
<to-view-id>/user/success.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/user/useraccount.jsp</from-view-id>
<navigation-case>
<from-action>#{userForm.saveUser}</from-action>
<from-outcome>successUserRegistration</from-outcome>
<to-view-id>/user/newaccountsuccess.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{userForm.saveUser}</from-action>
<from-outcome>successUserUpdate</from-outcome>
<to-view-id>/user/userUpdateSuccess.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{userForm.saveUser}</from-action>
<from-outcome>error</from-outcome>
<to-view-id>/user/useraccount.jsp</to-view-id>
</navigation-case>
</navigation-rule>

</faces-config>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 2,195 other followers

%d bloggers like this: