JBoss.orgCommunity Documentation

Chapter 2. Seam Action Development

2.1. Create a New Seam Action
2.2. Test Seam Action
2.3. Modify Seam Action User Interface

Now it’s 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.

Go to main menu bar and click on FileNewNew Seam Action to start the New Seam Action wizard.

Specify a Seam component name (e.g., "myAction"). The other properties will be auto-completed for you so there is no need to change them. Click on the Finish button.


Now, open the MyAction.java file and replace the "myAction" method with this logic:

							public void myAction() {
							Calendar cal = Calendar.getInstance();
							log.info("myAction.myAction() action called");
							statusMessages.add("MyAction Executed on:" + cal.getTime());
							}
						

You also need to import the java.util.Calendar class by clicking CTRL+Shift+O.

The new action can be tested by browsing the workshop-test project. JBoss Developer Studio has already created a TestNG test case for you.


Tip

You may have to refresh the project to see the new files.

The test case simulates a Seam method execution for the MyAction.myAction() logic.

To run the test case, right click on MyActionTest.xml and click Run AsTestNG Suite or use the Run As... toolbar shortcut as shown below.


With any luck, the test case will pass. Look at the TestNG view.


Now, it’s safe to test the new Seam Action in a web browser. The fastest way to do that is to right click on myAction.xhtml and use Run As...Run On Server which will show the appropriate URL in the browser. Alternatively you can manually enter http://localhost:8080/workshop/myAction.seam into a browser.


Browse to http://localhost:8080/workshop/myAction.seam and click on the myAction button. This executes the “myAction” 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 editor.


Right click on the "myAction!" button in the visual part of editor and select <h:commandButton> Attributes.


Change the value of the button to something different. If desired, you can change any other text on the page. Then, type CTRL+S to save the facelet.


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.