이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 32. JBoss EL


Seam uses JBoss EL to provide an extension to the standard Unified Expression Language (EL). This provides several enhancements to the expressiveness and power of EL expressions.

32.1. Parameterized Expressions

Standard EL does not allow methods to be used with user-defined parameters, but JBoss EL removes this restriction. For example:
<h:commandButton action="#{hotelBooking.bookHotel(hotel)}" 
                 value="Book Hotel"/>
Copy to Clipboard Toggle word wrap
@Name("hotelBooking") 
public class HotelBooking { 
  public String bookHotel(Hotel hotel) { 
    // Book the hotel 
  } 
}
Copy to Clipboard Toggle word wrap

32.1.1. Usage

As in method calls from Java, parameters are surrounded by parentheses, and separated by commas:
<h:commandButton action="#{hotelBooking.bookHotel(hotel, user)}" 
                 value="Book Hotel"/>
Copy to Clipboard Toggle word wrap
Here, the parameters hotel and user will be evaluated as value expressions and passed to the bookHotel() method of the component.
Any value expression can be used as a parameter:
<h:commandButton action="#{hotelBooking.bookHotel(hotel.id, 
                           user.username)}" 
                 value="Book Hotel"/>
Copy to Clipboard Toggle word wrap
When the page is rendered, the parameter names —hotel.id and user.username —are stored, and evaluated as value expressions when the page is submitted. Objects cannot be passed as parameters.
Parameters must be available both when the page is rendered and when it is submitted. If the arguments cannot be resolved at page submission time, the action method will be called with null arguments.
You can also pass literal strings using single quotes:
<h:commandLink action="#{printer.println('Hello world!')}" 
               value="Hello"/>
Copy to Clipboard Toggle word wrap
Unified EL also supports value expressions, which are used to bind a field to a backing bean. Value expressions use JavaBean naming conventions and expect a getter/setter pair. JSF often expects a value expression where only retrieval (get) is required (for example, in the rendered attribute), but many objects do not have appropriately named property accessors, or do not require parameters.
JBoss EL removes this restriction by allowing values to be retrieved using the method syntax. For example:
<h:outputText value="#{person.name}" 
              rendered="#{person.name.length() > 5}" />
Copy to Clipboard Toggle word wrap
You can access the size of a collection in a similar manner:
#{searchResults.size()}
Copy to Clipboard Toggle word wrap
In general, any expression of the form #{obj.property} would be identical to the expression #{obj.getProperty()}.
Parameters are also allowed. The following example calls the productsByColorMethod with a literal string argument:
#{controller.productsByColor('blue')}
Copy to Clipboard Toggle word wrap

32.1.2. Limitations and Hints

JBoss EL does have several limitations:
  • Incompatibility with JSP 2.1 —JBoss EL cannot currently be used with JSP 2.1, because the compiler rejects expressions that include parameters. You will need Facelets if you want to use this extension with JSF 1.2. The extension works correctly with JSP 2.0.
  • Use inside iterative components —Components like <c:forEach /> and <ui:repeat /> iterate over a list or array, exposing each item in the list to nested components. This is effective if you are selecting a row with a <h:commandButton /> or <h:commandLink /> like so:
    @Factory("items") 
    public List<Item> getItems() { 
      return entityManager.createQuery("select ...").getResultList(); 
    }
    
    Copy to Clipboard Toggle word wrap
    <h:dataTable value="#{items}" var="item"> 
      <h:column> 
        <h:commandLink value="Select #{item.name}" 
           action="#{itemSelector.select(item})" /> 
      </h:column> 
    </h:dataTable>
    
    Copy to Clipboard Toggle word wrap
    However, if you want to use <s:link /> or <s:button /> you must expose the items as a DataModel, and use a <dataTable /> (or equivalent from a component set like <rich:dataTable />). Neither <s:link /> or <s:button /> submit the form, so they do not produce a bookmarkable link. An additional parameter is required to recreate the item when the action method is called. This parameter can only be added when a data table backed by a DataModel is used.
  • Calling a MethodExpression from Java code —Normally, when a MethodExpression is created, the parameter types are passed in by JSF. However, in a method binding, JSF assumes that there are no parameters to pass. With this extension, there is no way to know the parameter types prior to expression evaluation. 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.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat