Notes by Fang

Displaying notes 91 - 100
Created by Fang on November 21, 2011 13:49:11    Last update: November 21, 2011 13:49:11
In the test for the simple taglib example , I used a literal string for the name attribute: <my:hello name="Jack"/> What happens if the name attribute contains EL expresson? For example: <my:hello name="#{param['name']}"/> If EL works, the tag should take the value of the " name " request parameter and print it out. But the tag as implemented in the simple taglib example prints the literal string: Hello #{param['name']}! I am FaceletTag. In order to make a tag to recognize EL, we have to use TagAttribute.getValue(FaceletContext ctx) instead of TagAttribute.getValue() . The latter returns the literal value of the attribute. The HelloTagHandler should be changed to: package com.example; import java.io.IOExcep... Rebuild the taglib and test with a URL like this: http://localhost:8080/facelet-test/?name=Jack The tag will print:...
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 14, 2011 11:01:55    Last update: November 14, 2011 11:01:55
This is the best in my opinion: http://search.maven.org/ . It is not the first result by Google search, but I hope it will be there soon. Others are confusing...
Created by Fang on November 12, 2011 21:03:03    Last update: November 12, 2011 21:03:03
Experts may disagree but I found it absolutely stunning that JSF EL does not provide an operator for string concatenation. The Java "+" operator is there for the take. Java, which is a strongly typed compiled language, overloads the "+" operator in such a way that any object can be concatenated with a string. But JSF EL, which definitely isn't as strongly typed as Java, restricts the "+" operator to numerical values only! Of course, experts may argue that the "+" operator overloading is a huge design flaw of the Java language. But even so, JSF EL is not the right place to fix it! In some cases, a concatenation operator isn't needed, for example: <ui:repeat var="tab" value="#{tabs}"> <img ... But in case the concatenated...
Created by Fang on November 02, 2011 17:15:34    Last update: November 12, 2011 20:09:28
The HTML prettifier tidy can also be used to pretty print XML. Just use the -xml switch. tidy -xml <xmlfile> With indentation: tidy -xml -i <xmlfile> Increase indentation to 4 spaces from the default 2: tidy -xml -i --indent-spaces 4 <xmlfile>
Created by Fang on November 11, 2011 19:43:46    Last update: November 11, 2011 19:43:46
Suppose slides is an array, you can display the first two elements by index like this: Value by index: <p><b>#{slides[0]}</b></p> <... The dot notation, which works for some template languages, does not work for facelets: This does not work: <p><b>#{slides.0}</b></p> ...
Created by Fang on November 10, 2011 20:33:46    Last update: November 10, 2011 20:33:46
The stack trace is like this: java.lang.IllegalArgumentException: Component prop... You get this error because you are using the class attribute with a JSF UI component, for which the class attribute cannot be altered. Of course you meant CSS class, not Java class! You can use the styleClass attribute instead of the class attribute. The styleClass attribute becomes the class attribute when the component is rendered. If you can add a tag handler to the UI component, you can alias class to styleClass , which will allow you to use the class attribute on the UI component: import javax.faces.view.facelets.*; pub...
Created by Fang on November 10, 2011 12:40:47    Last update: November 10, 2011 12:41:07
The expression language defines a set of implicit objects in JSF context: Variable Description facesContext The FacesContext instance for the current request. param Maps a request parameter name to a single value. paramValues Maps a request parameter name to an array of values. header Maps a request header name to a single value. headerValues Maps a request header name to an array of values. cookie Maps a cookie name to a single cookie. initParam Maps a context initialization parameter name to a single value. requestScope Maps request-scoped variable names to their values. sessionScope Maps session-scoped variable names to their values. applicationScope Maps application-scoped variable names to their values. The variable pageScope , which exists in JSP EL, does not exist in JSF EL.
Created by Fang on November 10, 2011 11:27:37    Last update: November 10, 2011 11:28:25
This has been tested working with Apache MyFaces 2.1.3 running Tomcat 7. Managed bean code: package com.example; import javax.faces.bea... Facelet page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric...
Created by Fang on November 10, 2011 09:26:12    Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines! <?xml version="1.0" encoding="UTF-8"?> <xsd:sch...
Previous  5 6 7 8 9 10 11 12 13 14 Next