Hello!

I have a javascript function, 

function onGetLatLng(gLatLng){

        if(gLatLng == null) {
                alert("Sorry, we couldn't find this address.");
                return false;
        }
        
        new Ajax.Request(urlGetGroupsOnLocation, { onSuccess: updatePage,
                parameters: 'lat='+gLatLng.lat() + '&lng=' + gLatLng.lng() + 
'&radius=' +
50000});
}

..which is calling urlGetGroupsOnLocation in my class:

        public Object onGetGroupsOnLocation(){
                System.out.println("onGetGroupsOnLocation");    

                if (request.getParameter("lat") != null && 
request.getParameter("lng") !=
null){
                        Double lat = Double.parseDouble( 
request.getParameter("lat") );
                        Double lng = Double.parseDouble( 
request.getParameter("lng") );
                        Double radiusInMeters = Double.parseDouble(
request.getParameter("radius") ) / 2;
                        
                        Geometry location = GeometryService.getPolygon(new 
GeoPoint(lat, lng),
radiusInMeters.intValue());
                        groups = groupService.getGroupsOnLocation(location);
                        
                        System.out.println("returnBody");                       
        
                        return zone.getBody(); 
                }
                System.out.println("null");
                return null;
        }

but, .. i dont know how to update the zone now with tapestry. zone.getBody
does not work. The only thing i managed was a hard approach within JS:

window.location.reload();


my full class:


package com.airwriting.frontend.pages.group;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;


import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

import se.unbound.tapestry.breadcrumbs.BreadCrumb;

import com.airwriting.configuration.Configuration;
import com.airwriting.domain.GeoPoint;
import com.airwriting.domain.Group;
import com.airwriting.service.GeometryService;
import com.airwriting.service.data.GroupService;
import com.vividsolutions.jts.geom.Geometry;

@Import(library = {
                "context:js/browselocalgroups.js" 
        })
@BreadCrumb(titleKey="group/ListLocalGroups")
public class ListLocalGroups {
        
        @Inject
        private GroupService groupService;
        @Inject
        private JavaScriptSupport jsSupport;
        @Inject
        private Request request;
        @Inject
        private ComponentResources componentResources;
        @Property
        private Geometry location;
        

        @Inject
        private Configuration configuration;

        @Property
        private String googleMapsKey;
        
        @Persist
        @Property
        private List<Group> groups;
                
        @InjectComponent
        private Zone zone;
        
        @Property
        private Group curGroup;
        
        @Persist        
        private Date lastUpdate;
        
        public void setupRender() {
                
                
                if (request.getServerName().endsWith(".net")){
                        googleMapsKey = 
configuration.getString("googleMaps.key.net");
                }else if (request.getServerName().endsWith(".de")){
                        googleMapsKey = 
configuration.getString("googleMaps.key.de");
                }else if (request.getServerName().endsWith(".at")){
                        googleMapsKey = 
configuration.getString("googleMaps.key.at");
                }
                else {//.com
                        googleMapsKey = 
configuration.getString("googleMaps.key");                      
                }
                
                System.out.println("setupRender");
                
                if (groups == null || groups.size() == 0){
                        
                        System.out.println("createEventLink");
                        Link linkGetGroupsOnLocation =
componentResources.createEventLink("getGroupsOnLocation");
                        groups = new ArrayList<Group>();
                        
                        if (lastUpdate == null ){
                                updatePage(linkGetGroupsOnLocation);
                                 
                        }else if (minutesDiff(lastUpdate, new Date()) > 1){
                                updatePage(linkGetGroupsOnLocation);
                                 
                        }

                }else {
                        
                }
        }

        private void updatePage(Link linkGetGroupsOnLocation) {
                jsSupport.addScript(
                                "init('%s');", 
                                linkGetGroupsOnLocation.toURI());
                lastUpdate = new Date();
        }
        
        
        
        public Object onGetGroupsOnLocation(){
                System.out.println("onGetGroupsOnLocation");    

                if (request.getParameter("lat") != null && 
request.getParameter("lng") !=
null){
                        Double lat = Double.parseDouble( 
request.getParameter("lat") );
                        Double lng = Double.parseDouble( 
request.getParameter("lng") );
                        Double radiusInMeters = Double.parseDouble(
request.getParameter("radius") ) / 2;
                        
                        Geometry location = GeometryService.getPolygon(new 
GeoPoint(lat, lng),
radiusInMeters.intValue());
                        groups = groupService.getGroupsOnLocation(location);
                        
                        System.out.println("returnBody");                       
        
                        return zone.getBody(); 
                }
                System.out.println("null");
                return null;
        }
        
        private static int minutesDiff(Date earlierDate, Date laterDate)
        {
            if( earlierDate == null || laterDate == null ) return 0;

            return (int)((laterDate.getTime()/60000) -
(earlierDate.getTime()/60000));
        }
        
}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/updating-a-zone-from-javascript-tp5716428.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to