Taylor

Defining Presentation Rules

From Taylor

JSF components have many attributes which control how they are ultimately rendered, such as: required, disabled, rendered, maxsize, reRender, etc. These attributes are typically initialized with constants or expressions in individual facelets. However, this scatters these business rules across the code base. Taylor provides a simple alternative.

Contents

Goal

  • Define rules in a single location instead of spread across many facelets
  • Reuse rules across facelets
  • Leverage Seam's support for expression language in resource bundles
  • Leverage existing rules defined in entity beans via annotations

Rule Access

  • Rules are retrieved using the TaylorFunctions library
  • The library uses the view id, class name, and property name to look up the rule in a resource bundle
<h:inputText value="#{product.productNumber}"
	rendered="#{t:rendered(product, 'productNumber')}"
	disabled="#{t:disabled(product, 'productNumber')}" 
/>

Rule Defintion

Resource Bundle Based Rules

  • <project-ejb>/src/main/resources/rules.properties
  • Not regenerated by Taylor MDA

Global Rules

  • <classSimpleName>.<propertyName>.<rule>=expression
Product.editable=#{product.unapproved}
Product.productNumber.rendered=#{true}
Product.productNumber.disabled=#{!s:hasRole('ProductAdmin')}
Product.discounts.rendered=#{product.discounted}

View Specific Rules

  • <view.id>.<classSimpleName>.<propertyName>.<rule>=expression
  • JSF View Id with / replaced with . and no extension
    • /jsf/ProductWizard.xhtml = jsf.ProductWizard
jsf.ProductWizard.Product.productNumber.disabled=#{true}
jsf.ProductWizard.Product.type.reRender=optionsPanel

Context Variables

  • The context variables used in the expressions must be initialized
  • Factory option
   @Factory('product')
   public Product initEntity() {
      return getInstance();
   }
  • Out-jection option
   @Out 
   private Product product;

Annotation Based Rules

Some rules are not specific to the presentation layer, but still play a role. These are modeled using stereotypes and generated into entity beans as annotations.

TaylorFunctions will use reflection to derive the presentation rule.

  • t:required - @Required
  • t:length - @Length, @Column
  • t:min - @Min, @Range
  • t:max - @Max, @Range
  • t:hasPermission - @Premission

Configuration

  • <project-ejb>/src/main/resources/rules.properties
  • components.xml
<core:resource-loader>
	<core:bundle-names>
		<value>application</value>
		<value>messages</value>
		<value>rules</value>
	</core:bundle-names>
</core:resource-loader>