Serverside Marker events - how do they really work?

41 views
Skip to first unread message

dapooley

unread,
Nov 14, 2009, 6:10:23 AM11/14/09
to gmaps4jsf-dev
Can someone post a xhtml and bean example of serverside events for a
marker? I'm also about dragging the thing and updating its coordinates
(in the java object)?

A stipulation is that there are n number of markers on the map and any
can be dragged, not the example's 2, each with their own bean methods.

regards,

dpooley

Hazem Saleh

unread,
Nov 14, 2009, 6:42:37 AM11/14/09
to gmaps4...@googlegroups.com
http://mashups.s43.eatj.com/gmaps4jsf-examples/pages/markersServerSideEvents.jsp.source
> --
>
> You received this message because you are subscribed to the Google Groups "gmaps4jsf-dev" group.
> To post to this group, send email to gmaps4...@googlegroups.com.
> To unsubscribe from this group, send email to gmaps4jsf-de...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gmaps4jsf-dev?hl=.
>
>
>



--
Hazem Ahmed Saleh Ahmed

Author of (The Definitive Guide to Apache MyFaces and Facelets):
http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370
http://www.amazon.com/-/e/B002M052KY

Web blog: http://www.jroller.com/page/HazemBlog

[Web 2.0] Google Maps Integration with JSF:
http://code.google.com/p/gmaps4jsf/
http://www.ibm.com/developerworks/library/wa-aj-gmaps/

dapooley

unread,
Nov 16, 2009, 6:14:20 AM11/16/09
to gmaps4jsf-dev
And the bean? Thats really what I'm after.

On Nov 14, 10:42 pm, Hazem Saleh <hazem.sa...@gmail.com> wrote:
> http://mashups.s43.eatj.com/gmaps4jsf-examples/pages/markersServerSid...
>
>
>
>
>
> On Sat, Nov 14, 2009 at 1:10 PM, dapooley <dapoo...@gmail.com> wrote:
> > Can someone post a xhtml and bean example of serverside events for a
> > marker? I'm also about dragging the thing and updating its coordinates
> > (in the java object)?
>
> > A stipulation is that there are n number of markers on the map and any
> > can be dragged, not the example's 2, each with their own bean methods.
>
> > regards,
>
> > dpooley
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "gmaps4jsf-dev" group.
> > To post to this group, send email to gmaps4...@googlegroups.com.
> > To unsubscribe from this group, send email to gmaps4jsf-de...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/gmaps4jsf-dev?hl=.
>
> --
> Hazem Ahmed Saleh Ahmed
>
> Author of (The Definitive Guide to Apache MyFaces and Facelets):http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/159...http://www.amazon.com/-/e/B002M052KY
>
> Web blog:http://www.jroller.com/page/HazemBlog
>
> [Web 2.0] Google Maps Integration with JSF:http://code.google.com/p/gmaps4jsf/http://www.ibm.com/developerworks/library/wa-aj-gmaps/- Hide quoted text -
>
> - Show quoted text -

Hazem Saleh

unread,
Nov 16, 2009, 8:50:25 AM11/16/09
to gmaps4...@googlegroups.com
Excuse me but I do not understand.'And the bean'??
> For more options, visit this group at http://groups.google.com/group/gmaps4jsf-dev?hl=.
>
>
>



--
Hazem Ahmed Saleh Ahmed

Author of (The Definitive Guide to Apache MyFaces and Facelets):
http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370

dapooley

unread,
Nov 16, 2009, 7:16:45 PM11/16/09
to gmaps4jsf-dev
From the example the m:marker has:

submitOnValueChange="true"
valueChangeListener="#{map.processValueChangeForSecondMarker}"

My understanding is:
submitOnValueChange means do a serverside event.
valueChangeListener means perform some EL

#{map.processValueChangeForSecondMarker}

where

map is a bean
processValueChangeForSecondMarker is a method on that bean
(setProcessValueChangeForSecondMarker?)

What is the argument passed to processValueChangeForSecondMarker? What
does this method do internally?

Is my understanding completely wrong?

