Just a quick update to correct a couple of issues I found with the recent post on populating a Google Map. You may remember that there was a convoluted method for populating the map by iterating over the elements of the Collection using a rich:dataList. This can simply be replaced with a loop using ui:repeat. For example:


<div id="shopListController" style="visibility: hidden;"><!-- yeah, I know this is clumsy! -->
<rich:dataList var="shop" value="#{shops}">
<script type="text/javascript">
addShop('<h:outputText value="#{shop.latitude}"/>',

'<h:outputText value="#{shop.longitude}"/>',
<h:outputText value="#{shop.id}"/>,
'<h:outputText value="#{shop.name}"/>',
'<h:outputText value="#{shop.description}"/>');

</script>
</rich:dataList></div>


becomes:


<ui:repeat var="shop" value="#{shops}">
<script type="text/javascript">
addShop('<h:outputText value="#{shop.latitude}"/>',

'<h:outputText value="#{shop.longitude}"/>',
<h:outputText value="#{shop.id}"/>,
'<h:outputText value="#{shop.name}"/>',
'<h:outputText value="#{shop.description}"/>');

</script>
</ui:repeat>


Also, any items with a single quote in either the name or the description will cause the Javascript to fail. One way to solve this is by creating a tag library which provides functionality to replace the single quote with the relevant escaped character.

So we will have a class containing a method to replace apostrophes (for example ViewUtils.replaceApostrophe(java.lang.String input)). We will need to create an appropriate tag library definition file containing a reference to this method.


<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<facelet-taglib>
<namespace>http://www.abstractec.co.uk/thinkinginseam</namespace>

<function>
<function-name>replaceApostrophe</function-name>
<function-class>uk.co.abstractec.example.util.ViewUtil</function-class>
<function-signature>java.lang.String replaceApostrophe(java.lang.String)</function-signature>
</function>
</facelet-taglib>


Now, within our Facelet we will have to include this tag library by adding the following line into ui:composition:


xmlns:abstractec="http://www.abstractec.co.uk/thinkinginseam"


Note that the XML namespace in the Facelet matches the namespace element in the taglib file.

Now we can use the taglib in our facelet.