Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_cn
Articles_de
Articles_pt
Articles_zh
CreateActions
CreateActions_de
CreateActions_it
CreateActions_pt
CreateActions_zh
...and 1 more




JSPWiki v2.2.33

[RSS]


Hide Menu

JSFBeans


Difference between version 24 and version 6:

At line 6 changed 1 line.
This tutorial will show you how to create JSF Beans and JSPs. It'll also demonstrate writing a JUnit Test to test PersonForm. The Managed Bean we create will talk to the PersonManager we created in the [Creating Managers|CreateManager] tutorial. In most web frameworks, the controller logic is contain in an "Action" of some sort. However, with JSF, they're commonly referred to as "Managed Beans". The methods within these beans are called actions. This tutorial is not going to teach you a whole lot about how JSF works, but it will get you up and running quickly with it. If you want a more in-depth learning experience, I suggest you read [David Geary's|http://jroller.com/page/dgeary] [Core JSF|http://www.horstmann.com/corejsf/].
This tutorial will show you how to create JSF Beans and JSPs. It'll also demonstrate writing a JUnit Test to test PersonForm. The Managed Bean we create will talk to the PersonManager we created in the [Creating Managers|CreateManager] tutorial. In most web frameworks, the controller logic is contain in an "Action" of some sort. However, with JSF, they're commonly referred to as "Managed Beans". The methods within these beans are called actions. This tutorial is not going to teach you a whole lot about how JSF works, but it will get you up and running quickly with it. If you want a more in-depth learning experience, I suggest you read [David Geary's|http://jroller.com/page/dgeary] [Core JSF|http://www.horstmann.com/corejsf/]. I had it close by my side and used it frequently while integrating JSF into AppFuse. Thanks for the help David and Cay (co-author)!
At line 13 changed 3 lines.
* [1] Create skeleton JSPs using XDoclet
* [1] Create personForm.jsp with XDoclet
At line 22 changed 2 lines.
!!Create a skeleton JSP using XDoclet [#1]
In this step, you'll generate a ''skeleton'' JSP to display information from the Person object. I say ''skeleton'' because it'll just be the <form> itself. It will contain JSF's JSP tags that render table rows for each property in Person.java. The AppGen tool that's used to do this is based off a StrutsGen tool - which was originally written by [Erik Hatcher|http://www.blogscene.org/erik/]. It's basically just a couple of classes and a bunch of XDoclet templates. All these files are located in extras/appgen.
!!Create personForm.jsp with XDoclet [#1]
In this step, you'll generate a JSP page to display information from the Person object. It will contain JSF's JSP tags that render table rows for each property in Person.java. The [AppGen] tool that's used to do this is based off a StrutsGen tool - which was originally written by [Erik Hatcher|http://www.blogscene.org/erik/]. It's basically just a couple of classes and a bunch of XDoclet templates. All these files are located in extras/appgen.
At line 28 changed 1 line.
* Execute __ant -Dobject.name=Person -Dappgen.type=pojo__ to generate a bunch of files in extras/appgen/build/gen. In fact, it'll generate all the files you need to complete this tutorial. However, let's just grab the ones you need.
* Execute __ant -Dobject.name=Person -Dappgen.type=pojo -Dapp.module=__ to generate a bunch of files in extras/appgen/build/gen. In fact, it'll generate all the files you need to complete this tutorial. However, let's just grab the ones you need.
At line 30 changed 3 lines.
** web/personForm.jsp (skeleton JSP file for viewing a single Person)
** web/personList.jsp (skeleton JSP file for viewing a list of People)
* Copy the contents of Person.properties into web/WEB-INF/classes/ApplicationResources_en.properties. These are all the keys you will need for titles/headings and form properties. Here is an example of what you should add to ApplicationResources_en.properties:
** web/personForm.xhtml (Facelets template for viewing a single Person)
** web/personList.xhtml (Facelets template for viewing a list of People)
* Copy the contents of Person.properties into web/WEB-INF/classes/ApplicationResources.properties. These are all the keys you will need for titles/headings and form properties. Here is an example of what you should add to ApplicationResources.properties:
At line 36 changed 3 lines.
personForm.id=Id
personForm.firstName=First Name
personForm.lastName=Last Name
person.id=Id
person.firstName=First Name
person.lastName=Last Name
At line 53 changed 1 line.
* Copy personForm.jsp to web/personForm.jsp. Copy personList.jsp to web/personList.jsp. ''Notice that each of the new filename's first character is lowercase.''
* Copy personForm.xhtml to web/personForm.xhtml. Copy personList.xhtml to web/personList.xhtml.
At line 69 added 1 line.
At line 74 added 1 line.
At line 87 changed 1 line.
assertEquals(bean.save(), "list");
assertEquals("list", bean.save());
At line 95 changed 1 line.
assertEquals(bean.edit(), "edit");
assertEquals("edit", bean.edit());
At line 103 changed 1 line.
assertEquals(bean.edit(), "edit");
assertEquals("edit", bean.edit());
At line 112 changed 1 line.
assertEquals(bean.save(), "edit");
assertEquals("edit", bean.save());
At line 121 changed 1 line.
assertEquals(bean.delete(), "list");
assertEquals("list", bean.delete());
At line 198 changed 1 line.
You'll notice a number of keys in this file - "person.deleted", "person.added" and "person.updated". These are all keys that need to be in your i18n bundle (ApplicationResources_en.properties). You should've added these at the beginning of this tutorial. If you want to customize these messages, to add the a person's name or something, simply add a {0} placeholder in the key's message and then use the addMessage(key, stringtoreplace) method. You can also use an Object[] for the stringtoreplace variable if you want to make multiple substitutions.
You'll notice a number of keys in this file - "person.deleted", "person.added" and "person.updated". These are all keys that need to be in your i18n bundle (ApplicationResources.properties). You should've added these at the beginning of this tutorial. If you want to customize these messages, to add the a person's name or something, simply add a {0} placeholder in the key's message and then use the addMessage(key, stringtoreplace) method. You can also use an Object[] for the stringtoreplace variable if you want to make multiple substitutions.
At line 221 added 2 lines.
%%note Spring's [DelegatingVariableResolver|http://www.springframework.org/docs/api_1.2/org/springframework/web/jsf/DelegatingVariableResolver.html] helps JSF to resolve "#{personManager}" to the "personManager" Spring bean. This "variableResolver" has already been declared at the top of the ''faces-config.xml'' file.%%
At line 226 changed 1 line.
<from-view-id>/personForm.jsp</from-view-id>
<from-view-id>/personForm.xhtml</from-view-id>
At line 229 changed 1 line.
<to-view-id>/mainMenu.jsp</to-view-id>
<to-view-id>/mainMenu.xhtml</to-view-id>
At line 234 changed 1 line.
<to-view-id>/mainMenu.jsp</to-view-id>
<to-view-id>/mainMenu.xhtml</to-view-id>
At line 240 changed 1 line.
;:''The PersonForm returns "list" from the {{delete()}} and {{save()}} methods. In the next tutorial, you will eventually change the "list" in the navigation-rule to point to the list screen.''
;:''The PersonForm returns "list" from the {{cancel()}}, {{delete()}} and {{save()}} methods. In the next tutorial, you will change the "list" in the navigation-rule to point to the list screen.''
At line 272 changed 1 line.
If you want to add a usability enhancement to your form, you can set the cursor to focus on the first field when the page loads. Simply add the following JavaScript at the bottom of your form (web/personForm.jsp):
If you want to add a usability enhancement to your form, you can set the cursor to focus on the first field when the page loads. Simply add the following JavaScript at the bottom of your form (web/personForm.xhtml):
At line 296 changed 1 line.
<from-view-id>/mainMenu.jsp</from-view-id>
<from-view-id>/mainMenu.xhtml</from-view-id>
At line 299 changed 1 line.
<to-view-id>/personForm.jsp</to-view-id>
<to-view-id>/personForm.xhtml</to-view-id>
At line 304 changed 1 line.
Finally, to make this page more user friendly, you may want to add a message for your users at the top of the form, but this can easily be done by adding text (using &lt;fmt:message&gt;) at the top of the personForm.jsp page.
Finally, to make this page more user friendly, you may want to add a message for your users at the top of the form, but this can easily be done by adding text (using &lt;fmt:message&gt;) at the top of the personForm.xhtml page.
At line 363 added 1 line.
<verifytext description="verify success message" text="${person.updated}"/>
At line 397 added 1 line.
<prepareDialogResponse description="Confirm delete" dialogType="confirm" response="true"/>
At line 399 added 1 line.
<verifyNoDialogResponses/>

Back to JSFBeans, or to the Page History.