Monday, December 14, 2015
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
to the function below:
Done!!
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!!
Saturday, October 24, 2015
getElementById with PrimeFaces
To get a HTML component in javascript, normally we use getElementById('componentId'),
But there are 2 constraints to get PrimeFaces component.
1. the id defined in component tag is not the actual element id in HTML.
to resolve this issue, we can use the javascript API provided by PrimeFaces to retrieve the actual HTML element id.
#{p:component('componentId')}
2. quote in the above API breaks the quote in getElementById
to resolve this problem, the quote in PF's API need to be replaced.
Done!!
But there are 2 constraints to get PrimeFaces component.
1. the id defined in component tag is not the actual element id in HTML.
to resolve this issue, we can use the javascript API provided by PrimeFaces to retrieve the actual HTML element id.
#{p:component('componentId')}
2. quote in the above API breaks the quote in getElementById
to resolve this problem, the quote in PF's API need to be replaced.
document.getElementById('#{p:component("componentId")}')
Done!!
Complex Native SQL to JPA entity
Assuming there is a ContactDetail entity.
This could be a database table or table view.
where the entity columns are actually come from different table.
This could be a database table or table view.
@Entity
public class ContactDetail {
private String name;
private String address;
private String phoneNo;
private String mobileNo;
private String email;
// getter and setter
}
the direct way to get this entity is to execute the following sql.
select name, address, phone_no, mobile_no, email from contact_detail;
another way is to select those column from different tables.
eg.
select p.name as name, a.address as address, b.phoneNo as phoneNo, b.mobileNo as mobileNo, c.email as email from person p
join address a on a.p_id = p.p_id
join phone b on b.p_id = p.p_id
join email c on c.p_id = p.p_id;
where the entity columns are actually come from different table.
which could be a view.
or SQL to return a table entity based on business requirement.
after gotten the correct SQL, we can proceed to query the JPA with the native SQL.
Done!!
after gotten the correct SQL, we can proceed to query the JPA with the native SQL.
List<ContactDetail > customers = (List<ContactDetail>)em.createNativeQuery(YOUR_NATIVE_SQL, ContactDetail.class).getResultList();
Done!!
Subscribe to:
Posts (Atom)
Popular Posts
- How to create database view with Oracle SQL Developer Data Modeler
- Primefaces fileDownload in Liferay
- How to enable CKEditor in PrimeFaces Extension
- How to backup Oracle SQL Developer Data Modeler project
- Eclipselink Cache Coordination with JBoss and JMS
- How to handle multilingual error messages for jQuery validation plugins
- Import/Export MySQL database with SQLyog
- Handling Many-to-Many relationship in relational model
- How to edit Liferay email notification templates
- How to easily embed a Google Map in your website