JSF - rendered Problem

y0dA

Erfahrenes Mitglied
Hoi!
Mein leidiges Thema geht weiter..
Also vorweg möchte ich die Google Map in eine Applikation einbauen (habe ich schon in anderen Projekten geschafft) jedoch behindert mich bei meiner momentanen Implementierung dass die Google Map eine Subview ist und dadurch der Initialisierungsprozess (um Punkte in die Karte zu laden) nicht durchgeführt wird. Ich verwende myFaces 1.1.3, Richfaces und Ajax4Jsf.

Im Prinzip hatte ich es mir so gedacht (und dies funktioniert auch wenn die map von Anfang an enabled wäre) dass ich bei der Initialisierung der Map (setMap() Methode der Klasse Bean.java) den Parameter "oninit" auf "initializePoints" setze, welches eine javascript function ist (subview2.jsp - unter dem Tag "<a4j") und in dieser Funktion werden eben die Werte der Punkte aus der Bean geholt und danach wird die Javascript Funktion "createPoints(data)" aufgerufen (zu finden unter page2.jsp).

--> Dies funktioniert leider nicht da somit nie die "oninit" Funktion der Google Map aufgerufen wird, wenn die Jsp subview.jsp disabled - sprich nicht gerendered wird.

Das Problem liegt einfach darin dass ich wenn die Map gerenderd wird ich dieselbe eben noch mit den Punkten über JavaScript versorgen muss.

Hier mal Beispielcode welcher das Problem beschreibt:

page2.jsp (welche die anderen als subviews beinhaltet):
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
    <head>
        <title>Hello World</title>
        <script type="text/javascript" src="../../script/block.js"></script>
<script type="text/javascript">
   //<![CDATA[
   
  	function createPoints(data) {
		for (var i = 0; data.length; i++) {
			var point = new GLatLng(data[i].lat, data[i].lng);
			map.addOverlay(createMarkerWithIdentifier(point, data[i].desc));
		}		
   	} 
   	
   	function createMarkerWithIdentifier(point, desc) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(desc);
	  });
	  return marker;
	}  	
	
	function createOnePoint() {
		map.openInfoWindow(map.getCenter(),
        	document.createTextNode("Hello, world"));
	}
    //]]>
</script>
    </head>
    <body>
        <f:view>        
            <f:verbatim><h2></f:verbatim>
            <h:outputText value="Hello #{helloWorldBacking.name}. We hope you enjoy Apache MyFaces"/>
            <f:verbatim></h2></f:verbatim>

            <h:form id="page2">
              <h:commandLink id="link1" action="back">
                <h:outputText id="linkText" value="GO HOME"/>
              </h:commandLink>
            </h:form>
            
         <h:panelGroup>
			<%@include file="subview1.jsp"%>
		</h:panelGroup>
            
        </f:view>
    </body>
</html>

erste subview (welche die google map als subview beinhaltet):
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:subview id="subviewWhichIncludeSubview">        
            <f:verbatim><h2></f:verbatim>
            <h:outputText value="subviewWhichIncludeSubview"/>
            <f:verbatim></h2></f:verbatim>
             
             <h:form id="subview1">
              
            <h:panelGroup rendered="#{gmBean.activate}">
				<%@include file="subview2.jsp"%>
			</h:panelGroup>
		
			<h:commandButton value="aktivieren" actionListener="#{gmBean.doActivate}">
			</h:commandButton>
            </h:form>
        
            
</f:subview>

google map subview:
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> 

<f:subview id="subview2">
	<h:panelGrid columns="2">
		<rich:gmap binding="#{gmBean.map}"/>	
	</h:panelGrid>        
	<h:form id="subview2">   
		<a4j:jsFunction name="initializePoints" data="#{gmBean.points}"
			oncomplete="createPoints(data)">
		</a4j:jsFunction>
	</h:form> 
</f:subview>

servlet:
Code:
package org.richfaces.demo.gmap;

