Tag: jsf

JSF – Javascript without taglibs, scriptlets and no pain

Who tried to use an if with javascript with logic operators && or ||, knows how painful this can be inside a JSF page.

Many developer opt to create .js files and reference them with tag <script src=”path_to_file.js”></script>, what is highly recommended, but will increase amount files in your directories when you just need a specific script only in a page and in no other place.

To avoid fails in JSF Render Fase, add a comment followed by tag CDATA after line with <script> and end with another comment closing CDATA, like this:

<script>
//<![CDATA[
...
//]]>
</script>

JSF works parsing these files as XML and the expressions “&&” and “||” are confused with scriptlet’s logic operators or ELExpressions, what causes fail in rendering.


JSF 2.2: Pass Through – Using custom attributes without headache

JSF taglib is very helpful to build HTML forms and reports. Not all W3C’s attributes are available in standard tags. The h:inputText does not contains the attribute “placeholder”, available only in HTML5.

To make up this “limitation” without overwriting a component or building a new one, JSF 2.2 has the “workaround” called Pass Through Attributes. A new tag to inhibit to remove any custom attributes.

Declare tag using xmlns:p=”http://xmlns.jcp.org/jsf/passthrough”. Now, you can put “p:” in any JSF tag as attribute, like “<h:outputText p:MyAttribute=”MyValue” … />”. This will write “<input type=”text” MyAttribute=”MyValue” … />”.

Go to work:

JSF without Pass Through

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html">
	<h:head>
	</h:head>
	<h:body>
		<f:view contentType="text/html">
			<h:form>
				<!-- Numeric input text and placeholder attribute -->
				<h:inputText ... placeholder="Age" type="number" />
			</h:form>
		</f:view>
	</h:body>
</html>

There is not “placeholder” attribute

With Pass Through

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://xmlns.jcp.org/jsf/passthrough">
	<h:head>
	</h:head>
	<h:body>
		<f:view contentType="text/html">
			<h:form>
				<!-- Numeric input text and placeholder attribute -->
				<h:inputText ... p:placeholder="Age" p:type="number" />
			</h:form>
		</f:view>
	</h:body>
</html>
There is "placeholder" attribute

There is “placeholder” attribute


  • Advertisement

  • Advertisement

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress