JSF2
This is version . It is not the current version, and thus it cannot be edited.
Back to current version   Restore this version

Hier sind einige Informationen über JSF 2 gespeichert.

Google Richfaces vs Primefaces Trends#

RED = Primefaces, BLUE = Richfaces

Composite Tags#

AJAX Status#

Die Component zeit den AJAX-Status an.
<?xml version="1.0" encoding="UTF-8"?>
<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/jsp/jstl/core"
	xmlns:cc="http://java.sun.com/jsf/composite"
>
	<cc:interface>
		<cc:attribute name="status" default="begin"/>
	</cc:interface>
	<cc:implementation>
		<script type="text/javascript">
			jsf.ajax.addOnEvent(function(data) {
				document.getElementById('#{cc.clientId}:status').style.visibility =
					data.status == '#{cc.attrs.status}' ? 'visible' : 'hidden';
			});
		</script>
		<div id="#{cc.clientId}:status" style="visibility: hidden;">
		    <cc:insertChildren/>
		</div>
	</cc:implementation>
</html>

Verwendung zum Beispiel wie folgt:

<test:ajaxStatus>
	<h:graphicImage value="/images/wait30trans.gif"/>
</test:ajaxStatus>

HTML Element Tag#

Der Tag rendert ein HTML-Element mit ClientId und übergibt alle Attribute und Childrens.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:cc="http://java.sun.com/jsf/composite"
>
	<cc:interface name="test">
		<cc:attribute name="element" required="true"/>
		<cc:attribute name="rendered"/>
	</cc:interface>
	<cc:implementation>
		<c:if test="#{!rendered or rendered}">
			<h:outputText value="&lt;#{cc.attrs.element} id=&quot;#{cc.clientId}&quot;" escape="false"/>
			<c:forEach items="#{cc.attributes}" var="attribute">
				<h:outputText value=" #{attribute.key}=&quot;#{attribute.value}&quot;" escape="false"
					rendered="#{!attribute.key.startsWith('javax.faces') and
						!attribute.key.startsWith('com.sun') and
						attribute.key != 'element' and
						attribute.key != 'rendered'}"/>
			</c:forEach>
			<h:outputText value="&gt;" escape="false"/>
			<cc:insertChildren/>
			<h:outputText value="&lt;/#{cc.attrs.element}&gt;" escape="false"/>
		</c:if>
	</cc:implementation>
</html>

Validierung prüfen#

FacesContext.getCurrentInstance().isValidationFailed();

#{facesContext.validationFailed}

Setup#

web.xml
	<context-param>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>server</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.PROJECT_STAGE</param-name>
		<param-value>Development</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
		<param-value>/WEB-INF/test.taglib.xml</param-value>
	</context-param>
	
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>/faces/*</url-pattern>
	</servlet-mapping>

EL-Expressions 2.1#

Die neuen EL-Expressions erlauben das Binding an Action-Methods, die Parameter besitzen:
<h:commandButton value="Test" action="#{test.action('param')}"/>

In der pom.xml die Libs referenzieren:

		<dependency>
			<groupId>javax.el</groupId>
			<artifactId>el-api</artifactId>
			<version>2.2</version>
		</dependency>
		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>el-impl</artifactId>
			<version>2.2</version>
		</dependency>
		
		<repository>
			<id>maven.java.net</id>
			<name>Java.net Maven2 Repository</name>
			<url>http://download.java.net/maven/2</url>
		</repository>

Und in der web.xml die Factory festlegen:

	<context-param>
		<param-name>com.sun.faces.expressionFactory</param-name>
		<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
	</context-param>