import java.util.ArrayList;
import java.util.HashMap;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.richfaces.component.html.HtmlGmap;


public class Bean {
	
	//------------------------------------------------------------------------------------------------------------------
	// FIELDS
	//------------------------------------------------------------------------------------------------------------------
	
	/** google map */
	private HtmlGmap map;

	/** whole authorization for google map */
	private String gmapKey;
	
	/** google key for this application */
	private static final String GOOGLE_API_KEY = 
		"ABQIAAAAU5IDceLqYFSp4k84FYLxyRTwM0brOpm-All5BF6PoaKBxRWWERSDiAIGyx-hbmMfA3v7tHF4Tvwfaw";
	
	/** application url */
	private static final String APPL_URL = "localhost:8080";
	
	/** host string */
	private static final String HOST = "host";
	
	/** error message if key is not generated for <code>Bean.APPL_URL</code> */
	private static final String KEY_ERROR_MSG =
		"get the key for your domain at http://www.google.com/apis/maps/signup.html";
	
	/** style of the google map */
	private static final String MAP_STYLE = "width:400px;height:400px";
	
	/** java script method which load points for google map - ajax4jsf script */
	private static final String LOAD_POINTS_INITIALIZE = "initializePoints()";
	
	/** google map initial zoom */
	private static final String MAP_ZOOM_INITIAL = "5";
	
	/** google map initial lattidude value */
	private static final String MAP_LATTIDUDE_INITIAL = "37.4419";
	
	/** google map initial longtidude value */
	private static final String MAP_LONGTIDUDE_INITIAL = "-122.1419";
	
	/** google map initial type of show value */
	private static final String MAP_TYPE_INITIAL = "G_NORMAL_MAP";
	
	/** google map variable for java script */
	private static final String MAP_GMAP_VAR = "map";
	
	/** contains google map points data */
	private ArrayList<Place> points;
	
	private String longtitude;
	
	private String lattidude;
	
	private Boolean activate = false;
	
	//------------------------------------------------------------------------------------------------------------------
	// CONSTRUCTOR
	//------------------------------------------------------------------------------------------------------------------

	/**
	 * constructor
	 */
	public Bean() {
		this.points = this.loadDataForMap();
	}
	
	//------------------------------------------------------------------------------------------------------------------
	// HELPER METHODS
	//------------------------------------------------------------------------------------------------------------------
	
	/**
	 * dummy methode
	 */
	public void doActivate(ActionEvent ae) {
		if (this.activate.booleanValue()) {
			this.activate = false;
		} else {
			this.activate = true;
		}
	}
	
	/**
	 * reset user input from view
	 */
	private void resetInput() {
		this.longtitude = "";
		this.lattidude = "";
	}
	
	/**
	 * UI method
	 * add a new marker
	 * @param ae action event
	 */
	@Deprecated //immo noch nicht ausprobiert siehe jsp addMarker.jsp
	public void addNewMarker(ActionEvent ae) {
		/* add marker */
		this.points.add(new Place("id", "pic", this.lattidude, this.longtitude, 10, "beschreibung"));
		/* reset user input */
		this.resetInput();
	}
	
	/**
	 * load points for google map
	 * @return tmp loaded point data for map
	 */
	private ArrayList<Place> loadDataForMap() {
		ArrayList<Place> tmp = new ArrayList<Place>();
		tmp.add(new Place ("goldengate", "/org/richfaces/demo/gmap/images/gold.gif", "37.81765", "-122.477603" , 14,
				"Golden Gate  Bridge, San Francisco"));
		tmp.add(new Place ("eiffeltower", "/org/richfaces/demo/gmap/images//tower.gif", "48.858489", "2.295295" , 17,
				"Eiffel Tower, Paris"));
		tmp.add(new Place ("pyramids", "/org/richfaces/demo/gmap/images/pyramids.gif", "29.977785", "31.132915" , 15,
				"Pyramids of Egypt, Giza"));
		tmp.add(new Place ("exadel", "/org/richfaces/demo/gmap/images/exadel.gif", "37.971796", "-122.042334" , 18,
				"Headquarter of Exadel, Inc , Concord"));
		
				
		return tmp;
	}
	
