|
Disclaimer:
These pages about different languages / apis / best practices were mostly jotted down quckily and rarely corrected afterwards. The languages / apis / best practices may have changed over time (e.g. the facebook api being a prime example), so what was documented as a good way to do something at the time might be outdated when you read it (some pages here are over 15 years old). Just as a reminder. Facelets Developer notes (Java Server Faces)Coding examples and things I found out about facelets when developed websites in JSFAlso see My Java Server Faces (JSF) notes http://www-128.ibm.com/developerworks/java/library/j-facelets/#N100AA http://www.jsfcentral.com/articles/facelets_3.html To use Tomahawk with facelets http://wiki.apache.org/myfaces/Use_Facelets_with_Tomahawk Loops/conditions in facelets vs jstljstl is evaluated in the Build phase, and the render components in the sender phase, i.e. jstl within ui:repeat will not work since the jstl statements already have been evaluated. as an alternativ, you can use c:forEach <c:forEach items="#{bean.myItems}" var="item"> or use ui:repeat but without jstl conditions <ui:repeat var="item" values="#{bean.myItems}"> http://www.nabble.com/%3Cc:if%3E-block-within-%3Cui:repeat%3E--t1855407.html JSTL is evaluated at build time, where all others are evaluated at render time: <ui:repeat ....> alpha <h:outputText value="beta" rendered="#{cellBean.booleanA}"/> <h:outputText value="charlie" rendered="#{cellBean.booleanB"/> </ui:repeat> If you want to have a value which is a bunch of HTML markup in the page, then you can use: <ui:fragment rendered="#{cellBean.booleanC}"> <marquee>weeeee!</marquee> </ui:fragment> http://www.nabble.com/JSTL-EL-problems---conditions-tf3227462.htm Sorry, bear with me there is a reason for this, but where is aCat set? If it is an iteration variable from a "render time" component, for example, it will not exist yet when <c:if> is evaluated. It's the build time vs render time thing, think of the jstl tags as macros that are expanded prior to the component tree being built. If they are nested inside an iterator such as ui:repeat or t:dataList they still get executed before those tags are rendered. So if they reference an iteration variable from those tags the variable is not yet set. It is set, however, by the time your output text is rendered and this why you see values. l Directory structure problemsFor the record, XXX replied (off-list?) and told me that I could use #{facesContext.externalContext.requestContextPath}.
In fact, I did this in my main template.xhtml: <c:set var="webRoot" value="#{facesContext.externalContext.requestContextPath}"/> <link href="#{webRoot}/resources/view/styles/default.css" type="text/css" rel="stylesheet" /> The advantage is that now, the shorter #{webRoot} is available everywhere, including in templates that use my main template.xhtml. Create custom components in facelets / reuse jsf componentsHow to create a custom component in a separare .jarTo include resources (javascripts, images) in the jar file, weblets seems to be the solution. The file/directory structure I build like this, I could not find any standard naming for the directories: META-INF/example.taglib.xml
web/sometag.xhtml example.taglib.xml: <?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://www.arc-mind.com/jsf</namespace> <tag> <tag-name>mytag</tag-name> <source>/web/sometag.xhtml</source> </tag> </facelet-taglib> sometag.xhtml: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"> <ui:composition> HERE SHOULD THE CODE FOR THE COMPONENT BE </ui:composition> </html> Interesting Facelets Linkshttp://www.jsfcentral.com/articles/facelets_2-2.htmlhttp://www.javakaffee.de/blog/2006/12/11/how-to-add-a-new-attribute-to-an-existing-jsf-component-using-facelets/ http://marc2.theaimsgroup.com/?t=116463837000004&r=1&w=2 http://www.theserverside.com/news/thread.tss?thread_id=40113 http://www-128.ibm.com/developerworks/java/library/j-facelets/ Advanced facelets programming http://www-128.ibm.com/developerworks/web/library/j-facelets2.html http://www-128.ibm.com/developerworks/library/os-ad-derbymyfaces/ Forum about Faceletshttp://www.nabble.com/java.net---Facelets-f13477.htmlCode snippets<ui:fragment rendered="#{type == 'developer'}"><ui:repeat value="#{jsfBackingBean.listDevelopers}" var="aDeveloper"> More programming related pages |
|