Hazem Saleh

unread,
Nov 18, 2009, 8:00:22 AM11/18/09
to gmaps4...@googlegroups.com
The processValueChangeForSecondMarker is a standard JSF value change
listener like the one in selectOneMenu for example.

The parameter to this value change listener is a value change event as
follows:

public void processValueChangeForFirstMarker(ValueChangeEvent event)
throws AbortProcessingException {
//event.getNewValue( ) returns the new marker coordinates ...
}

From this ValueChangeEvent you can get the new marker longitude and latitude.

This can be useful if you want to interact with the marker from the
server side code.

dapooley

unread,
Nov 21, 2009, 2:42:43 AM11/21/09
to gmaps4jsf-dev
Cool thanks, I'll give it a whirl. Using Seam faces-anything i dont
use at all.

dapooley

unread,
Nov 21, 2009, 8:02:14 AM11/21/09
to gmaps4jsf-dev
Added a void markerDragged(ValueChangeEvent event); method with impl
simply to print out stuff. Dragging the marker is not submitting the
form however... i am using 1.1.3 snapshot library (facelets).

<h:form id="mapForm">
<h:panelGrid columns="1" id="world">
<m:map jsVariable="jsmap" width="650px" height="450px"
autoReshape="true" latitude="#{mapsearch.defaultLatitude}" longitude="#
{mapsearch.defaultLongitude}" zoom="#{mapsearch.defaultZoom}">
<m:mapControl name="GLargeMapControl" position="G_ANCHOR_TOP_LEFT"/>
<m:mapControl name="GMapTypeControl" position="G_ANCHOR_TOP_RIGHT"/>

<c:forEach var="loc" items="#{spatialMarkers}">
<m:marker latitude="#{loc.latitude}" longitude="#{loc.longitude}"
draggable="true" submitOnValueChange="true" valueChangeListener="#
{mapsearch.markerDragged}"/>
</c:forEach>

.. closing

Hazem Saleh

unread,
Nov 23, 2009, 3:37:20 AM11/23/09
to gmaps4...@googlegroups.com
Use ui:repeat instead of c:forEach.

Hazem Saleh

unread,
Nov 23, 2009, 4:20:55 AM11/23/09
to gmaps4...@googlegroups.com
Also use the latest snapshot jar:
http://gmaps4jsf.googlecode.com/files/gmaps4jsf-1.1.3-SNAPSHOT.jar

As there was an issue that was related with the markers inside
iterators that is fixed in this snapshot.

dapooley

unread,
Nov 23, 2009, 6:52:01 AM11/23/09
to gmaps4jsf-dev
No, that didn't work.

as an extra: markers are displayed with ui:repeat but m:points inside
an m:poly... still have to use c:forEach to be picked up.

Hazem Saleh

unread,
Nov 23, 2009, 3:17:23 PM11/23/09
to gmaps4...@googlegroups.com

dapooley

unread,
Nov 24, 2009, 6:59:52 AM11/24/09
to gmaps4jsf-dev
lol thanks that was the cause and I had to go hunting because 1.1.2
had been deleted
from lib but 'kept around' in the ear.

Hazem Saleh

unread,
Nov 24, 2009, 5:07:41 PM11/24/09
to gmaps4...@googlegroups.com
u r welcome.
And thanks for using GMaps4JSF and supporting other people.

I will add you as a project contributor.
> --
>
> You received this message because you are subscribed to the Google Groups "gmaps4jsf-dev" group.
> To post to this group, send email to gmaps4...@googlegroups.com.
> To unsubscribe from this group, send email to gmaps4jsf-de...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gmaps4jsf-dev?hl=en.

dapooley

unread,
Nov 25, 2009, 4:54:07 AM11/25/09
to gmaps4jsf-dev
Further notes:

The ValueChangedEvent had no old value, just new value of a
MarkerValue? My handling method doesnt have to do anything... the
dragging redraws the polygon.

I had to change my object (lat/long are Doubles) to MarkerValues as
well as otherwise getting IllegalArgumentException or this property
not on this object when trying to take in strings/objects.