	/**
	 * create the whole google map key
	 * @return key generated key
	 */
	private String createKey() {
		HashMap<String, String> hosts = new HashMap<String, String>();
		hosts.put(Bean.APPL_URL, Bean.GOOGLE_API_KEY);
		ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
		String host = (String)ec.getRequestHeaderMap().get(Bean.HOST);
		String key = hosts.get(host);
		if (key != null) 
			return key;
		else
			return Bean.KEY_ERROR_MSG;	
	}
	
	/**
	 * dummy button - just test
	 *
	 */
	public void doSomething() {
		System.out.println("laft");
		this.map.getGmapVar();
		this.map.getAttributes();
	}
	
	//------------------------------------------------------------------------------------------------------------------
	// GETTER/SETTER
	//------------------------------------------------------------------------------------------------------------------

	/**
	 * getter method
	 * @return gmapKey
	 */
	public String getGmapKey() {
		if (gmapKey == null) {
			gmapKey = createKey();
		}
		return gmapKey;
	}

	/**
	 * setter method
	 * @param gmapKey
	 */
	public void setGmapKey(final String gmapKey) {
		this.gmapKey = gmapKey;
	}

	/**
	 * getter method
	 * @return map
	 */
	public HtmlGmap getMap() {
		return this.map;
	}

	/**
	 * setter method
	 * also initialized google map 
	 * @param map
	 */
	public void setMap(final HtmlGmap map) {
		if (this.map == null) {
			this.map = map;
			this.map.setGmapVar(Bean.MAP_GMAP_VAR);
			this.map.setOninit(Bean.LOAD_POINTS_INITIALIZE);
			this.map.setZoom(Bean.MAP_ZOOM_INITIAL);
			this.map.setStyle(Bean.MAP_STYLE);
			this.map.setGmapKey(this.getGmapKey());
			this.map.setLat(Bean.MAP_LATTIDUDE_INITIAL);
			this.map.setLng(Bean.MAP_LONGTIDUDE_INITIAL);
			this.map.setMapType(Bean.MAP_TYPE_INITIAL);
		} else {
			this.map = map;
		}
	}

	/**
	 * getter method
	 * @return points
	 */
	public ArrayList<Place> getPoints() {
		return this.points;
	}
	
	/**
	 * setter method
	 * @param points
	 */
	public void setPoints(final ArrayList<Place> points) {
		this.points = points;
	}

	public String getLongtitude() {
		return longtitude;
	}

	public void setLongtitude(String longtitude) {
		this.longtitude = longtitude;
	}

	public String getLattidude() {
		return lattidude;
	}

	public void setLattidude(String lattidude) {
		this.lattidude = lattidude;
	}

	public Boolean getActivate() {
		return activate;
	}

	public void setActivate(Boolean activate) {
		this.activate = activate;
	}
}
 
Hab das Problem endlich lokalisiert und behoben, falls es jemand irgendwann mal interessieren sollte einfach PM (ausführlichere Antwort).


mfg
 
Mosfat hat gesagt.:
Hey,

ich weiß dein Beitrag ist einbischen älter, aber ich habe ein ähnliches PRoblem. Wie hast du das Problem gelöst?
Hallo!
Ist tatsächlich schon etwas her, ich habe es damals unter Hilfenahme von ajax4jsf und richfaces umgesetzt, wie aus meinem Post eh schon hervorgeht. Ich glaube mich zu erinnern dass es an dem form-tag in der subview ging, bin mir aber nicht mehr sicher. Weiters müssen auch die Javascripts sowie die ajax4jsf funktionen in der "Haupt-Jsp" und nicht in der Subview stehen. Betreffend meiner beiden Jsps (siehe unten) kann subview 2 auch mit subview 1 getauscht werden (sprich ich hab hier nur testweise 2 subviews) Hier der funktionierende Testcode (hoffe ich zumindest!):

