此内容没有您所选择的语言版本。
Chapter 31. Seam JSF controls
Seam includes a number of JavaServer Faces (JSF) controls to complement built-in controls, and controls from other third-party libraries. We recommend JBoss RichFaces and Apache MyFaces Trinidad tag libraries for use with Seam. We do not recommend the use of the Tomahawk tag library.
31.1. Tags 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To use these tags, define the
s
namespace in your page as follows (Facelets only):
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib">
The user interface example demonstrates the use of a number of these tags.
31.1.1. Navigation Controls 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.1.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A button that supports invoking an action with control over conversation propagation. This button does not submit the form.
Attributes
value
— the button label.action
— a method binding that specifies the action listener.view
— specifies the JSF view ID to link to.fragment
— specifies the fragment identifier to link to.disabled
— specifies whether the link is disabled.propagation
— determines the conversation propagation style:begin
,join
,nest
,none
orend
.pageflow
— specifies a pageflow definition to begin. (Effective only whenpropagation="begin"
orpropagation="join"
is used.)
Usage
<s:button id="cancel" value="Cancel" action="#{hotelBooking.cancel}"/>
<s:button id="cancel" value="Cancel" action="#{hotelBooking.cancel}"/>
You can specify both
view
and action
on <s:link />
. In this case, the action will be called once the redirect to the specified view has occurred.
The use of action listeners (including the default JSF action listener) is not supported with
<s:button />
.
31.1.1.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Adds the conversation ID to a JSF link or button, for example:
<h:commandLink />
, <s:button />
.
Attributes
None.
31.1.1.3. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Adds the task ID to an output link (or similar JSF control) when the task is available via
#{task}
.
Attributes
None.
31.1.1.4. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A link that supports invoking an action with control over conversation propagation. This does not submit the form.
The use of action listeners (including the default JSF action listener) is not supported with
<s:link />
.
Attributes
value
— specifies the link label.action
— a method binding that specifies the action listener.view
— specifies the JSF view ID to link to.fragment
— specifies the fragment identifier to link to.disabled
— specifies whether the link is disabled.propagation
— determines the conversation propagation style:begin
,join
,nest
,none
orend
.pageflow
— specifies a pageflow definition to begin. (Effective only when usingpropagation="begin"
orpropagation="join"
.)
Usage
<s:link id="register" view="/register.xhtml" value="Register New User"/>
<s:link id="register" view="/register.xhtml" value="Register New User"/>
You can specify both
view
and action
on <s:link />
. In this case, the action will be called once the redirect to the specified view has occurred.
31.1.1.5. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Customizes the conversation propagation for a command link or button (or similar JSF control). Facelets only.
Attributes
type
— determines the conversation propagation style:begin
,join
,nest
,none
orend
.pageflow
— specifies a pageflow definition to begin. (Effective only useful when usingpropagation="begin"
orpropagation="join"
.)
Usage
<h:commandButton value="Apply" action="#{personHome.update}"> <s:conversationPropagation type="join" /> </h:commandButton>
<h:commandButton value="Apply" action="#{personHome.update}">
<s:conversationPropagation type="join" />
</h:commandButton>
31.1.1.6. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Specifies the default action to run when the form is submitted using the enter key.
Currently you this can only be nested inside buttons, such as
<h:commandButton />
, <a:commandButton />
or <tr:commandButton />
).
You must specify an ID on the action source, and only one default action can be specified per form.
Attributes
None.
Usage
<h:commandButton id="foo" value="Foo" action="#{manager.foo}"> <s:defaultAction /> </h:commandButton>
<h:commandButton id="foo" value="Foo" action="#{manager.foo}">
<s:defaultAction />
</h:commandButton>
31.1.2. Converters and Validators 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.2.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Perform date or time conversions in the Seam timezone.
Attributes
None.
Usage
<h:outputText value="#{item.orderDate}"> <s:convertDateTime type="both" dateStyle="full"/> </h:outputText>
<h:outputText value="#{item.orderDate}">
<s:convertDateTime type="both" dateStyle="full"/>
</h:outputText>
31.1.2.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Assigns an entity converter to the current component. This is useful for radio button and dropdown controls.
The converter works with any managed entity - either simple or composite. If the converter cannot find the items declared in the JSF controls upon form submission, a validation error will occur.
Attributes
None.
Configuration
You must use Seam managed transactions (see Section 10.2, “Seam managed transactions”) with
<s:convertEntity />
.
Your Managed Persistence Context must be named
entityManager
— if it is not, you can change its named in components.xml
:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:jpa-entity-loader entity-manager="#{em}" />
<components xmlns="http://jboss.com/products/seam/components"
xmlns:ui="http://jboss.com/products/seam/ui">
<ui:jpa-entity-loader entity-manager="#{em}" />
If you are using a Managed Hibernate Session, you must also set this in
components.xml
:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:hibernate-entity-loader />
<components xmlns="http://jboss.com/products/seam/components"
xmlns:ui="http://jboss.com/products/seam/ui">
<ui:hibernate-entity-loader />
Your Managed Hibernate Session must be named
session
— if it is not, you can change its named in components.xml
:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:hibernate-entity-loader session="#{hibernateSession}" />
<components xmlns="http://jboss.com/products/seam/components"
xmlns:ui="http://jboss.com/products/seam/ui">
<ui:hibernate-entity-loader session="#{hibernateSession}" />
To use multiple entity managers with the entity converter, create a copy of the entity converter for each entity manager in
components.xml
. The entity converter delegates to the entity loader to perform persistence operations like so:
Usage
31.1.2.3. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Assigns an enum converter to the current component. This is primarily useful for radio button and dropdown controls.
Attributes
None.
Usage
31.1.2.4. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
javax.faces.convert.Converter
for java.util.concurrent.atomic.AtomicBoolean
.
Attributes
None.
Usage
<h:outputText value="#{item.valid}"> <s:convertAtomicBoolean /> </h:outputText>
<h:outputText value="#{item.valid}">
<s:convertAtomicBoolean />
</h:outputText>
31.1.2.5. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
javax.faces.convert.Converter
for java.util.concurrent.atomic.AtomicInteger
.
Attributes
None.
Usage
<h:outputText value="#{item.id}"> <s:convertAtomicInteger /> </h:outputText>
<h:outputText value="#{item.id}">
<s:convertAtomicInteger />
</h:outputText>
31.1.2.6. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
javax.faces.convert.Converter
for java.util.concurrent.atomic.AtomicLong
.
Attributes
None.
Usage
<h:outputText value="#{item.id}"> <s:convertAtomicLong /> </h:outputText>
<h:outputText value="#{item.id}">
<s:convertAtomicLong />
</h:outputText>
31.1.2.7. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Validates that an input control's parent's value is equal, or not equal, to the referenced control's value.
Attributes
for
— The ID of a control to validate against.message
— Message to show on failure.required
— False will disable a check that a value at all is inputted in fields.messageId
— Message ID to show on failure.operator
— The operator to use when comparing values. Valid operators are:equal
— validates thatvalue.equals(forValue)
.not_equal
— validates that!value.equals(forValue)
greater
— validates that ((Comparable)value).compareTo(forValue) > 0greater_or_equal
— validates that ((Comparable)value).compareTo(forValue) >= 0less
— validates that ((Comparable)value).compareTo(forValue) < 0less_or_equal
— validates that ((Comparable)value).compareTo(forValue) <= 0
Usage
<h:inputText id="name" value="#{bean.name}"/> <h:inputText id="nameVerification" > <s:validateEquality for="name" /> </h:inputText>
<h:inputText id="name" value="#{bean.name}"/>
<h:inputText id="nameVerification" >
<s:validateEquality for="name" />
</h:inputText>
31.1.2.8. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A non-visual control that validates a JSF input field against the bound property with the Hibernate Validator.
Attributes
None.
Usage
<h:inputText id="userName" required="true" value="#{customer.userName}"> <s:validate /> </h:inputText> <h:message for="userName" styleClass="error" />
<h:inputText id="userName" required="true" value="#{customer.userName}">
<s:validate />
</h:inputText>
<h:message for="userName" styleClass="error" />
31.1.2.9. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A non-visual control that validates all child JSF input fields against their bound properties with the Hibernate Validator.
Attributes
None.
Usage
31.1.3. Formatting 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.3.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
"Decorates" a JSF input field when validation fails or when
required="true"
is set.
Attributes
template
— the Facelets template used to decorate the component.enclose
— iftrue
, the template used to decorate the input field is enclosed by the element specified with the "element" attribute. (By default, this is adiv
element.)element
— the element enclosing the template that decorates the input field. By default, the template is enclosed with adiv
element.
#{invalid}
and #{required}
are available inside s:decorate
. #{required}
evaluates to true
if the input component being decorated is set to required
. #{invalid}
evaluates to true
if a validation error occurs.
Usage
<s:decorate template="edit.xhtml"> <ui:define name="label">Country:</ui:define> <h:inputText value="#{location.country}" required="true"/> </s:decorate>
<s:decorate template="edit.xhtml">
<ui:define name="label">Country:</ui:define>
<h:inputText value="#{location.country}" required="true"/>
</s:decorate>
31.1.3.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Renders a HTML
<div>
.
Attributes
None.
Usage
<s:div rendered="#{selectedMember == null}"> Sorry, but this member does not exist. </s:div>
<s:div rendered="#{selectedMember == null}">
Sorry, but this member does not exist.
</s:div>
31.1.3.3. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Renders a HTML
<span>
.
Attributes
title
— Title for a span.
Usage
<s:span styleClass="required" rendered="#{required}" title="Small tooltip"> * </s:span>
<s:span styleClass="required" rendered="#{required}" title="Small tooltip">
*
</s:span>
31.1.3.4. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A non-rendering component useful for enabling/disabling rendering of it's children.
Attributes
None.
Usage
<s:fragment rendered="#{auction.highBidder ne null}"> Current bid: </s:fragment>
<s:fragment rendered="#{auction.highBidder ne null}">
Current bid:
</s:fragment>
31.1.3.5. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
"Decorates" a JSF input field with the label. The label is placed inside the HTML
<label>
tag, and is associated with the nearest JSF input component. It is often used with <s:decorate>
.
Attributes
style
— The control's style.styleClass
— The control's style class.
Usage
<s:label styleClass="label"> Country: </s:label> <h:inputText value="#{location.country}" required="true"/>
<s:label styleClass="label"> Country: </s:label>
<h:inputText value="#{location.country}" required="true"/>
31.1.3.6. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
"Decorates" a JSF input field with the validation error message.
Attributes
None.
Usage
31.1.4. Seam Text 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.4.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Checks that the submitted value is valid Seam Text.
Attributes
None.
31.1.4.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Outputs Seam Text, a rich text markup useful for blogs, wikis and other applications that might use rich text. See the Seam Text chapter for full usage.
Attributes
value
— an EL expression specifying the rich text markup to render.
Usage
<s:formattedText value="#{blog.text}"/>
<s:formattedText value="#{blog.text}"/>
Example
31.1.5. Form support 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.5.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Produces a random token to insert into a hidden form field in order to secure JSF form posts against Cross-Site Request Forgery (XSRF) attacks. The browser must have cookies enabled to submit forms that include this component.
Attributes
requireSession
— indicates whether the session ID should be included in the form signature to bind the token to the session. The default value isfalse
, but this should only be used if Facelets is in "build before restore" mode. ("Build before restore" is the default mode in JSF 2.0.)enableCookieNotice
— indicates that a JavaScript check should be inserted into the page to verify that cookies are enabled in the browser. If cookies are not enabled, present a notice to the user that form posts will not work. The default value isfalse
.allowMultiplePosts
— indicates whether the same form is allowed to submit multiple times with the same signature (where the view has not changed). This is often required when the form is performing AJAX calls without rerendering itself or the UIToken component. It is better to rerender the UIToken component upon any AJAX call where the UIToken component would be processed. The default value isfalse
.
Usage
<h:form> <s:token enableCookieNotice="true" requireSession="false"/> ... </h:form>
<h:form>
<s:token enableCookieNotice="true" requireSession="false"/>
...
</h:form>
31.1.5.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Creates a
SelectItem
from an enum value.
Attributes
enumValue
— the string representation of the enum value.label
— the label to be used when rendering theSelectItem
.
Usage
31.1.5.3. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Creates a
List<SelectItem>
from a List, Set, DataModel or Array.
Attributes
value
— an EL expression specifying the data that backs theListSelectItem>
var
— defines the name of the local variable that holds the current object during iteration.label
— the label to be used when rendering theSelectItem
. Can reference thevar
variable.itemValue
— specifies the value to return to the server if this option is selected. This is an optional attribute. If included,var
is the default object used. Can reference thevar
variable.disabled
— if this is set totrue
, theSelectItem
will be rendered disabled. Can reference thevar
variable.noSelectionLabel
— specifies the (optional) label to place at the top of list. Ifrequired="true"
is also specified then selecting this value will cause a validation error.hideNoSelectionLabel
— if true, thenoSelectionLabel
will be hidden when a value is selected.
Usage
<h:selectOneMenu value="#{person.age}" converter="ageConverter"> <s:selectItems value="#{ages}" var="age" label="#{age}" /> </h:selectOneMenu>
<h:selectOneMenu value="#{person.age}" converter="ageConverter">
<s:selectItems value="#{ages}" var="age" label="#{age}" />
</h:selectOneMenu>
31.1.5.4. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Renders a file upload control. This control must be used within a form with an encoding type of
multipart/form-data
:
<h:form enctype="multipart/form-data">
<h:form enctype="multipart/form-data">
For multipart requests, the Seam Multipart servlet filter must also be configured in
web.xml
:
Configuration
The following configuration options for multipart requests can be configured in
components.xml
:
createTempFiles
— if this option is set totrue
, uploaded files are streamed to a temporary file rather than being held in memory.maxRequestSize
— the maximum size of a file upload request, in bytes.
Here's an example:
<component class="org.jboss.seam.web.MultipartFilter"> <property name="createTempFiles">true</property> <property name="maxRequestSize">1000000</property> </component>
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles">true</property>
<property name="maxRequestSize">1000000</property>
</component>
Attributes
data
— specifies the value binding that receives the binary file data. The receiving field must be declared as either abyte[]
orInputStream
.contentType
— an optional attribute specifying the value binding that receives the file's content type.fileName
— an optional attribute specifying the value binding that receives the filename.fileSize
— an optional attribute specifying the value binding that receives the file size.accept
— a comma-separated list of acceptable content types, for example,"images/png,images/jpg"
,"images/*"
. The types listed may not be supported by the browser.style
— The control's style.styleClass
— The control's style class.
Usage
<s:fileUpload id="picture" data="#{register.picture}" accept="image/png" contentType="#{register.pictureContentType}" />
<s:fileUpload id="picture"
data="#{register.picture}" accept="image/png"
contentType="#{register.pictureContentType}" />
31.1.6. Other 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
31.1.6.1. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Caches the rendered page fragment using JBoss Cache. Note that
<s:cache>
actually uses the instance of JBoss Cache managed by the built-in pojoCache
component.
Attributes
key
— the key to cache rendered content, often a value expression. For example, if we were caching a page fragment that displays a document, we might usekey="Document-#{document.id}"
.enabled
— a value expression that determines whether the cache should be used.region
— specifies the JBoss Cache node to use. Different nodes can have different expiry policies.
Usage
31.1.6.2. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
A tag that acts as a file download provider. It must be alone in the JSF page. To use this control, you must configure
web.xml
as follows:
Configuration
Attributes
data
— specifies data that should be downloaded. May be a java.util.File, an InputStream or a byte array.fileName
— the filename of the file to be served.contentType
— the content type of the file to be downloaded.disposition
— the disposition to use. The default disposition isinline
.
Usage
The tag is used as follows:
<s:resource xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" data="#{resources.data}" contentType="#{resources.contentType}" fileName="#{resources.fileName}" />
<s:resource xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
data="#{resources.data}" contentType="#{resources.contentType}"
fileName="#{resources.fileName}" />
Here, the bean named
resources
is some backing bean that, given some request parameters, serves a specific file — see s:download
.
31.1.6.3. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Builds a RESTful link to a
<s:resource>
. Nested f:param
build up the url.
src
— Resource file serving files.
Attributes
<s:download src="/resources.xhtml"> <f:param name="fileId" value="#{someBean.downloadableFileId}"/> </s:download>
<s:download src="/resources.xhtml">
<f:param name="fileId" value="#{someBean.downloadableFileId}"/>
</s:download>
This produces a link of a similar form to the following:
http://localhost/resources.seam?fileId=1
31.1.6.4. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
An extended
<h:graphicImage>
that allows the image to be created in a Seam Component. It is possible to transform the image further.
All
<h:graphicImage>
attributes are supported, in addition to:
Attributes
value
— specifies the image to display. Can be a pathString
(loaded from the classpath), abyte[]
, ajava.io.File
, ajava.io.InputStream
or ajava.net.URL
. Currently supported image formats areimage/png
,image/jpeg
andimage/gif
.fileName
— specifies the filename of the image. This name should be unique. If left unspecified, a unique filename will be generated for the image.
Transformations
To transform the image, nest a tag specifying which transformation to apply. Seam currently supports the following transformation tags:
-
<s:transformImageSize>
width
— specifies the new width of the image.height
— specifies the new height of the image.maintainRatio
— iftrue
, and one of eitherwidth
orheight
is specified, the image will be resized to maintain theheight
:width
aspect ratio.factor
— scales the image by the specified factor.
-
<s:transformImageBlur>
radius
— performs a convolution blur with the specified radius.
-
<s:transformImageType>
contentType
— alters the image type to eitherimage/jpeg
orimage/png
.
You can also create your own image transformation. Create a
UIComponent
that implements org.jboss.seam.ui.graphicImage.ImageTransform
. Inside the applyTransform()
method, use image.getBufferedImage()
to get the original image and image.setBufferedImage()
to set your transformed image. Transforms are applied in the order specified in the view.
Usage
<s:graphicImage rendered="#{auction.image ne null}" value="#{auction.image.data}"> <s:transformImageSize width="200" maintainRatio="true"/> </s:graphicImage>
<s:graphicImage rendered="#{auction.image ne null}"
value="#{auction.image.data}">
<s:transformImageSize width="200" maintainRatio="true"/>
</s:graphicImage>
31.1.6.5. 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Description
Generates the Javascript stubs required to use Seam Remoting.
Attributes
include
— a comma-separated list of the component names (or fully qualified class names) for which to generate Seam Remoting Javascript stubs. See Chapter 24, Remoting for more details.
Usage
<s:remote include="customerAction,accountAction,com.acme.MyBean"/>
<s:remote include="customerAction,accountAction,com.acme.MyBean"/>