The ending jsf:

<ui:repeat var="loc" value="#{spatialMarkers}">
<m:marker latitude="#{loc.latitude}" longitude="#{loc.longitude}"
draggable="true" submitOnValueChange="true" valueChangeListener="#
{mapsearch.markerDragged}"/>
</ui:repeat>

<c:if test="#{spatialMarkers != null}">
<c:if test="#{fn:length(spatialMarkers) == 2}">
<m:polyline lineWidth="2">
<c:forEach var="loc" items="#{spatialMarkers}">
<m:point latitude="#{loc.latitude}" longitude="#
{loc.longitude}" />
</c:forEach>
</m:polyline>
</c:if>
<c:if test="#{fn:length(spatialMarkers) > 2}">
<m:polygon lineWidth="2">
<c:forEach var="loc" items="#{spatialMarkers}">
<m:point latitude="#{loc.latitude}" longitude="#
{loc.longitude}" />
</c:forEach>
</m:polygon>
</c:if>
</c:if>

#{spatialMarkers} is a list of MarkerValue instances populated tba
(next step). Using seam its just a @Out(required=true)
List<MarkerValue> spatialMarkers; to implement.

The markerDragged method exists just to allow the event firing and
value rebinding to take place.

Two markers will draw a line, three will draw an open polygon (shaded
region). A separate close event will close the polygon.

Hazem Saleh

unread,
Nov 25, 2009, 5:51:52 PM11/25/09
to gmaps4...@googlegroups.com
Do you have any comment about this approach (We can include in our
Todos) or the current one fits your requirements ?

dapooley

unread,
Nov 26, 2009, 7:02:16 AM11/26/09
to gmaps4jsf-dev
hmmm....

I've just finished the functionality that I wanted to add to the map
(a relief) which was:

1. User can click on the map and a marker will appear. That marker is
a server side object.
2. Markers are draggable.
3. A line is drawn at two markers.
4. An unclosed polygon is drawn at three markers.

The bits I added since last post were:

<m:eventListener eventName="click" jsFunction="function placeMarker
(overlay, latlng){ document.getElementById
('spatialSearchCriteria:mapCenLat').value = latlng.y;
document.getElementById('spatialSearchCriteria:mapCenLong').value =
latlng.x; document.spatialSearchCriteria.submit();}"/>

Had to write the entire javascript function in jsFunction to get the
x.y point picked up and set on the hidden form elements. Thats a pain.
I'd like a defined set of params send to any function on a map click,
or it fires a named function that a developer has to write/override.
Or something. (or someone tell me how to do it better/well).

The form submit was another pain but an active brain solved that
quickly enough using pages.xml:

<page view-id="map.jsf" action="#{bean.addSpatialMarker()}">
</page>

The hidden form params are injected into bean on the form submission
then the method to turn them into a MarkerValue happen in the page
rule.

So end result is a full serverside read/write map.

Of course, if as much of this or its requirements can be pushed into
the library then thats the best thing. Making the write side a toggle
(like the MyMaps shape mapControl button). Finding a standard API for
all jsf platforms might be tricky.

Hazem Saleh

unread,
Nov 26, 2009, 10:36:50 PM11/26/09
to gmaps4...@googlegroups.com
Can you please clarify these issues in points, and the APIs you expect
to make the life easier in your case.

I am not sure why do not you use the server side events on markers? Is
it because it does not return the old value or what?

... All what I wish to hear is an enhancement list (whether a defect
or an enhancement so we can put it in our further releases).

Finally, thanks for using GMaps4JSF.

Hazem Saleh

unread,
Nov 26, 2009, 11:02:39 PM11/26/09
to gmaps4...@googlegroups.com
I just want these points because if you find a pain while developing
Google Maps in JSF using GMaps4JSF then this means that we need more
work on such use cases to achieve the desired abstraction.

The main objective of GMaps4JSF is to minimize the effort of the JSF
developer who wants to work with Google Maps APIs inside his JSF
application.

So please list the issues (defects and enhancements), and let's
discuss them in the next days.

Thanks!