Haupt-JSP:
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> 
<html>
    <head>
        <title>Hello World</title>
        <script type="text/javascript" src="../../script/block.js"></script>
		<script type="text/javascript" src="../../script/default.js"></script>
<script type="text/javascript">
   //<![CDATA[
   
  	function createPoints(data) {
		for (var i = 0; data.length; i++) {
			var point = new GLatLng(data[i].lat, data[i].lng);
			map.addOverlay(createMarkerWithIdentifier(point, data[i].desc));
		}		
   	} 
   	
   	function createMarkerWithIdentifier(point, desc) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(desc);
	  });
	  return marker;
	}  	
    //]]>
</script>
</head> 
    <body>
        <f:view>        
            <f:verbatim><h2></f:verbatim>
            <h:outputText value="Hello #{helloWorldBacking.name}. We hope you enjoy Apache MyFaces"/>
            <f:verbatim></h2></f:verbatim>

            <h:form id="page2Form">
              <h:commandLink id="link1" action="back">
                <h:outputText id="linkText" value="GO HOME"/>
              </h:commandLink>
              <h:panelGroup>
              	<%@include file="subview1.jsp"%>
              </h:panelGroup>
	    		<a4j:jsFunction name="initializePoints" data="#{gmBean.points}"
		    		oncomplete="createPoints(data)">
			    </a4j:jsFunction>
			    
			    <h:commandButton value="show map" actionListener="#{gmBean.doActivate}" type="submit"/>
		    </h:form>
        </f:view>
    </body>
</html>

Subview1:
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<f:subview id="subview1">        
	 <h:panelGroup rendered="#{gmBean.activate}">
    	<%@include file="subview2.jsp"%>
	</h:panelGroup>       
</f:subview>

Subview2:
Code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<f:subview id="subview1">        
	<h:panelGrid columns="1">
		<rich:gmap binding="#{gmBean.map}"/>	
	</h:panelGrid>           
</f:subview>

jsf config:
Code:
<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd" >

<faces-config>
	
	<!-- managed beans of the simple hello world app -->
	<managed-bean>
		<managed-bean-name>helloWorldBacking</managed-bean-name>
		<managed-bean-class>org.apache.myfaces.blank.HelloWorldBacking</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	
	<managed-bean>
	  <managed-bean-name>gmBean</managed-bean-name>
	  <managed-bean-class>org.richfaces.demo.gmap.Bean</managed-bean-class>
	  <managed-bean-scope>session</managed-bean-scope>
	 <!-- <managed-property>
	   <property-name>zoom</property-name>
	   <property-class>java.lang.String</property-class>
	   <value></value>
	  </managed-property>-->
 	</managed-bean>
	
	<!-- navigation rules for helloWorld.jsp -->
	<navigation-rule>
		<from-view-id>/helloWorld.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/page2.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	
	<!-- navigation rules for page2.jsp -->
	<navigation-rule>
		<from-view-id>/page2.jsp</from-view-id>
		<navigation-case>
			<from-outcome>back</from-outcome>
			<to-view-id>/helloWorld.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>

web.xml:
Code:
<?xml version="1.0"?>

