Notes by Fang
Displaying keyword search results 1 - 10
Created by Fang on December 05, 2011 13:04:11
Last update: December 05, 2011 13:04:11
Facelet requires strict XML syntax, so unmatched tags (start with no end, etc) generate errors. This is a trick to workaround that. The following code generates a row for every three items and for each row assigns a row id:
<!-- using ui:repeat -->
<ui:repeat var="name" ...
Created by Fang on December 03, 2011 12:12:22
Last update: December 03, 2011 12:14:38
I wrote about this before and I'm writing about it again. Because I fell for it for the second time!
This does not work :
<ui:repeat var="item" value="items" varStatus="sta...
Use this instead:
<ui:repeat var="item" value="items" varStatus="sta...
Created by Fang on December 01, 2011 18:54:54
Last update: December 01, 2011 18:54:54
Use the varStatus attribute with the ui:repeat tag to get the iteration index:
<ui:repeat varStatus="status" var="item" value="#{...
The varStatus attribute specifies the name of the exported request scoped variable for the status of the iteration.The object is a POJO with the following read-only JavaBeans properties. This scoped variable has nested visibility.
begin of type Integer
end of type Integer
index of type int
step of type Integer
even of type boolean
odd of type boolean
first of type boolean
last of type boolean
Created by Fang on November 22, 2011 10:40:16
Last update: November 22, 2011 10:40:16
This is an example that uses tag handler, UI component and renderer together to support a custom taglib. The main purpose is to show how these components play together.
The tag renders
<ui:param name="extra" value="el interpreted"/>
...
as
<h3>my:foreach</h3>
<ul class="css class" extra...
These are the files:
The tag handler ( src/main/java/com/example/ForeachTagHandler.java ):
package com.example;
import java.util.Map;
...
The UI component ( src/main/java/com/example/UIForeach.java ):
package com.example;
import java.io.IOExcep...
The renderer ( src/main/java/com/example/ForeachRenderer.java ):
package com.example;
import java.io.IOExcep...
Faces config ( src/main/resources/META-INF/faces-config.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<faces-c...
Taglib config ( src/main/resources/META-INF/foreach.taglib.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<facelet...
Created by Fang on November 14, 2011 20:50:51
Last update: November 22, 2011 09:06:10
This facelet fragment will never print anything:
<ui:repeat var="person" value="#{myBean.theJTeam}"... because the test condition always returns false, even though the person var is not null. The same happens even when I define another variable with ui:param : <ui:repeat var="person" value="#{myBean.theJTeam}"... What's happening? The c:if test condition is evaluated before the ui:repeat tag had a chance to set the value! Both facelet ui tags and JSTL c tags are evaluated at the Render Response phase of the JSF lifecycle. But within the Render Response cycle, there are two sub-phases (so to speak): the first builds the UI element tree, the second renders the UI tree. The JSTL c:if tag is evaluated when the tree is built, but the facelet ui:repeat tag is evaluated when the UI...
Created by Fang on November 08, 2011 20:55:00
Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print
<p>john</p> <p>steve</p> <p>mike</p> with custom tag <my:foreach> : <my:foreach var="who" value="john steve mike"> ... These are the files: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/com/example/UIForeash.java : package com.example; import java.io.IOExcep... src/main/resources/META-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <faces-c... src/main/resources/META-INF/foreach.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by Fang on November 14, 2011 20:14:35
Last update: November 14, 2011 20:14:35
Using the c:forEach tag in JSF:
<c:forEach var="person" value="#{myBean.people}">
...
failed with OutOfMemoryError :
java.lang.OutOfMemoryError: Java heap space
at...
The problem? The c:forEach tag gets the iteration collection from the item attribute, not the value attribute (as ui:repeat does). But still, OutOfMemoryError for using a wrong attribute is gross!
Created by Fang on November 08, 2011 14:40:57
Last update: November 08, 2011 14:40:57
This error happened when I loaded a JSF page, using Apache MyFaces. From the stack trace it looked like the XML parser failed, but in reality the runtime was not able to load the class specified in the handler-class element - a typo in the class name! That's the price you pay for wiring together components with XML!
This was the stack trace:
Caused by: org.xml.sax.SAXException: Error Handlin...
Created by Fang on November 02, 2011 14:40:16
Last update: November 02, 2011 14:40:48
JSTL was built for Java Server Pages (JSPs). With the coming of JSF 2.0, facelets, instead of JSP , is the preferred page rendering technology.
Facelets exposes a subset of the JSTL Core tag library and the entirety of the JSTL Function tag library.
The JSTL tags available in facelets are:
c:set
c:if
c:forEach
c:choose
c:when
c:otherwise
c:catch
Created by Fang on March 23, 2010 01:43:47
Last update: September 03, 2010 14:21:15
This is a bare bones, no frills, just the facts tutorial on JSTL. I will not bother you with theories, principles, best practices, anecdotes, or any other junk, because JSTL is shallow and simple, and I don't want to make it sound deep or complex. Getting ready JSTL/JSP Expression Language JSTL implicit variables A simple test application for JSTL Expanding the simple JSTL test application Core Tags Basic tags : <c:out> , <c:set> , <c:remove> , <c:catch> Flow control tags : <c:if> , <c:choose> , <c:when> , <c:otherwise> , <c:forEach> , <c:forTokens> URL Tags : <c:import> , <c:url> , <c:redirect> , <c:param> Internationalization (i18n) and formatting tags I18N Overview Set locale : <fmt:setLocale> , <fmt:requestEncoding> Format messages : <fmt:message> , <fmt:bundle> , <fmt:setBundle> , <fmt:param>...