From jbosstools-commits at lists.jboss.org Fri May 28 09:59:48 2010 Content-Type: multipart/mixed; boundary="===============3851867685838367443==" MIME-Version: 1.0 From: jbosstools-commits at lists.jboss.org To: jbosstools-commits at lists.jboss.org Subject: [jbosstools-commits] JBoss Tools SVN: r22411 - in trunk/documentation/guides/GettingStartedGuide/en-US: images/first_seam and 1 other directory. Date: Fri, 28 May 2010 09:59:48 -0400 Message-ID: <201005281359.o4SDxm9E004484@svn01.web.mwc.hst.phx2.redhat.com> --===============3851867685838367443== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: smukhina Date: 2010-05-28 09:59:47 -0400 (Fri, 28 May 2010) New Revision: 22411 Modified: trunk/documentation/guides/GettingStartedGuide/en-US/first_seam.xml trunk/documentation/guides/GettingStartedGuide/en-US/images/first_seam/f= irst_seam13.png trunk/documentation/guides/GettingStartedGuide/en-US/images/first_seam/f= irst_seam3.png trunk/documentation/guides/GettingStartedGuide/en-US/images/first_seam/f= irst_seam5.png trunk/documentation/guides/GettingStartedGuide/en-US/images/first_seam/f= irst_seam8.png Log: nomsg Modified: trunk/documentation/guides/GettingStartedGuide/en-US/first_seam.x= ml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/documentation/guides/GettingStartedGuide/en-US/first_seam.xml 201= 0-05-28 13:11:43 UTC (rev 22410) +++ trunk/documentation/guides/GettingStartedGuide/en-US/first_seam.xml 201= 0-05-28 13:59:47 UTC (rev 22411) @@ -1,820 +1,828 @@ - - - - - - JBoss Developer Studio - Seam - JBoss - - - Write Your First Project with JBoss Developer Studio - This chapter is a set of hands-on labs. You get step-by-step infor= mation about how the JBoss - Developer Studio can be used during the development process. -
- Create a Seam Application - In this section you get to know how to create a Seam project in = JBDS, how to start the - server and what a structure your project has after creating. -
- Start Development Database - Before opening the JBoss Developer studio you need to download= and start W= orkshop Database - . - To start the database just run ./runDBServer.sh or runDBServer.bat from the database directory. - The end result should be a console window that looks like: -
- Starting DataBase - - - - - -
-
-
- Create and deploy Seam Web Project - Minimize the terminal window and run the JBoss Devel= oper Studio - from Applications Menu or from the desktop icon. - First of all you get the Workspace Launcher. Change the defaul= t workspace location if - it's needed. Click on Ok. -
- Workspace Launcher Dialog - - - - - -
- After startup, you see the welcome page. You could read how to= work with welcome pages - in previous chapter. Now select <= property>Create - New... icon and then press on Create Seam P= roject - link. - The New Seam Project wizard is started. Y= ou need to enter a name - (e.g., "workshop") and a location directory for your new= project. The wizard has - an option for selecting the actual Server (and not just WTP runtim= e) that will be used for - the project. This allows the wizard to correctly identify where th= e needed datasource and - driver libraries need to go. -
- New Seam Project Wizard - - - - - -
- All settings are already specified here, you can just modify t= he Configuration. Click on - the - Modify... - button to configure your custom facets pattern: -
- Project Facets Specifying - - - - - -
- On the whole the dialog allows to select the "features" you wa= nt to use in your project. - Doing this JBoss Developer Studio setups the = appropriate tooling for - your project. Since JBoss Seam integrates all popular Java EE fram= eworks, you can select any - combination of technologies from the list. Here, for the default c= onfiguration, Dynamic Web - Module, Java, JavaServer Faces (JSF), and Seam Facet are already s= elected for a typical - database-driven web application. The default project facets should= suffice. - In the Project Facets form you can also b= ring up server runtimes - panel by clicking Runtimes tab on the right = corner. This panel shows - available server runtimes. -
- Runtimes Selecting - - - - - -
- Click on - Ok - and then - Next - to proceed further. - A dynamic web application contains both web pages and Java code. - The next wizard will ask you where you want to store Java files. -
- Java Build Path - - - - - -
- Following page provides you Web Module Settings .You can just leave - the default values or choose another folder. -
- Web Module Settings - - - - - -
- On the next form, you will be able to select where those libra= ry JARs come from. The - easiest is just to select the JARs provided by the JBoss AS runtim= e associated with this - project. That is why it is important to chose the right JBoss AS 4= .2 runtime in the project - setup window. - - - Select - Library Provided by Target Runtime - as Type of JSF Impl= ementation - Library. We will use the JSF implementation that = comes with JBoss - server. - - - Click - Next - - - -
- JSF Capabilities Adding - - - - - -
- Next wizard step needs more settings that previous. Let's star= t with General section. - Leave the default Seam runtime and check a WAR deployment. -
- Seam Facet Setting - - - - - -
- Next Database section is a little tricky.= The Connection - Profile needs to be edited so that the new project wo= rks properly with the - external HSQLDB server. By default the project wizard tries to use= the JBoss embedded - HSQLDB, but the tutorial uses an external database to replicate a = more real world - development scenario. Click on Edit to modify= the Connection - Profile. -
- DataBase Setting - - - - - -
- Select HSQLDB Profile Properties. Make su= re the Database location - is set to - hsql://localhost:1701 - -
- JDBC Connection Properties - - - - - -
- Try click on Test Connection button. It p= robably won=E2=80=99t work. This - happens if the hsql jdbc driver is not exactly the same. This can = be worked around by - modifying the HSQLDB database driver settings. To modify the setti= ngs, click the Edit Driver Definition Driver( - - - - ) . - The proper Driver JAR File should be listed under Ja= r List. Select - the hsqldb.jar file found in the jbdevstudio/jboss-eap/jboss-as/co= mmon/lib/ directory and - click Ok. -
- Driver Details - - - - - -
- Now, the Test Connection should succeed. = After testing the - connection, click Ok. -
- Connection Testing - - - - - -
- You can leave the Code Generation section= as is. It refers to Java - packages in which the generated code will be placed. -
- Code Generation Setting - - - - - -
- Click on Finish button. Now, there should= be a new Seam project - called =E2=80=9Cworkshop=E2=80=9D listed in Package Explorer view.= -
- "worskhop" Project in the Package Explorer - - - - - -
-
-
- Start JBoss Application Server - The complete information on how to manage JBoss AS from JBoss = Developer Studio you can - read in a corresponding chapter. - Now you just need to start the server by clicking on the Start= the server icon ( - - - - - ) in the Servers. - Then run the project by selecting the project and use Run As... > - Run on Server. - - Note: - If the project does not show up, then you can use a normal b= rowser and use - http://localhost:8080/workshop/home.seam - as the url. - - Your project looks like this: -
- "workshop" Project Started - - - - - -
-
-
- Workshop Project Code Overview - Now let's examine the project and its structure. Go back to th= e Package Explorer view in - JBoss Developer Studio. - It seems like it's not much for project but this shell ap= plication contains a login - screen with default login logic, a menu template that can be furth= er modified, and other - layout templates. - It's important to note that the business logic will resid= e in the - src/hot - folder, by default. And, the package naming convention= s that were used in - New Seam project wizard could have been cha= nged to something - different from - org.domain.workshop.session. Al= so, notice that there is a - default Authenticator. java file. This is whe= re custom security logic - can be added. Seam has a nice declarative security model that we w= ill explore in a bit more - detail later on. The - src/main - folder is a model directory. It stores the project&apo= s;s JPA entity - beans. -
- Project Structure - - - - - -
- The view tier of the application is also important. Seam uses = facelets and there is a - built-in facelets GUI editor that has some nice WYSIWYG and compon= ent drag/drop - functionality. Try this out by opening home.xhtml from WebContent folder. -
- Facelets GUI Editor - - - - - -
- Notice that the templates reside in the - WebContent/layout - folder. There is a stylesheet in the - WebContent/stylesheet - folder. There is also a login and default error page. = The Facelet editor will be - explored in more detail later in the lab. - The project already has a datasource that was created per the = Seam project wizard - database settings. And, obviously all of the Seam specific configu= ration files and JAR - dependencies are included and placed in the proper locations. On l= ast noteworthy line item - is related to the build script. There isn=E2=80=99t a build script= because the Eclipse WTP(Web Tools - Project) plugin is used to publish web application changes. As you= can see, JBoss Developer - Studio is removing a great deal of complexity from the enterprise = Java project - setup/deployment process. The end result is a developer that is wr= iting code, not spending - days/weeks trying to figure out how to get a decent development en= vironment and project - build process. -
-
-
- Seam Action Development - Now, it=E2=80=99s time to write some code. The good news is that= JBoss Developer Studio can also - help out in this respect. In this section, we will create a new Seam= Action POJO and facelet - with some custom business logic and some GUI changes. -
- Create a New Seam Action - Go to main menu bar and click on - File > New > New Seam Action - to start the New Seam Action wizard. - Specify a Seam component name (e.g., &quo= t;myAction"). The - other properties will be auto-completed for you so there is no nee= d to change them. Click on - Finish. -
- New Seam Action Wizard - - - - - -
- Now, open the MyAction.java file and repl= ace the - "myAction" method with this logic: - - You also need to import the java.util.Calendar class by clicking - CTRL + Shift + O. -
-
- Test Seam Action - The new action can be tested by browsing the workshop-test pro= ject. JBoss Developer - Studio has already created a TestNG test case for you. -
- "workshop-test" Project - - - - - -
- The test case simulates a Seam component/method execution for = the MyAction.myAction() logic. - To run the test case, right click on MyActionTest.xm= l and click - - Run As > TestNG Suite - or use the Run As... toolbar shor= tcut as shown - below. -
- TestNG Running - - - - - -
- With any luck, the test case will pass. Look at the TestNG vie= w. -
- TestNG Results - - - - - -
- Now, it=E2=80=99s safe to test the new Seam Action in a web br= owser. The fastest way to do that - is to right click on myAction.xhtml and use <= emphasis> - Run As... > Run On Server - which will show the appropriate url in the browser. Al= ternatively you can - manually enter - http://localhost:8080/workshop/myAction.seam - into a browser. -
- Seam Action in a Web Browser - - - - - -
-
-
- Modify Seam Action User Interface - Browse to - http://localhost:8080/workshop/myAction.seam - and click on myAction. This execu= tes the =E2=80=9CmyAction=E2=80=9D method. - This looks pretty good, but we could make this page look a little = better. - Open - WebContent/myAction.xhtml - in JBoss Developer Studio to use the nice facelets edi= tor. -
- Open Seam Action with Editor - - - - - -
- Right click on the "myAction!" button in the visual = part of editor and select - <h:commandButton> Attributes. -
- Seam Action Editing - - - - - -
- Change the value of the button to somethi= ng different. If desired, - you can change any other text on the page. Then, type - CTRL + S - to save the facelet. -
- Attributes Dialog - - - - - -
- Refresh - http://localhost:8080/workshop/myAction.seam - and now you should see your changes. - Notice that you did not have to publish the application. JBoss= Developer Studio - auto-published it for you. -
- Seam Action Is Modified - - - - - -
-
-
-
- Declarative Security - In this section you will see how it=E2=80=99s easy to secure the= facelets and facelet components - in Seam. Let=E2=80=99s go ahead and secure the action button, then w= e will secure the entire - page. -
- Edit Login Authentication Logic - There is a class called Authenticator.java. The login page will - execute the Authenticator.authenticate() meth= od by default, so we=E2=80=99ll - start by adding some custom login logic. - Open Authenticator.java in JBoss Develope= r Studio and replace the - authenticate() method with this code: - -
-
- Secure Seam Page Component - Open myAction.xhtml and add a new secured= command button: - ]]> - Refresh - http://localhost:8080/workshop/myAction.seam - If you are not logged in you will only see one button.= If you are logged in, - there will be two buttons. -
- One Button on a Page - - - - - -
- The secured button is not visible because the user isn=E2=80= =99t logged in as "admin". -
- Secured Button is Visible - - - - - -
- The user is logged in as "admin". Securing components is - easy but securing pages is pretty simple as well. - Open - WebContent/WEB-INF/pages.xml - . Then add this markup directly underneath the <page= s> element: - ]]> - Refresh - http://localhost:8080/workshop/myAction.seam - If you are not logged in you will get bounced back to = the login page. -
- Login Page - - - - - -
- Thus, if you enter login credentials for the "a= dmin" - user, you will be re-directed to the secured page and secured comp= onent. If you enter - different login credentials, page access will be granted, but the = secured component will not - be displayed. - Congratulations! You have secured your new action both at the = facelet component and page - level. You also added custom authentication logic to the login act= ion. -
-
-
- Browsing Workshop Database - In this section you get to know how to use the workshop database= that was started at the - beginning of the lab. -
- Database Connectivity Setup - The workshop data can be browsed inside of JBoss Developer Stu= dio. - To open the Data Source Explorer, click on Window > Open Perspective - > Other > Database Development. - In the Data Source Explorer, expand a Databases node and select a - Default database. Right click on it, select= Connect from the context menu. -
- Data Source Explorer - - - - - -
-
-
- Browse Workshop Database - Then in the current view, drill down to the CUSTOMER= S table. -
- "CUSTOMERS" Table - - - - - -
- Right click on CUSTOMERS, select - Data > Sample Contents - to view the data in the table. - There should be a SQL Results view on the workbench, but it co= uld be hidden. Click on - the "Result1" tab in the right side= and you should see the - data in the CUSTOMERS table. -
- SQL Results View - - - - - -
- - Note: - If you can=E2=80=99t find the SQL Results view tab, click on= Window > Show - View > Other > SQL Development > SQL Results. - - Congratulations! You just connected to the workshop database a= nd queried the content - using Database Explorer tools. -
-
-
- Database Programming - Now, it=E2=80=99s time to reverse engineer the workshop database= into a fully functioning Seam - CRUD(Create Read Update Delete) application. -
- Reverse Engineer CRUD from a Running Database - In JBoss Developer Studio, switch to Seam - perspective, and then right-click the project and sel= ect New > Seam Generate Entities. - "workshop" project in the Seam Generate En= tities wizard - will be selected automatically. There is no need to change somethi= ng more, click - Next - to proceed further. -
- Generate Seam Entities - - - - - -
- On the next page use the - Include - button to include all the tables from the database and= click - Finish. -
- Selecting Tables - - - - - -
- After running the Generate Entities action, you will see new <= emphasis> - org.domain.workshop.entity - classes. These classes represent insert/update/delete/= query logic. -
- org.domain.workshop.entity Classes - - - - - -
- There are also - org.domain.workshop.entity - package that contains the JPA classes. These are the e= ntity beans that are - mapped to database tables.Note,that you can use Seam refactoring t= ools with Seam components. - Read more about it in Seam refactoring tools chapter of Seam Dev Tools Refere= nce Guide. - Last, but not least, there are facelets for all of the CRUD sc= reens. The best way to get - a feel for the generated code is to open a browser and play around= with the application. Go - to - http://localhost:8080/workshop - and insert/update/delete/query a few records. There is= quite a bit of AJAX in - this application, but which we will explore further later on in th= e lab. For now, take note - of the page tabs, required field logic and data table sorting in t= he list pages. -
- CustomersList.xhtml in the Editor - - - - - -
- Congratulations! You now have a fully functioning CRUD applica= tion that is already AJAX - enabled. -
-
- Use Hibernate Tools to Query Data via JPA - Now, it's time to write some JPA queries using the Hibern= ate perspective in - JBoss Developer Studio. - In the upper right corner of the workbench there is a small ic= on (see the figure below), - click on it and choose Hibernate. -
- Hibernate Perspective - - - - - -
- Look at the Hibernate Configurations view. In the "worksh= op" project, drill - down on the Session Factory and notice that t= he JPA entities/attributes - are listed in a nice tree view. -
- Hibernate Configurations View - - - - - -
- Right click on the Session Factory and se= lect HQL - Editor. This will open a JPA query scratch pad window= . - Write your query and click on the "Hibernate Dynamic SQL = Preview" tab. You - should see the SQL that will be executed if this JPA query is run.= -
- JPA Query Editor - - - - - -
- Run the query by clicking on the green run icon. - The results are listed in the "Hibernate Query Result&quo= t; tab. There is a - "Properties" tab in the workbench that can be used to se= e a specific JPA result. - These results represent the JPA objects because our query did not = specify column - names. -
- Hibernate Query Result View - - - - - -
- The query can be refined, and take note that there is nice cod= e completion in the JPA - query editor. -
- Code Completion - - - - - -
- A refined query will return results that are more ResultSet or= iented. Notice the join - logic that JPA supports. -
- The Hibernate Query Result - - - - - -
- There was no need to specify an Employees= table in the from part of the JPA query because JPA supports refe= rence traversal via Java - class attribute references. Not only are JPA and HQL queries fully= supported, but Criteria - based queries can also be written in the Criteria Editor. You shou= ld spend some time - tinkering with different queries and possibly Criteria based queri= es, even though the - instructions are not provided in this lab. -
- Criteria Editor - - - - - -
-
-
- Use Hibernate Tools to visualize the Data Model - Now, it=E2=80=99s time to view the data model for the workshop= database. - In the Hibernate Configurations view, select "workshop&qu= ot; project and expand the - Configuration node. Select the Cu= stomers entity, - right click on it, choose Open Mapping Diagram. -
- Mapping Diagram Opening - - - - - -
- You see a Diagram tab for the CUSTOMERS table and any tables t= hat have FK references. - This is a handy way to view the data model and JPA mappings. Now, = you=E2=80=99ve got access to - something that the Erwin Data Modeler can=E2=80=99t do. -
- Diagram Tab - - - - - -
-
-
-
- Rich Components - This lab will conclude with one last AJAX twist. In this section= we add a RichFaces - inputNumberSlider to the Order Details edit s= creen. -
- Add a Richfaces component to the CRUD Application - Switch to Seam perspective, open - WebContent/OrderdetailsEdit.xhtml - in JBoss Developer Studio. - Change the form field values using the visual editor. Seam has= generated the form field - names that match the database column names. This is not ideal for = business users. -
- Form Fields Editing - - - - - -
- Also, replace the QTY Ordered input field with a inp= utNumberSlider. - You can use the JBoss Developer Studio palette or right click on t= he form and insert the - RichFaces component. -
- Insert RichFaces Component from Context Menu - - - - - -
- One the last option is to use the source view and manually cop= y the inputNumberSlider - markup listed below: - ]]> -
- Manually coping Source Code - - - - - -
- The end result is an edit page that has better form labels and= a new RichFaces - control. -
- The Result Page - - - - - -
- Congratulations! You have completed the JBoss Developer Studio= lab. -
-
-
+ + + + + + JBoss Developer Studio + Seam + JBoss + + + Write Your First Project with JBoss Developer Studio + This chapter is a set of hands-on labs. You get step-by-step infor= mation about how the JBoss + Developer Studio can be used during the development process. +
+ Create a Seam Application + In this section you get to know how to create a Seam project in = JBDS, how to start the + server and what a structure your project has after creating. +
+ Start Development Database + Before opening the JBoss Developer studio you need to download= and start W= orkshop Database + . + To start the database just run ./runDBServer.sh or runDBServer.bat from the database directory. + The end result should be a console window that looks like: +
+ Starting DataBase + + + + + +
+
+
+ Create and deploy Seam Web Project + Minimize the terminal window and run the JBoss Devel= oper Studio + from Applications Menu or from the desktop icon. + First of all you get the Workspace Launcher. Change the defaul= t workspace location if + it's needed. Click on Ok. +
+ Workspace Launcher Dialog + + + + + +
+ After startup, you see the welcome page. You could read how to= work with welcome pages + in previous chapter. Now select <= property>Create + New... icon and then press on Create Seam P= roject + link. + The New Seam Project wizard is started. Y= ou need to enter a name + (e.g., "workshop") and a location directory for your new= project. The wizard has + an option for selecting the actual Server (and not just WTP runtim= e) that will be used for + the project. This allows the wizard to correctly identify where th= e needed datasource and + driver libraries need to go. +
+ New Seam Project Wizard + + + + + +
+ All settings are already specified here, you can just modify t= he Configuration. Click on + the + Modify... + button to configure your custom facets pattern: +
+ Project Facets Specifying + + + + + +
+ On the whole the dialog allows to select the "features" you wa= nt to use in your project. + Doing this JBoss Developer Studio setups the = appropriate tooling for + your project. Since JBoss Seam integrates all popular Java EE fram= eworks, you can select any + combination of technologies from the list. Here, for the default c= onfiguration, Dynamic Web + Module, Java, JavaServer Faces (JSF), and Seam Facet are already s= elected for a typical + database-driven web application. The default project facets should= suffice. + In the Project Facets form you can also b= ring up server runtimes + panel by clicking Runtimes tab on the right = corner. This panel shows + available server runtimes. +
+ Runtimes Selecting + + + + + +
+ Click on + Ok + and then + Next + to proceed further. + A dynamic web application contains both web pages and Java code. + The next wizard will ask you where you want to store Java files. +
+ Java Build Path + + + + + +
+ Following page provides you Web Module Settings .You can just leave + the default values or choose another folder. +
+ Web Module Settings + + + + + +
+ On the next form, you will be able to select where those libra= ry JARs come from. The + easiest is just to select the JARs provided by the JBoss AS runtim= e associated with this + project. That is why it is important to chose the right JBoss AS 4= .2 runtime in the project + setup window. + + + Select + Library Provided by Target Runtime + as Type of JSF Impl= ementation + Library. We will use the JSF implementation that = comes with JBoss + server. + + + Click + Next + + + +
+ JSF Capabilities Adding + + + + + +
+ Next wizard step needs more settings that previous. Let's star= t with General section. + Leave the default Seam runtime and check a WAR deployment. +
+ Seam Facet Setting + + + + + +
+ Next Database section is a little tricky.= The Connection + Profile needs to be edited so that the new project wo= rks properly with the + external HSQLDB server. By default the project wizard tries to use= the JBoss embedded + HSQLDB, but the tutorial uses an external database to replicate a = more real world + development scenario. Click on Edit to modify= the Connection + Profile. +
+ DataBase Setting + + + + + +
+ Select HSQLDB Profile Properties. Make su= re the Database location + is set to + hsql://localhost:1701 + +
+ JDBC Connection Properties + + + + + +
+ Try click on Test Connection button. It p= robably won=E2=80=99t work. This + happens if the hsql jdbc driver is not exactly the same. This can = be worked around by + modifying the HSQLDB database driver settings. To modify the setti= ngs, click the Edit Driver Definition Driver( + + + + ) . + The proper Driver JAR File should be listed under Ja= r List. Select + the hsqldb.jar file found in the jbdevstudio/jboss-eap/jboss-as/co= mmon/lib/ directory and + click Ok. +
+ Driver Details + + + + + +
+ Now, the Test Connection should succeed. = After testing the + connection, click Ok. +
+ Connection Testing + + + + + +
+ You can leave the Code Generation section= as is. It refers to Java + packages in which the generated code will be placed. + = +
+ Code Generation Setting + + + + + +
+ + + Tip: + If you want to name your web project "MyProject-war" note th= at the Test project name should not be "MyProject-war-test", = + it should be "MyProject-test". + + = + Click on Finish button. Now, there should= be a new Seam project + called =E2=80=9Cworkshop=E2=80=9D listed in Package Explorer view.= +
+ "worskhop" Project in the Package Explorer + + + + + +
+
+
+ Start JBoss Application Server + The complete information on how to manage JBoss AS from JBoss = Developer Studio you can + read in a corresponding chapter. + Now you just need to start the server by clicking on the Start= the server icon ( + + + + + ) in the Servers. + Then run the project by selecting the project and use Run As... > + Run on Server. + + Note: + If the project does not show up, then you can use a normal b= rowser and use + http://localhost:8080/workshop/home.seam + as the url. + + Your project looks like this: +
+ "workshop" Project Started + + + + + +
+
+
+ Workshop Project Code Overview + Now let's examine the project and its structure. Go back to th= e Package Explorer view in + JBoss Developer Studio. + It seems like it's not much for project but this shell ap= plication contains a login + screen with default login logic, a menu template that can be furth= er modified, and other + layout templates. + It's important to note that the business logic will resid= e in the + src/hot + folder, by default. And, the package naming convention= s that were used in + New Seam project wizard could have been cha= nged to something + different from + org.domain.workshop.session. Al= so, notice that there is a + default Authenticator. java file. This is whe= re custom security logic + can be added. Seam has a nice declarative security model that we w= ill explore in a bit more + detail later on. The + src/main + folder is a model directory. It stores the project&apo= s;s JPA entity + beans. +
+ Project Structure + + + + + +
+ The view tier of the application is also important. Seam uses = facelets and there is a + built-in facelets GUI editor that has some nice WYSIWYG and compon= ent drag/drop + functionality. Try this out by opening home.xhtml from WebContent folder. +
+ Facelets GUI Editor + + + + + +
+ Notice that the templates reside in the + WebContent/layout + folder. There is a stylesheet in the + WebContent/stylesheet + folder. There is also a login and default error page. = The Facelet editor will be + explored in more detail later in the lab. + The project already has a datasource that was created per the = Seam project wizard + database settings. And, obviously all of the Seam specific configu= ration files and JAR + dependencies are included and placed in the proper locations. On l= ast noteworthy line item + is related to the build script. There isn=E2=80=99t a build script= because the Eclipse WTP(Web Tools + Project) plugin is used to publish web application changes. As you= can see, JBoss Developer + Studio is removing a great deal of complexity from the enterprise = Java project + setup/deployment process. The end result is a developer that is wr= iting code, not spending + days/weeks trying to figure out how to get a decent development en= vironment and project + build process. +
+
+
+ Seam Action Development + Now, it=E2=80=99s time to write some code. The good news is that= JBoss Developer Studio can also + help out in this respect. In this section, we will create a new Seam= Action POJO and facelet + with some custom business logic and some GUI changes. +
+ Create a New Seam Action + Go to main menu bar and click on + File > New > New Seam Action + to start the New Seam Action wizard. + Specify a Seam component name (e.g., &quo= t;myAction"). The + other properties will be auto-completed for you so there is no nee= d to change them. Click on + Finish. +
+ New Seam Action Wizard + + + + + +
+ Now, open the MyAction.java file and repl= ace the + "myAction" method with this logic: + + You also need to import the java.util.Calendar class by clicking + CTRL + Shift + O. +
+
+ Test Seam Action + The new action can be tested by browsing the workshop-test pro= ject. JBoss Developer + Studio has already created a TestNG test case for you. +
+ "workshop-test" Project + + + + + +
+ The test case simulates a Seam component/method execution for = the MyAction.myAction() logic. + To run the test case, right click on MyActionTest.xm= l and click + + Run As > TestNG Suite + or use the Run As... toolbar shor= tcut as shown + below. +
+ TestNG Running + + + + + +
+ With any luck, the test case will pass. Look at the TestNG vie= w. +
+ TestNG Results + + + + + +
+ Now, it=E2=80=99s safe to test the new Seam Action in a web br= owser. The fastest way to do that + is to right click on myAction.xhtml and use <= emphasis> + Run As... > Run On Server + which will show the appropriate url in the browser. Al= ternatively you can + manually enter + http://localhost:8080/workshop/myAction.seam + into a browser. +
+ Seam Action in a Web Browser + + + + + +
+
+
+ Modify Seam Action User Interface + Browse to + http://localhost:8080/workshop/myAction.seam + and click on myAction. This execu= tes the =E2=80=9CmyAction=E2=80=9D method. + This looks pretty good, but we could make this page look a little = better. + Open + WebContent/myAction.xhtml + in JBoss Developer Studio to use the nice facelets edi= tor. +
+ Open Seam Action with Editor + + + + + +
+ Right click on the "myAction!" button in the visual = part of editor and select + <h:commandButton> Attributes. +
+ Seam Action Editing + + + + + +
+ Change the value of the button to somethi= ng different. If desired, + you can change any other text on the page. Then, type + CTRL + S + to save the facelet. +
+ Attributes Dialog + + + + + +
+ Refresh + http://localhost:8080/workshop/myAction.seam + and now you should see your changes. + Notice that you did not have to publish the application. JBoss= Developer Studio + auto-published it for you. +
+ Seam Action Is Modified + + + + + +
+
+
+
+ Declarative Security + In this section you will see how it=E2=80=99s easy to secure the= facelets and facelet components + in Seam. Let=E2=80=99s go ahead and secure the action button, then w= e will secure the entire + page. +
+ Edit Login Authentication Logic + There is a class called Authenticator.java. The login page will + execute the Authenticator.authenticate() meth= od by default, so we=E2=80=99ll + start by adding some custom login logic. + Open Authenticator.java in JBoss Develope= r Studio and replace the + authenticate() method with this code: + +
+
+ Secure Seam Page Component + Open myAction.xhtml and add a new secured= command button: + ]]> + Refresh + http://localhost:8080/workshop/myAction.seam + If you are not logged in you will only see one button.= If you are logged in, + there will be two buttons. +
+ One Button on a Page + + + + + +
+ The secured button is not visible because the user isn=E2=80= =99t logged in as "admin". +
+ Secured Button is Visible + + + + + +
+ The user is logged in as "admin". Securing components is + easy but securing pages is pretty simple as well. + Open + WebContent/WEB-INF/pages.xml + . Then add this markup directly underneath the <page= s> element: + ]]> + Refresh + http://localhost:8080/workshop/myAction.seam + If you are not logged in you will get bounced back to = the login page. +
+ Login Page + + + + + +
+ Thus, if you enter login credentials for the "a= dmin" + user, you will be re-directed to the secured page and secured comp= onent. If you enter + different login credentials, page access will be granted, but the = secured component will not + be displayed. + Congratulations! You have secured your new action both at the = facelet component and page + level. You also added custom authentication logic to the login act= ion. +
+
+
+ Browsing Workshop Database + In this section you get to know how to use the workshop database= that was started at the + beginning of the lab. +
+ Database Connectivity Setup + The workshop data can be browsed inside of JBoss Developer Stu= dio. + To open the Data Source Explorer, click on Window > Open Perspective + > Other > Database Development. + In the Data Source Explorer, expand a Databases node and select a + Default database. Right click on it, select= Connect from the context menu. +
+ Data Source Explorer + + + + + +
+
+
+ Browse Workshop Database + Then in the current view, drill down to the CUSTOMER= S table. +
+ "CUSTOMERS" Table + + + + + +
+ Right click on CUSTOMERS, select + Data > Sample Contents + to view the data in the table. + There should be a SQL Results view on the workbench, but it co= uld be hidden. Click on + the "Result1" tab in the right side= and you should see the + data in the CUSTOMERS table. +
+ SQL Results View + + + + + +
+ + Note: + If you can=E2=80=99t find the SQL Results view tab, click on= Window > Show + View > Other > SQL Development > SQL Results. + + Congratulations! You just connected to the workshop database a= nd queried the content + using Database Explorer tools. +
+
+
+ Database Programming + Now, it=E2=80=99s time to reverse engineer the workshop database= into a fully functioning Seam + CRUD(Create Read Update Delete) application. +
+ Reverse Engineer CRUD from a Running Database + In JBoss Developer Studio, switch to Seam + perspective, and then right-click the project and sel= ect New > Seam Generate Entities. + "workshop" project in the Seam Generate En= tities wizard + will be selected automatically. There is no need to change somethi= ng more, click + Next + to proceed further. +
+ Generate Seam Entities + + + + + +
+ On the next page use the + Include + button to include all the tables from the database and= click + Finish. +
+ Selecting Tables + + + + + +
+ After running the Generate Entities action, you will see new <= emphasis> + org.domain.workshop.entity + classes. These classes represent insert/update/delete/= query logic. +
+ org.domain.workshop.entity Classes + + + + + +
+ There are also + org.domain.workshop.entity + package that contains the JPA classes. These are the e= ntity beans that are + mapped to database tables.Note,that you can use Seam refactoring t= ools with Seam components. + Read more about it in Seam refactoring tools chapter of Seam Dev Tools Refere= nce Guide. + Last, but not least, there are facelets for all of the CRUD sc= reens. The best way to get + a feel for the generated code is to open a browser and play around= with the application. Go + to + http://localhost:8080/workshop + and insert/update/delete/query a few records. There is= quite a bit of AJAX in + this application, but which we will explore further later on in th= e lab. For now, take note + of the page tabs, required field logic and data table sorting in t= he list pages. +
+ CustomersList.xhtml in the Editor + + + + + +
+ Congratulations! You now have a fully functioning CRUD applica= tion that is already AJAX + enabled. +
+
+ Use Hibernate Tools to Query Data via JPA + Now, it's time to write some JPA queries using the Hibern= ate perspective in + JBoss Developer Studio. + In the upper right corner of the workbench there is a small ic= on (see the figure below), + click on it and choose Hibernate. +
+ Hibernate Perspective + + + + + +
+ Look at the Hibernate Configurations view. In the "worksh= op" project, drill + down on the Session Factory and notice that t= he JPA entities/attributes + are listed in a nice tree view. +
+ Hibernate Configurations View + + + + + +
+ Right click on the Session Factory and se= lect HQL + Editor. This will open a JPA query scratch pad window= . + Write your query and click on the "Hibernate Dynamic SQL = Preview" tab. You + should see the SQL that will be executed if this JPA query is run.= +
+ JPA Query Editor + + + + + +
+ Run the query by clicking on the green run icon. + The results are listed in the "Hibernate Query Result&quo= t; tab. There is a + "Properties" tab in the workbench that can be used to se= e a specific JPA result. + These results represent the JPA objects because our query did not = specify column + names. +
+ Hibernate Query Result View + + + + + +
+ The query can be refined, and take note that there is nice cod= e completion in the JPA + query editor. +
+ Code Completion + + + + + +
+ A refined query will return results that are more ResultSet or= iented. Notice the join + logic that JPA supports. +
+ The Hibernate Query Result + + + + + +
+ There was no need to specify an Employees= table in the from part of the JPA query because JPA supports refe= rence traversal via Java + class attribute references. Not only are JPA and HQL queries fully= supported, but Criteria + based queries can also be written in the Criteria Editor. You shou= ld spend some time + tinkering with different queries and possibly Criteria based queri= es, even though the + instructions are not provided in this lab. +
+ Criteria Editor + + + + + +
+
+
+ Use Hibernate Tools to visualize the Data Model + Now, it=E2=80=99s time to view the data model for the workshop= database. + In the Hibernate Configurations view, select "workshop&qu= ot; project and expand the + Configuration node. Select the Cu= stomers entity, + right click on it, choose Open Mapping Diagram. +
+ Mapping Diagram Opening + + + + + +
+ You see a Diagram tab for the CUSTOMERS table and any tables t= hat have FK references. + This is a handy way to view the data model and JPA mappings. Now, = you=E2=80=99ve got access to + something that the Erwin Data Modeler can=E2=80=99t do. +
+ Diagram Tab + + + + + +
+
+
+
+ Rich Components + This lab will conclude with one last AJAX twist. In this section= we add a RichFaces + inputNumberSlider to the Order Details edit s= creen. +
+ Add a Richfaces component to the CRUD Application + Switch to Seam perspective, open + WebContent/OrderdetailsEdit.xhtml + in JBoss Developer Studio. + Change the form field values using the visual editor. Seam has= generated the form field + names that match the database column names. This is not ideal for = business users. +
+ Form Fields Editing + + + + + +
+ Also, replace the QTY Ordered input field with a inp= utNumberSlider. + You can use the JBoss Developer Studio palette or right click on t= he form and insert the + RichFaces component. +
+ Insert RichFaces Component from Context Menu + + + + + +
+ One the last option is to use the source view and manually cop= y the inputNumberSlider + markup listed below: + ]]> +
+ Manually coping Source Code + + + + + +
+ The end result is an edit page that has better form labels and= a new RichFaces + control. +
+ The Result Page + + + + + +
+ Congratulations! You have completed the JBoss Developer Studio= lab. +
+
+
\ No newline at end of file Modified: trunk/documentation/guides/GettingStartedGuide/en-US/images/first= _seam/first_seam13.png =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) Modified: trunk/documentation/guides/GettingStartedGuide/en-US/images/first= _seam/first_seam3.png =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) Modified: trunk/documentation/guides/GettingStartedGuide/en-US/images/first= _seam/first_seam5.png =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) Modified: trunk/documentation/guides/GettingStartedGuide/en-US/images/first= _seam/first_seam8.png =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) --===============3851867685838367443==--