<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <description>MyProject web.xml</description>

    <context-param>
        <description>Comma separated list of URIs of (additional) faces config files.
            (e.g. /WEB-INF/my-config.xml)
            See JSF 1.0 PRD2, 10.3.2
            Attention: You do not need to put /WEB-INF/faces-config.xml in here.
        </description>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/examples-config.xml</param-value>
    </context-param>
    <context-param>
        <description>State saving method: "client" or "server" (= default)
            See JSF Specification 2.5.3</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <description>Only applicable if state saving method is "server" (= default).
            Defines the amount (default = 20) of the latest views are stored in session.</description>
        <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
        <param-value>20</param-value>
    </context-param>
    <context-param>
        <description>Only applicable if state saving method is "server" (= default).
            If true (default) the state will be serialized to a byte stream before it
            is written to the session.
            If false the state will not be serialized to a byte stream.</description>
        <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>Only applicable if state saving method is "server" (= default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
            If true (default) the serialized state will be compressed before it
            is written to the session. If false the state will not be compressed.</description>
        <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>This parameter tells MyFaces if javascript code should be allowed in the
            rendered HTML output.
            If javascript is allowed, command_link anchors will have javascript code
            that submits the corresponding form.
            If javascript is not allowed, the state saving info and nested parameters
            will be added as url parameters.
            Default: "true"</description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <description>If true, rendered HTML code will be formatted, so that it is "human readable".
            i.e. additional line separators and whitespace will be written, that do not
            influence the HTML code.
            Default: "true"</description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>If true, a javascript function will be rendered that is able to restore the
            former vertical scroll on every request. Convenient feature if you have pages
            with long lists and you do not want the browser page to always jump to the top
            if you trigger a link or button action that stays on the same page.
            Default: "false"</description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>Used for encrypting view state. Only relevant for client side
            state saving. See MyFaces wiki/web site documentation for instructions
            on how to configure an application for diffenent encryption strengths.
        </description>
        <param-name>org.apache.myfaces.SECRET</param-name>
        <param-value>NzY1NDMyMTA=</param-value>
    </context-param>

    <context-param>
        <description>
            Validate managed beans, navigation rules and ensure that forms are not nested.
        </description>
        <param-name>org.apache.myfaces.VALIDATE</param-name>
        <param-value>true</param-value>
    </context-param>
    
    <context-param>
        <description>
            Treat readonly same as if disabled attribute was set for select elements.
        </description>
        <param-name>org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS</param-name>
        <param-value>true</param-value>
    </context-param>    
    
    <context-param>
        <description>
            Use the defined class as the class which will be called when a resource is added to the
            ExtensionFilter handling. Using StreamingAddResource here helps with performance. If you want to add
            custom components and want to use the ExtensionFilter, you need to provide your custom implementation here.
        </description>
        <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
        <param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource</param-value>
    </context-param>        

    <context-param>
        <description>
            Virtual path in the URL which triggers loading of resources for the MyFaces extended components
            in the ExtensionFilter.
        </description>
        <param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
        <param-value>/faces/myFacesExtensionResource</param-value>
    </context-param>
    
    <context-param>
        <description>
            Check if the extensions-filter has been properly configured.
        </description>
        <param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
        <param-value>true</param-value>
    </context-param>    

    <context-param>
        <description>
            Define partial state saving as true/false.
        </description>
        <param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
        <param-value>false</param-value>
    </context-param>    

    <!-- Extensions Filter -->
    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
        <init-param>
            <description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                10k - 10 KB
                10m - 10 MB
                1g - 1 GB</description>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
        </init-param>
        <init-param>
            <description>Set the threshold size - files
                below this limit are stored in memory, files above
                this limit are stored on disk.

                Format: 10 - 10 bytes
                10k - 10 KB
                10m - 10 MB
                1g - 1 GB</description>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

    <!-- Listener, to allow Jetty serving MyFaces apps -->
    <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <!-- Welcome files -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

	<context-param> 
	  <param-name>org.ajax4jsf.SKIN</param-name> 
	  <param-value>blueSky</param-value> 
	</context-param> 
	<filter> 
	  <display-name>Ajax4jsf Filter</display-name> 
	  <filter-name>ajax4jsf</filter-name> 
	  <filter-class>org.ajax4jsf.Filter</filter-class> 
	</filter> 
	<filter-mapping> 
	  <filter-name>ajax4jsf</filter-name> 
	   <servlet-name>Faces Servlet</servlet-name>
	   <dispatcher>REQUEST</dispatcher>
	   <dispatcher>FORWARD</dispatcher>
	   <dispatcher>INCLUDE</dispatcher>
	</filter-mapping>

</web-app>

Bean.java:
Code:
package org.richfaces.demo.gmap;

import java.util.ArrayList;
import java.util.HashMap;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.richfaces.component.html.HtmlGmap;


public class Bean {
	
	//------------------------------------------------------------------------------------------------------------------
	// FIELDS
	//------------------------------------------------------------------------------------------------------------------
	
	/** google map */
	private HtmlGmap map;

	/** whole authorization for google map */
	private String gmapKey;
	
	/** google key for this application */
	private static final String GOOGLE_API_KEY = 
		"ABQIAAAAU5IDceLqYFSp4k84FYLxyRTwM0brOpm-All5BF6PoaKBxRWWERSDiAIGyx-hbmMfA3v7tHF4Tvwfaw";
	
	/** application url */
	private static final String APPL_URL = "localhost:8080";
	
	/** host string */
	private static final String HOST = "host";
	
	/** error message if key is not generated for <code>Bean.APPL_URL</code> */
	private static final String KEY_ERROR_MSG =
		"get the key for your domain at http://www.google.com/apis/maps/signup.html";
	
	/** style of the google map */
	private static final String MAP_STYLE = "width:400px;height:400px";
	
	/** java script method which load points for google map - ajax4jsf script */
	private static final String LOAD_POINTS_INITIALIZE = "initializePoints()";
	
	/** google map initial zoom */
	private static final String MAP_ZOOM_INITIAL = "5";
	
	/** google map initial lattidude value */
	private static final String MAP_LATTIDUDE_INITIAL = "37.4419";
	
	/** google map initial longtidude value */
	private static final String MAP_LONGTIDUDE_INITIAL = "-122.1419";
	
	/** google map initial type of show value */
	private static final String MAP_TYPE_INITIAL = "G_NORMAL_MAP";
	
	/** google map variable for java script */
	private static final String MAP_GMAP_VAR = "map";
	
	/** contains google map points data */
	private ArrayList<Place> points;
	
	private String longtitude;
	
	private String lattidude;
	
	private Boolean activate = false;
	
	//------------------------------------------------------------------------------------------------------------------
	// CONSTRUCTOR
	//------------------------------------------------------------------------------------------------------------------

	/**
	 * constructor
	 */
	public Bean() {
		this.points = this.loadDataForMap();
	}
	
	//------------------------------------------------------------------------------------------------------------------
	// HELPER METHODS
	//------------------------------------------------------------------------------------------------------------------
	
	/**
	 * dummy klasse zum testen warum pkt bei emoris nicht geladen werden
	 */
	public void doActivate(ActionEvent ae) {
		if (this.activate.booleanValue()) {
			this.activate = false;
		} else {
			this.activate = true;
		}
	}
	
	/**
	 * reset user input from view
	 */
	private void resetInput() {
		this.longtitude = "";
		this.lattidude = "";
	}
	
	/**
	 * UI method
	 * add a new marker
	 * @param ae action event
	 */
	@Deprecated //immo noch nicht ausprobiert siehe jsp addMarker.jsp
	public void addNewMarker(ActionEvent ae) {
		/* add marker */
		this.points.add(new Place("id", "pic", this.lattidude, this.longtitude, 10, "beschreibung"));
		/* reset user input */
		this.resetInput();
	}
	
	/**
	 * load points for google map
	 * @return tmp loaded point data for map
	 */
	private ArrayList<Place> loadDataForMap() {
		ArrayList<Place> tmp = new ArrayList<Place>();
		tmp.add(new Place ("goldengate", "/org/richfaces/demo/gmap/images/gold.gif", "37.81765", "-122.477603" , 14,
				"Golden Gate  Bridge, San Francisco"));
		tmp.add(new Place ("eiffeltower", "/org/richfaces/demo/gmap/images//tower.gif", "48.858489", "2.295295" , 17,
				"Eiffel Tower, Paris"));
		tmp.add(new Place ("pyramids", "/org/richfaces/demo/gmap/images/pyramids.gif", "29.977785", "31.132915" , 15,
				"Pyramids of Egypt, Giza"));
		tmp.add(new Place ("exadel", "/org/richfaces/demo/gmap/images/exadel.gif", "37.971796", "-122.042334" , 18,
				"Headquarter of Exadel, Inc , Concord"));
		
		//test hinzufügen einer emoris site koordinate 
		tmp.add(new Place ("Berchtesgarden", "pic nix gibt", "47.61667", "12.58333" , 10,
				"emoris site,Berchtesgarden emoris site"));
		//test
		
		tmp.add(new Place ("Schöffelgasse ", "pic nix gibt", "48.386393", "16.219623" , 10,
		"AUSTRIA ALDA AUSTRIA"));
		
		return tmp;
	}
	
	/**
	 * create the whole google map key
	 * @return key generated key
	 */
	private String createKey() {
		HashMap<String, String> hosts = new HashMap<String, String>();
		hosts.put(Bean.APPL_URL, Bean.GOOGLE_API_KEY);
		ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
		String host = (String)ec.getRequestHeaderMap().get(Bean.HOST);
		String key = hosts.get(host);
		if (key != null) 
			return key;
		else
			return Bean.KEY_ERROR_MSG;	
	}
	
	/**
	 * dummy button - just test
	 *
	 */
	public void doSomething() {
		System.out.println("laft");
		this.map.getGmapVar();
		this.map.getAttributes();
	}
	
	//------------------------------------------------------------------------------------------------------------------
	// GETTER/SETTER
	//------------------------------------------------------------------------------------------------------------------

	/**
	 * getter method
	 * @return gmapKey
	 */
	public String getGmapKey() {
		if (gmapKey == null) {
			gmapKey = createKey();
		}
		return gmapKey;
	}

	/**
	 * setter method
	 * @param gmapKey
	 */
	public void setGmapKey(final String gmapKey) {
		this.gmapKey = gmapKey;
	}

	/**
	 * getter method
	 * @return map
	 */
	public HtmlGmap getMap() {
		return this.map;
	}

	/**
	 * setter method
	 * also initialized google map 
	 * @param map
	 */
	public void setMap(final HtmlGmap map) {
		if (this.map == null) {
			this.map = map;
			this.map.setGmapVar(Bean.MAP_GMAP_VAR);
			this.map.setOninit(Bean.LOAD_POINTS_INITIALIZE);
			this.map.setZoom(Bean.MAP_ZOOM_INITIAL);
			this.map.setStyle(Bean.MAP_STYLE);
			this.map.setGmapKey(this.getGmapKey());
			this.map.setLat(Bean.MAP_LATTIDUDE_INITIAL);
			this.map.setLng(Bean.MAP_LONGTIDUDE_INITIAL);
			this.map.setMapType(Bean.MAP_TYPE_INITIAL);
		} else {
			this.map = map;
		}
	}

	/**
	 * getter method
	 * @return points
	 */
	public ArrayList<Place> getPoints() {
		return this.points;
	}
	
	/**
	 * setter method
	 * @param points
	 */
	public void setPoints(final ArrayList<Place> points) {
		this.points = points;
	}

	public String getLongtitude() {
		return longtitude;
	}

	public void setLongtitude(String longtitude) {
		this.longtitude = longtitude;
	}

	public String getLattidude() {
		return lattidude;
	}

	public void setLattidude(String lattidude) {
		this.lattidude = lattidude;
	}

	public Boolean getActivate() {
		return activate;
	}

	public void setActivate(Boolean activate) {
		this.activate = activate;
	}
}

Ich hoffe das hilft dir, falls nicht schreib mich einfach nochmal an.

mfg
 
Zurück