SeamFramework.orgCommunity Documentation

Chapter 29. Seam JSF controls

29.1. Tags
29.1.1. Navigation Controls
29.1.2. Converters and Validators
29.1.3. Formatting
29.1.4. Seam Text
29.1.5. Dropdowns
29.1.6. Other
29.2. Annotations

Seam includes a number of JSF controls that are useful for working with Seam. These are intended to complement the built-in JSF 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.

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">

The ui example demonstrates the use of a number of these tags.

Description

Assigns an entity converter to the current component. This is primarily useful for radio button and dropdown controls.

The converter works with any managed entity which has an @Id annotation - either simple or composite.

Attributes

None.

Configuration

You must use Seam managed transactions (see Section 9.2, “Seam managed transactions”) with <s:convertEntity />.

If your Managed Persistence Context isn't called entityManager, then you need to set it in components.xml:


<component name="org.jboss.seam.ui.EntityConverter">
   <property name="entityManager">#{em}</property>
</component>

If you are using a Managed Hibernate Session then you need to set it in components.xml:


<component name="org.jboss.seam.ui.EntityConverter">
   <property name="session">#{hibernateSession}</property>
</component>

If you want to use more than one entity manager with the entity converter, you can create a copy of the entity converter for each entity manager in components.xml:


<component name="myEntityConverter" class="org.jboss.seam.ui.converter.EntityConverter">
   <property name="entityManager">#{em}</property>
</component>

<h:selectOneMenu value="#{person.continent}">
   <s:selectItems value="#{continents.resultList}" var="continent" 
                  label="#{continent.name}" />
   <f:converter converterId="myEntityConverter" />
</h:selectOneMenu>

Usage


<h:selectOneMenu value="#{person.continent}" required="true">
   <s:selectItems value="#{continents.resultList}" var="continent" 
                  label="#{continent.name}" 
                  noSelectionLabel="Please Select..."/>
   <s:convertEntity />
</h:selectOneMenu>

Description

Renders a file upload control. This control must be used within a form with an encoding type of multipart/form-data, i.e:


<h:form enctype="multipart/form-data">

For multipart requests, the Seam Multipart servlet filter must also be configured in web.xml:


<filter>
  <filter-name>Seam Filter</filter-name>
  <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>Seam Filter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Configuration

The following configuration options for multipart requests may be configured in components.xml:

Here's an example:


<component class="org.jboss.seam.web.MultipartFilter">
  <property name="createTempFiles">true</property>
  <property name="maxRequestSize">1000000</property>
</component>

Attributes

Usage


<s:fileUpload id="picture" data="#{register.picture}" 
              accept="image/png"
              contentType="#{register.pictureContentType}" />

Description

An extended <h:graphicImage> that allows the image to be created in a Seam Component; further transforms can be applied to the image.

All attributes for <h:graphicImage> are supported, as well as:

Attributes

Transformations

To apply a transform to the image, you would nest a tag specifying the transform to apply. Seam currently supports these transforms:

It's easy to create your own transform - create a UIComponent which 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>

Seam also provides annotations to allow you to use Seam components as JSF converters and validators:

@Converter
@Name("itemConverter") 

   @BypassInterceptors 
   @Converter
   public class ItemConverter implements Converter {
      
     @Transactional
     public Object getAsObject(FacesContext context, UIComponent cmp, String value) {
       EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
       entityManager.joinTransaction();
       // Do the conversion
     }
     
     public String getAsString(FacesContext context, UIComponent cmp, Object value) {
       // Do the conversion
     }
     
   }

<h:inputText value="#{shop.item}" converter="itemConverter" />

Registers the Seam component as a JSF converter. Shown here is a converter which is able to access the JPA EntityManager inside a JTA transaction, when converting the value back to it's object representation.

@Validator
@Name("itemValidator") 

   @BypassInterceptors 
   @Validator
   public class ItemValidator implements Validator {
      
     public void validate(FacesContext context, UIComponent cmp, Object value)
       throws ValidatorException {
       ItemController ItemController = (ItemController) Component.getInstance("itemController");
       return itemController.validate(value);
     }
     
     }

<h:inputText value="#{shop.item}" validator="itemValidator" />

Registers the Seam component as a JSF validator. Shown here is a validator which injects another Seam component; the injected component is used to validate the value.