JSF - rendered Problem

Status
Nicht offen für weitere Antworten.

y0dA

Top Contributor
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;
	}
}
 

y0dA

Top Contributor
schade dass betreffend solchen Fragen nie was kommt, sind hier wohl hauptsächlich im Anfänger Forum unterwegs :(

btw hab ich das Problem endlich lokalisiert und behoben, falls es jemand irgendwann mal interessieren sollte einfach PM.


mfg
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
D Problem mit Update von ApacheHttpClient von 5.2 auf 5.3 Allgemeines EE 10
D Problem mit redundanten Servern Allgemeines EE 7
Azemaria JSF: Problem bei der einfachsten Applikation Allgemeines EE 2
P JPA Internal Problem Nullpointer Allgemeines EE 10
S MessageDrivenBean Problem beim Zugriff auf Stateful EJB Allgemeines EE 2
M Glassfish Deployment-Problem unter Eclipse Allgemeines EE 0
B Problem beim Lesen des Codes... Allgemeines EE 2
R JPA Problem beim Speichern eines Users Allgemeines EE 2
S WebSocket Problem Allgemeines EE 0
F Eclipse/Java EE Debug-Problem Allgemeines EE 1
G Problem: Servlet in JSP einbinden mit <jsp:include> Allgemeines EE 3
Raidri [SEAM] rich:dataTable sortBy Problem Allgemeines EE 6
T Problem mit den Beispielen von Apache Allgemeines EE 5
W JSF Validator Problem HTTP Status 500 Allgemeines EE 2
E JBoss 7.1 Datasource Problem Allgemeines EE 2
M JSP Problem -unbestimmte Anzahl von Werten Transportieren Allgemeines EE 9
S Problem mit EJB Verständnis Allgemeines EE 4
B Problem beim einbinden einer CSS in eine JSP Allgemeines EE 8
F JSP Problem mit Datenbankanbindung über Glassfishserver Allgemeines EE 4
S java Entities Problem Allgemeines EE 19
S Embedded JBoss Problem beim Deployment Allgemeines EE 4
E Session Problem Allgemeines EE 9
F problem mit nullpointer bei DB zugriff Allgemeines EE 2
A Erste Schritte... Problem mit Hibernate Allgemeines EE 15
ruutaiokwu jboss problem - work-verzeichnis muss manuell gelöscht werden??? Allgemeines EE 5
Stillmatic sendRedirect Problem! Allgemeines EE 3
M Problem mit Lookup auf EJB3 mit Glassfish Allgemeines EE 11
0 Problem mit librarys javax.servlet.http.HttpServletRequest cannot be resolved Allgemeines EE 1
X JBoss InitialContext problem Allgemeines EE 5
LordZed Problem mit dem einbinden von Bibliotheken, die sich gegenseitig verwenden Allgemeines EE 5
H GWT Problem beim Ausführen Allgemeines EE 8
Q Problem mit JMS und Weblogic 10 Allgemeines EE 5
E Performance-Problem beim ersten Request Allgemeines EE 4
G Multi User Problem Allgemeines EE 8
G Datasource Problem Allgemeines EE 1
J OOP Java Array Problem Allgemeines EE 2
T Problem mit Java Transaction API Allgemeines EE 2
D Problem mit EJB: Bean soll Objekt eigener Klasse zurückgeben Allgemeines EE 2
N JavaMail Problem Allgemeines EE 4
N JBoss Problem mit Bibliothek in unterschiedlichen Versionen Allgemeines EE 2
A Tomcat -- JSP: komisches Problem Allgemeines EE 11
W Speicher-Problem bei WebApp unter Tomcat, Struts, Hibernate Allgemeines EE 3
B Problem mit ActionListener Allgemeines EE 13
G Simples JSF-Projekt in Eclipse - Problem Allgemeines EE 9
O eclipse - tomcat: Problem bei einfachem Webservice Allgemeines EE 16
J Problem mit EJB Aufruf und DualCore Rechner Allgemeines EE 4
J ejb3.0 datenbank problem Allgemeines EE 2
J Problem mit Zurück-Button Allgemeines EE 2
T Tomcat: JNDI + JDBC Problem Allgemeines EE 3
J problem mit jsp/js Allgemeines EE 2
B Help - EJB2 - Problem mit Hybernate und "LIMIT" Allgemeines EE 6
B JSTL Problem Allgemeines EE 8
byte Tomcat Deployment Problem (HTTP Status 503) Allgemeines EE 8
S Problem mit t:selectOneRadio und ValueChangeListener Allgemeines EE 2
S Problem mit Struts und tiles Allgemeines EE 4
B Problem mit JBoss-4.2.1.GA Allgemeines EE 8
N Tiles - JSF Problem Allgemeines EE 3
M JSF & EJB "Bean not bound" Problem Allgemeines EE 4
V MYSQL JDBC;java.lang.ClassNotFoundException; Problem Eclipse Allgemeines EE 3
megachucky JMS - Problem mit TemporaryQueue Allgemeines EE 2
G Problem mit MimeType/ContentType Allgemeines EE 4
E Java Mail problem Allgemeines EE 5
Y XFire - Maven Build Problem Allgemeines EE 2
D JSP Problem mit equals? Allgemeines EE 2
A Eclipse Start-Problem Allgemeines EE 5
S JSF - Custom converter Problem Allgemeines EE 3
Y JSF Uhrzeitausgabe Problem Allgemeines EE 4
M servlet --> jsp - problem beim umstrukturieren Allgemeines EE 5
D Servlet Problem über Server Allgemeines EE 26
Zed JSF h:inputText h:outputText update Problem Allgemeines EE 2
K mysql treiber problem wenn import java.sql.* bei _servlet_ Allgemeines EE 2
S JDBC Mysql Connection Problem - datasource null Allgemeines EE 3
T Session-Problem Allgemeines EE 2
R Tiles - Layout-Problem wegen Leerzeichen Allgemeines EE 6
G Tomcat / Eclipse oder Web.xml Problem Allgemeines EE 11
S Netbeans 5.5 Visual Web Pack Problem mit INSERT und PK Allgemeines EE 4
D JSF Problem mit Action Allgemeines EE 2
F Klassen und zugriffs Problem "Help wanted"! Allgemeines EE 16
D <input type="file"> Problem Allgemeines EE 6
N Struts - Problem mit <html:link> Action Allgemeines EE 3
A Problem / Fehler beim Einbinden einer Klasse in ein JSP Allgemeines EE 20
G Session Problem Allgemeines EE 5
T Ant Compiler Problem Allgemeines EE 9
T Problem dem Zaehler in mein Java - Code Allgemeines EE 2
A Hibernate-Problem mit MySQL-Cluster Allgemeines EE 6
H Servlet problem Allgemeines EE 10
G Problem mit Benutzerverwaltung Allgemeines EE 3
S Hibernate Mapping Problem Allgemeines EE 3
S Hibernate INSERT Problem Allgemeines EE 11
S Dummes JSP-Problem Allgemeines EE 8
P EJB-Installations-Problem Allgemeines EE 4
S CSS Problem in JSP Allgemeines EE 16
C Problem mit html:optionsCollection Allgemeines EE 4
R HILFE: Problem mit JSF examples Allgemeines EE 10
R Problem mit value-expression Allgemeines EE 7
R Problem mit for-schleife in JSP tag Allgemeines EE 8
B Struts Problem: Array in JSP ausgeben (logic:iterate) Allgemeines EE 12
M Redirct-Problem Allgemeines EE 4
M Geronimo v1.1 - Problem mit EAR deployen Allgemeines EE 5
S Problem mit Servlet Allgemeines EE 11

Ähnliche Java Themen

Neue Themen


Oben