Jose Noheda

unread,
Nov 27, 2009, 1:39:24 AM11/27/09
to gmaps4...@googlegroups.com
So you need a server side event listener on map click?

Regards

dapooley

unread,
Nov 27, 2009, 1:45:59 AM11/27/09
to gmaps4jsf-dev
Lol I'm not critisising (or spelling write). I do use the serverside
marker attributes but the listener method is only there to satisfy the
tags contract: the method has no code inside it because the
markervalue's (mine, kept in the session bean list) lat and long
fields are updated by another jsf phase. So in my case the listener is
really optional and that means the tag attribute could be as well us
possible - the ui component or some part of the library could catch
the event in this case.

dapooley

unread,
Nov 27, 2009, 5:16:55 AM11/27/09
to gmaps4jsf-dev
making things easier:

1. improving jsFunction. I had to write the entire function inside the
attribute value in order to access overlay and latlng on a map click
event as otherwise no paramers are passed on if jsfFunction=doX. Can't
take advantage of a script or formatting nicities.

2. server side map events. Clicking a map to add a marker should be a
common activity for write operations.

Value added:

This is where the library can shine and get a real differentiator by
having additional map controls for various acvities such as

i. drawing
ii. shapes
iii. distance calculation

etc.

Jose Noheda

unread,
Nov 27, 2009, 6:46:00 AM11/27/09
to gmaps4...@googlegroups.com
On Fri, Nov 27, 2009 at 11:16 AM, dapooley <dapo...@gmail.com> wrote:
making things easier:

1. improving jsFunction. I had to write the entire function inside the
attribute value in order to access overlay and latlng on a map click
event as otherwise no paramers are passed on if jsfFunction=doX. Can't
take advantage of a script or formatting nicities.

No, not really. Read about args in JS.
 
2. server side map events. Clicking a map to add a marker should be a
common activity for write operations.
 
Agree
 
Value added:

This is where the library can shine and get a real differentiator by
having additional map controls for various acvities such as

i. drawing
ii. shapes
iii. distance calculation

etc.

Hazem Saleh

unread,
Nov 27, 2009, 6:36:20 AM11/27/09
to gmaps4...@googlegroups.com
These are good enhancement points, I will include in the next release notes.

Thanks and I am really happy that the community needs more and more
abstraction on the current components.

Hazem Saleh

unread,
Nov 27, 2009, 7:43:13 AM11/27/09
to gmaps4...@googlegroups.com
I added this issue on defining server side event on the map:
http://code.google.com/p/gmaps4jsf/issues/detail?id=87

please review its bits and tell me if you still need to see more features.

clyd

unread,
Dec 6, 2009, 4:44:44 PM12/6/09
to gmaps4jsf-dev
Hi,
can you please help me out on how to set the valueChangeListener for a
marker on server-side? I.e. how to write the method binding stuff..? I
guess it might be another basic JSF thing, but it is all new to me..

Many thanks in advance!

Best regards,
Jukka
> > For more options, visit this group athttp://groups.google.com/group/gmaps4jsf-dev?hl=.
>
> --
> Hazem Ahmed Saleh Ahmed
>
> Author of (The Definitive Guide to Apache MyFaces and Facelets):http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/159...http://www.amazon.com/-/e/B002M052KY

Hazem Saleh

unread,
Dec 13, 2009, 2:24:02 AM12/13/09
to gmaps4...@googlegroups.com
sorry for being late in reply.
I just see your message:

please check the following example:
http://mashups.s43.eatj.com/gmaps4jsf-examples/pages/markersServerSideEvents.jsp.source

As you can see, you will just indicate your valueChangeListener and bind it to your managed bean method
as what you usually do with selectOneMenu.

I can write an article about this to illustrate in more details for all JSF beginners as well.

Thank you for pointing this out!

For more options, visit this group at http://groups.google.com/group/gmaps4jsf-dev?hl=en.





--
Hazem Ahmed Saleh Ahmed

Author of (The Definitive Guide to Apache MyFaces and Facelets):
Reply all
Reply to author
Forward
0 new messages