Tuesday Dec 27, 2011

Using JSTL in ADF Faces

The JavaServer Pages Standard Tag Library (JSTL) provides expressions for common web application functionalities. Though JavaServer Faces Expression Language (EL) is different from JSTL expressions, the two can be used in combination for functional for which it makes sense. For example, the table below lists JSTL expressions that operate on String values.

Function

Description

fn:contains()

Tests if an input string contains the specified substring.

fn:containsIgnoreCase()

Tests if an input string contains the specified substring in a case insensitive way.

fn:endsWith()

Tests if an input string ends with the specified suffix.

fn:escapeXml()

Escapes characters that could be interpreted as XML markup.

fn:indexOf()

Returns the index withing a string of the first occurrence of a specified substring.

fn:length()

Returns the number of items in a collection, or the number of characters in a string.

fn:replace()

Returns a string resulting from replacing in an input string all occurrences with a given string.

fn:startsWith()

Tests if an input string starts with the specified prefix.

fn:substring()

Returns a subset of a string.

fn:substringAfter()

Returns a subset of a string following a specific substring.

fn:substringBefore()

Returns a subset of a string before a specific substring.

fn:toLowerCase()

Converts all of the characters of a string to lower case.

fn:toUpperCase()

Converts all of the characters of a string to upper case.

fn:trim()

Removes white spaces from both ends of a string.

Src: http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

To use JSTL in Oracle ADF Faces component EL references, you need to add the JSTL namespace of the tags you want to reference. For the JSTL functions shown in the table above, you need to manually add the name space highlighted in red to the JSPX document or page fragment.

<jsp:root  
 xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"         
 xmlns:f="http://java.sun.com/jsf/core"         
 xmlns:h="http://java.sun.com/jsf/html"         
 xmlns:af="http://xmlns.oracle.com/adf/faces/rich"        
 xmlns:fn="http://java.sun.com/jsp/jstl/functions">

The value expression below, referenced in an af:outputText component, displays the substring (first, second and third character) for a value read from the ADF binding layer.

<af:outputText value="#{fn:substring(bindings.employeeName.inputValue,1,3)}" id="ot7"/>

Saturday Nov 05, 2011

Accessing View Object UI hints from EL

View Objects can have UI hints defined in their General category. For example, you may want to set the Display Name, Display Name (Plural) and Description on Employees View Object that is based on an Employees entity representing the Employees table in the HR database sample schema. The page snippet below shows how you can access the UI hints on a View Object to display them a header information on an page. 

<af:panelGroupLayout id="pgl2" layout="horizontal">
<af:outputText value="#{bindings.allEmployeesIterator.hints['label']}," id="ot3"/>
<af:spacer width="10" height="10" id="s1"/>
<af:outputText value="#{bindings.allEmployeesIterator.hints['labelPlural']}, " id="ot2"/>
<af:spacer width="10" height="10" id="s2"/>
<af:outputText value="#{bindings.allEmployeesIterator.hints['TOOLTIP']} " id="ot1"/>
</af:panelGroupLayout>

So the Display Name property maps to UI hints "label", the Display Name (Plural) property to the UI hints "labelPlural" and the Description property to the "TOOLTIP" string.

These strings are defined in the oracle.jbo.AttributeHints class. For future-save programming you should consider reading the UI hint strings directly from this class.

To do so, expose the AttributeHints class to EL through a helper managed bean (put it to application scope for best performance) that exposes JavaBean properties for each of the strings.

Using such a helper bean, the above page snippets would look similar to this

<af:panelGroupLayout id="pgl2" layout="horizontal">
<af:outputText value="#{bindings.allEmployeesIterator.hints[helperBean.label]}," id="ot3"/>
<af:spacer width="10" height="10" id="s1"/>
<af:outputText value="#{bindings.allEmployeesIterator.hints[helperBean.labelPlural]}, "
id="ot2"/>
<af:spacer width="10" height="10" id="s2"/>
   ….


About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today