Sei sulla pagina 1di 7

ptg

Step 3: Switch to tab 1 and click on Book Hotel. The application books
the Marriott San Francisco hotel. This makes sense, but only Seam, with
its support for multiple workspaces, can do this easily.
Figure 9.3
@Entity
@Name("user")
@Scope(SESSION)
@Table(name="Customer")
public class User implements Serializable
{
... ...
In a Seam application, a workspace maps one-to-one to a conversation, so a Seam
application with multiple concurrent conversations has multiple workspaces. As we
discussed in Section 8.3.4, a user starts a new conversation via an explicit HTTP GET
request. Thus, when you open a link in a new browser tab or manually load a URL in
the current browser tab, you start a new workspace. Seam then provides you a method
for accessing the old workspace/conversation (see Section 9.2.1).
CHAPTER 9 WORKSPACES AND CONCURRENT CONVERSATIONS 128
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
A group of concurrent conversations with the same user, each uniquely
identiable by ID
Figure 9.4
The Back Button Works across Conversations and Workspaces
If you interrupt a conversation via an HTTP GET request (e.g., by manually loading the
main.xhtml page in the middle of a conversation), you can then go back to the interrupted
conversation. When you are backed to a page inside an interrupted conversation, you can
simply click on any button and resume the conversation as if it had never been interrupted.
As we discussed in Section 8.3.4, if the conversation has ended or timed out by the
time you try to return to it, Seam handles this gracefully by redirecting you to a
no-conversation-view-id page (see Section 9.2.2) which is congurable in your
pages.xml. This ensures that, regardless of back-buttoning, the users experience remains
consistent with the server-side state.
9.2 Workspace Management
Seam provides a number of built-in components and features that facilitate workspace
and concurrent conversation management. The following sections will explore the fea-
tures provided by Seam to help you manage workspaces in your applications.
Section 9.2.1 will discuss the workspace switcher which provides a simple way to allow
users to swap between workspaces. In Section 9.2.2, we will demonstrate how you can
129 9.2 WORKSPACE MANAGEMENT
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
maintain a workspace even across GET requests. Finally, Section 9.2.3 will discuss how
Seam allows the conversation ID to be manipulated.
9.2.1 Workspace Switcher
Seam maintains a list of concurrent conversations in the current user session in a com-
ponent named #{conversationList}. You can iterate through the list to see the de-
scriptions of the conversations, their start times, and their last access times. The
#{conversationList} component also provides a means of loading any conversation
in the current workspace (browser window or tab). Figure 9.5 shows an example list of
conversations in the Seam Hotel Booking example. Click on any description link to
load the selected conversation in the current window.
A list of concurrent conversations (workspaces) in the current user
session
Figure 9.5
CHAPTER 9 WORKSPACES AND CONCURRENT CONVERSATIONS 130
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
Below is the JSF page code behind the workspace switcher. It is in the
conversations.xhtml le in the example source code.
<h:dataTable value="#{conversationList}" var="entry">
<h:column>
<h:commandLink action="#{entry.select}"
value="#{entry.description}"/>
<h:outputText value="[current]"
rendered="#{entry.current}"/>
</h:column>
<h:column>
<h:outputText value="#{entry.startDatetime}">
<f:convertDateTime type="time" pattern="hh:mm"/>
</h:outputText>
-
<h:outputText value="#{entry.lastDatetime}">
<f:convertDateTime type="time" pattern="hh:mm"/>
</h:outputText>
</h:column>
</h:dataTable>
The #{entry} object iterates through conversations in the #{conversationList}
component. The #{entry.select} property is a built-in JSF action for loading the
conversation #{entry} in the current window. Similarly, the #{entry.destroy} JSF
action destroys that conversation. Whats interesting is the #{entry.description}
property, which contains a string description of the current page in the conversation.
How does Seam gure out the description of a page? That requires another XML le.
The WEB-INF/pages.xml le in the app.war archive le (it is the resources/
WEB-INF/pages.xml le in the source code bundle) species the page descriptions.
This pages.xml le can also be used to replace the WEB-INF/navigation.xml le for
jBPM-based pageow conguration (see Section 24.5 for more details). You can learn
more about pages.xml in Chapter 15. Here is a portion of the content of the pages.xml
le in the Natural Hotel Booking example:
<pages>
... ...
</page>
<page view-id="/book.xhtml" timeout="600000" ... >
<description>
Book hotel: #{hotel.name}
</description>
... ...
</page>
<page view-id="/confirm.xhtml" timeout="600000" ... >
<description>
Confirm: #{booking.description}
</description>
... ...
</page>
</pages>
131 9.2 WORKSPACE MANAGEMENT
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
We can reference Seam components by name in the pages.xml le which is very useful
for displaying the description of a conversation.
Why Is the Conversation List Empty or Missing an Entry?
A conversation is only placed into the #{conversationList} component if a page descrip-
tion has been provided. This is often a source of confusion for rst-time users, so if you
are unsure as to why your conversation is not appearing in the conversationList, check
your pages.xml conguration.
The conversation switcher shown in Figure 9.5 displays conversations in a table. Of
course, you can customize how the table looks. But what if you want a switcher in a
drop-down menu? The drop-down menu takes less space on a web page than a table,
especially if you have many workspaces. However, the #{conversationList} compo-
nent is a DataModel and cannot be used in a JSF menu, so Seam provides a special
conversation list to use in a drop-down menu, which has a structure similar to the
data table.
<h:selectOneMenu value="#{switcher.conversationIdOrOutcome}">
<f:selectItems value="#{switcher.selectItems}"/>
</h:selectOneMenu>
<h:commandButton action="#{switcher.select}"
value="Switch"/>
<h:commandButton action="#{switcher.destroy}"
value="Destroy"/>
9.2.2 Carrying a Conversation across Workspaces
As we discussed earlier, Seam creates a new workspace for each HTTP GET request.
By denition, the new workspace has its own fresh conversation. So, what if we want
to do an HTTP GET and still preserve the same conversation context? For instance, you
might want a pop-up browser window to share the same workspace/conversation as the
current main window. Thats where the Seam conversation ID comes into play.
If you look at the URLs of the Seam Hotel Booking example application, every page
URL has a cid URL parameter at the end. This cid stays constant within a conver-
sation. For instance, a URL could look like this: http://localhost:8080/booking/
hotel.seam?cid=10.
To GET a page without disrupting the current conversation, you can append the same
cid name/value pair to your HTTP GET URL.
Appending the cid value to an URL can be risky. What if you pass in a wrong value
for the cid parameter? Will the application just throw an error? As a protection, you
CHAPTER 9 WORKSPACES AND CONCURRENT CONVERSATIONS 132
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
This page intentionally left blank
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com






ptg
A key value proposition of Seam is the unication of EJB3 and JSF component models.
Through the unied components, we can use EJB3 entity beans to back data elds in
JSF forms, as well as use EJB3 session beans as JSF UI event handlers. But Seam does
much more than that. Seam enables us to develop data components that have UI-related
behaviors. For instance, entity beans can have validators that behave like JSF valida-
tors.
In this chapter, we cover the Seam-enhanced end-to-end validators that take advantage
of Hibernate validator annotations on entity beans as well as Seam UI tags (see
Section 3.2). We refactor the stateful Hello World example to show how to use this
Seam feature. The new application is in the integration directory in the source code
bundle. We use the Integration application in the next two chapters as well.
AJAX Validators
In this chapter, we cover only the standard method of validation via form submission.
In Part IV, we discuss how to create AJAX-based validators. Still, the Seam annotations
and tags discussed in this chapter are highly relevant for AJAX-based validators as well.
12.1 Form Validation Basics
Form data validation is a task that almost every web application must implement. For
example, the Integration application has four data elds on the hello.xhtml page, and
all of them need to be validated before the person object can be saved into the database.
12
Validating Input Data
177
From the Library of sam kaplan
Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com

Potrebbero piacerti anche