站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss Seam 1.1.0 bate1 英文参考手册

Chapter 16. Expression language enhancements - JBoss Seam 1.1.0 bate1 英文参考手册

Chapter 16. Expression language enhancements

The standard Unified Expression Language (EL) assumes that any parameters to a method expression will be provided by Java code. This means that a method with parameters cannot be used as a JSF method binding. Seam provides an enhancement to the EL that allows parameters to be included in a method expression itself. This applies to any Seam method expression, including any JSF method binding, for example:

<s:commandButton action="#{hotelBooking.bookHotel(hotel)}" value="Book Hotel"/>

16.1. Configuration

To use this feature in Facelets, you will need to declare a special view handler, SeamFaceletViewHandler in faces-config.xml.

<faces-config>
    <application>
        <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>
    </application>
</faces-config>

16.2. Usage

Parameters are surrounded by parentheses, and separated by commas:

<h:commandButton action="#{hotelBooking.bookHotel(hotel, user)}" value="Book Hotel"/>

The parameters hotel and user will be evaluated as value expressions and passed to the bookHotel() method of the component. This gives you an alternative to the use of @In.

Any value expression may be used as a parameter:

<h:commandButton action="#{hotelBooking.bookHotel(hotel.id, user.username)}" value="Book Hotel"/>

You may even pass literal strings using single or double quotes:

<h:commandLink action=”#{printer.println( ‘Hello world!’ )}” value=”Hello”/>
<h:commandLink action=’#{printer.println( “Hello again” )}’ value=’Hello’/>

You might even want to use this notation for all your action methods, even when you don’t have parameters to pass. This improves readability by making it clear that the expression is a method expression and not a value expression:

<s:link value="Cancel" action="#{hotelBooking.cancel()}"/>

16.3. Limitations

Please be aware of the following limitations:

16.3.1. Incompatibility with JSP 2.1

This extension is not currently compatible with JSP 2.1. So if you want to use this extension with JSF 1.2, you will need to use Facelets. The extension works correctly with JSP 2.0.

16.3.2. Calling a MethodExpression from Java code

Normally, when a MethodExpression or MethodBinding is created, the parameter types are passed in by JSF. In the case of a method binding, JSF assumes that there are no parameters to pass. With this extension, we can’t know the parameter types until after the expression has been evaluated. This has two minor consequences:

  • When you invoke a MethodExpression in Java code, parameters you pass may be ignored. Parameters defined in the expression will take precedence.

  • Ordinarily, it is safe to call methodExpression.getMethodInfo().getParamTypes() at any time. For an expression with parameters, you must first invoke the MethodExpression before calling getParamTypes().

Both of these cases are exceedingly rare and only apply when you want to invoke the MethodExpression by hand in Java code.