Tuesday, December 29, 2015

How to parameterized label from resource bundle

Assuming we have a of labels to be displayed by type.
label.type.a = This is label A label.type.b = This is label B label.type.c = This is label C label.type.d = This is label D

To display the label by type in xhtml, the simplest way it to use a rendered attribute
<h:outputLabel value="#{lbl['label.type.a']}" rendered="#{myType == 'A'}" /> <h:outputLabel value="#{lbl['label.type.b']}" rendered="#{myType == 'B'}" /> <h:outputLabel value="#{lbl['label.type.c']}" rendered="#{myType == 'C'}" /> <h:outputLabel value="#{lbl['label.type.d']}" rendered="#{myType == 'D'}" />

Instead of using the above sample, I would prefer to use two lines to achieve the same effect.
especially when the list of type are long. 
<ui:param name="typeLabel" value="label.type.#{myType}" /> <h:outputLabel value="#{lbl['typeLabel']}" />


Done!!

Monday, December 14, 2015

Google Maps' icon not rendered in Liferay 6.2

When using Google Maps in Liferay  6.2.
All the icon in Google Maps are not rendered,
This is due to css conflict in Liferay 6.2 and Google Maps.

To resolve this problem, just need to add the following css.
.aui .gm-style img {
  max-width: none;
}


Done!!

Wednesday, December 9, 2015

How to resolve Google Maps and jQuery conflict

If Google Maps and jQuery are running in the same page of an application.
There might be conflicts and the Google Maps is not working sometimes.

To resolve this problem, just need to replace the following line

<script src="https://maps.googleapis.com/maps/api/js?sensor=false">

to the function below:

<script>
function loadScript() {
 var script = document.createElement('script');
 script.type = 'text/javascript';
 script.src = '//maps.googleapis.com/maps/api/js?sensor=false';
 document.body.appendChild(script);
}
$(document).ready(loadScript());
</script>


Done!!

Geocoding address with Google Maps API

<script src="https://maps.googleapis.com/maps/api/js?sensor=false">
<script>
var geocoder;
function geocodeAddr(address) {
 if(geocoder == 'undefined' || geocoder == null) {
  geocoder = new google.maps.Geocoder();
 }
 geocoder.geocode( { 'address': address}, function(results, status) {
 if (status == google.maps.GeocoderStatus.OK) {
  alert('Latitude: ' + results[0].geometry.location.lat());
  alert('Longitude: ' + results[0].geometry.location.lng());
 } else {
   alert('Geocode was not successful for the following reason: ' + status);
 }
  });
}
</script>

<input type="button" onclick="geocodeAddr('Cameron Highlands Resort,By The Golf Course, 39000 Tanah Rata,Cameron Highlands, Pahang, Malaysia')" />

With the geocodeAddr function above, the latitude and longitude of the given address will be alerted.


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...