RSS

Category Archives: JSF

Google Maps for JSF

Gone are the days when you have to open an atlas for looking some location. Thanks to GOOGLE MAPS which shows you whatever you want and that too within minutes. You can’t only see the location but also get its real time traffic details with lots of other information. Is not it cool to show your location in google map on your website or blog so that everyone can know where you are living or working?

GMaps4JSF is the extensive library provided by the google to integrate Google maps in JSF enabled pages. GMaps4JSF aims at integrating Google maps with JSF. JSF users will be also able to construct complex Streetview Panoramas and Maps with just few lines of code (JSF tags). It allows you to mark polygons, lines, HTML informatin window to your Map. GMaps4JSF is one of the JSF Mashups libraries that enables JSF users to build web 2.0 mashup applications in JSF easily.

Configuring GMap4JSF

You really don’t have to do much to use Google Maps with your JSF framework. You only need to follow these given steps:

  1. Download the gmaps4jsf-core-1.1.jar from http://code.google.com/p/gmaps4jsf/downloads/list and put it in your project’s lib folder.
  2. Include the tag library in your JSF page as follows:
    
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
    
  3. Add the following script tags in your jsp HEAD tags.
    < script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAxrVS1QxlpJHXxQ2Vxg2bJBQdkFK-tWRbPPQS4ACM1pq_e-PltxQXeyH20wQuqDaQ_6EM5UeGGVpnIw"  type="text/javascript"> < /script >
    

    The key which is used in JavaScript can be generated by signing up at http://code.google.com/apis/maps/signup.html

Embedding Google Map in JSF page.

After doing the above mentioned tasks you are all ready to insert map in your jsf page. This is the basic structure of a jsf page which is ready to incorporate Google map in it.

sampleJspPage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script
	src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAxrVS1QxlpJHXxQ2Vxg2bJBQdkFK- tWRbPPQS4ACM1pq_e-PltxQXeyH20wQuqDaQ_6EM5UeGGVpnIw"
	type="text/javascript"></script>
<title>Insert title here</title>
</head>
<body>
<f:view>
	<h:form id="form">
		<m:map zoom="16" width="500px" height="500px" address="White house">
			<m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_LEFT" />
			<m:mapControl name="GMapTypeControl" />
			<m:htmlInformationWindow htmlText="White house"></m:htmlInformationWindow>
		</m:map>
	</h:form>
</f:view>
</body>
</html>

Explanation:

<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m" %>

As described before the include directive tag imports the usable taglib and uses m as its prefix

<m:map zoom="16" width="500px" height="500px" address="White house" >
                <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_LEFT"/>
                        <m:mapControl name="GMapTypeControl"/>
                <m:htmlInformationWindow htmlText="White house"></m:htmlInformationWindow>
</m:map>
  • <m:map> is for map component. It allows us to create a map. It has various attributes which can be used to customize it. None of them are compulsory. So you are free to use them or not according to ypur needs.
    • zoom: Its default value is 11. You can change its value as per your requirements.
    • width and height: They represent the height and width of the map. The default values are 500 for both.
    • address: The address you wish the map to point to. If you use this attribute then don't use longitude or latitude attributes.
  • <m:mapControl> This component allows us to add a map control to the map component. Like if you want to add a control so that the user can zoom in or zoom out the map, or a control to switch between the types of the map.
  • htmlInformationWindowComponent: This component allows us to add an information window to the map component. Following we have provided the description about their attributes.
  • Advertisements
     
    7 Comments

    Posted by on April 21, 2010 in Java, JSF

     

    Tags: ,

    a4j:commandLink action not working in rich:datatable

    I was trying to put <a4j:commandLink>  in <rich:datatable> but it was not working. None of its action or actionListener were getting called. After wasting a lot of time and trying a lot I found that the value{Collection} used for dataTable has to be in session scoped bean. If it is in request scoped bean then the action is not getting executed.

    Owing to some performance issues I was not willing to put the bean in session so I splited the bean into two parts: one having the session related properties and other were having all the properties whose states were not needed to be maintained.

    Looks like this is an error in the implementation. Also <h:comandLink> doesnt work in <rich:datatable>. The reason is unknown till date. Hope we will find it soon.

    According to Tim Holloway of Javaranch:  Request-scope beans have very short lived. They only exist for a single request – for example, the one that presented the datatable.

    Unfortunately, when you are attempting to select a row in a datatable for further processing, that requires a second request. Since the original request was destroyed, a new request bean gets constructed. But it doesn’t have the row context that the previous request did. That’s why you need a session-scope object. So it will survive over multiple requests and maintain the datamodel and current row indicators.

     
    4 Comments

    Posted by on June 22, 2009 in JSF

     

    Server side and client side Validatons

    Server side and client side validations..

    This was asked to me in one of the java forums. I am also providing it here so that everyone can have a look. 

    Client Side Validations 
    Its quick… its fast… but it has its own limitations… 
    If you have implemented client side validations… I can easily see the source of the page and can easily crack your logic if it has some loop holes… The best example I can give you is the javaScript which was very popular used to watch pics of locked albums in orkut.

    Or I may disable the scripts in my browser and yes it is also true that all browsers do not support scripting… so at that time the code written for the validation is nullified. A user can enter any thing he wants and can produce some internal application error… or can corrupt ur database. 

    Just think that what can spammers do if the image verification is validated at the client side… 

    Now lets go to server side validations….

    Server Side Validations 
    Slow…. takes time… but are reliable…. a user can access my web application from PDA or any browser… It may or may not support scripting…. I am safe as the logic resides in my server… So i get protection against spammers, logical errors, application errors which can come due to inconsistent data.. 

    On the other hand it is more easier to write validations in any Programming language and to maintain it. It takes lesser time. 

    Hope this will give you a better understanding of what the reality is in todays unsafe world.

     
    Leave a comment

    Posted by on May 13, 2009 in JSF, Validations