Recent Notes
Displaying notes 71 - 80
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 05, 2011 12:41:21
Last update: December 05, 2011 12:41:21
Use the varStatus.first property and EL to assign a different CSS class for the first element:
<ui:repeat var="name" varStatus="status" value="#{...
Created by Fang on December 05, 2011 12:01:02
Last update: December 05, 2011 12:01:02
EL does floating point division when you divide two ints. For example:
<p>2/1: ${2/1}</p>
<p>4/2: ${4/2}</p>
<p>8/3...
outputs:
2/1: 2.0
4/2: 2.0
8/3: 2.66666666666...
What if you want to get 2 by 4/2 or 8/3 ?
Use:
<p>4/2: ${fn:substringBefore(4/2, '.')}</p>
<p>...
Created by Fang on December 05, 2011 08:41:31
Last update: December 05, 2011 08:41:31
Behavior for functions substringBefore and substringAfter are well defined when the string to look for exists. But what happens when the substring is not found? Do they return the whole string or empty string?
Code:
<p>substringBefore('a.b', '.'): #{fn:substringBefo...
Result:
substringBefore('a.b', '.'): a
substringBef...
Created by Fang on December 03, 2011 12:31:20
Last update: December 03, 2011 12:33:23
The <h:outputText> tag generates different output for body text and value attribute. I tested the following with Apache MyFaces 2.1.3:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric...
With value attribute, the output was:
<table border='1' cellspacing='0' cellpadding='4'>...
With text in body, the output was (i.e., the text was escaped despite escape="false" ):
<table border='1' cellspacing='0' cellpadding='...
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 mee2 on December 02, 2011 10:07:15
Last update: December 02, 2011 10:07:15
If you use "content" or "contents" as names for spaces, you cannot get to the space with Alfresco REST URL with /p . Suppose you give a URL like:
http://localhost:8080/alfresco/service/cmis/p/MySp...
How does Alfresco know that you are referring to the content space under SubSpace , not the contents of SubSpace ? In fact, Alfresco thinks the latter and will return "404 Page not found" if SubSpace is a space not content.
Created by Fang on November 10, 2011 13:19:13
Last update: December 01, 2011 19:10:43
You can add custom implicit variables to JSF pages by using a custom EL resolver, in two simple steps: Write an ELResolver class to resolve the variable Add the ELResolver to faces-config.xml Starting from the Maven Hello World example: Add faces API and EL dependencies to pom.xml :
<dependencies> <dependency> <groupId>o... Add a simple greeter class ( src/main/java/com/example/Greeter.java ): package com.example; public class Greeter {... Add our custom EL resolver ( src/main/java/com/example/ELResolver.java ): package com.example; import java.util.Itera... Add the custom EL resolver to src/main/resources/META-INF/faces-config.xml <?xml version="1.0" encoding="UTF-8"?> <faces-c... Build JAR with mvn package Drop the JAR into WEB-INF/lib of a webapp and test the new EL with: <h:outputText value="#{Greeter.sayHi('Mike')}"/> Fixed: the setValue method used to throw an exception, which is wrong. @Override public void setValue(ELContext ctx, O......
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 28, 2011 21:04:15
Last update: November 28, 2011 21:04:15
Some innocent looking JavaScript may cause a fatal error in a Facelet page. For example:
<script type="text/javascript">
if (items.lengt...
or
<script type="text/javascript">
// jQuery code ...
Because Facelet is strict XML, therefore, < and > must be escaped.
There are several ways to deal with this:
Do not embed JS code directly in the page. Put the code in .js files and include it in the page with the src attribute.
Put JS code in a CDATA section:
<h:outputScript target="head">
<![CDATA...
Use XML entities:
<script type="text/javascript">
// jQuery code ...