Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:26:34+00:00 2026-06-03T02:26:34+00:00

I made a jsf project and have the following example from http://docs.openlayers.org/library/introduction.html but as

  • 0

I made a jsf project and have the following example from http://docs.openlayers.org/library/introduction.html but as a xhtml file this wouldn’t run and as a html file it would run. How to run it with jsf and .xhtml. It runs with html though.

     <?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <script src="http://openlayers.org/api/OpenLayers.js"></script>

    </h:head>
    <h:body>
        <div style="width:100%; height:100%" id="map"></div>
        <script defer="defer" type="text/javascript">
        var map = new OpenLayers.Map('map');
        var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
        var dm_wms = new OpenLayers.Layer.WMS(
            "Canadian Data",
            "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
            {
                layers: "bathymetry,land_fn,park,drain_fn,drainage," +
                        "prov_bound,fedlimit,rail,road,popplace",
                transparent: "true",
                format: "image/png"
            },
            {isBaseLayer: false}
        );
        map.addLayers([wms, dm_wms]);
        map.zoomToMaxExtent();
      </script>
    </h:body>
</html>

Result at browser using firebug:

<head>
<body>
<div style="width: 100%; height: 100%; " id="map" class="olMap">
<div id="OpenLayers.Map_2_OpenLayers_ViewPort" style="position: relative; overflow-x: hidden; overflow-y: hidden; width: 100%; height: 100%; " class="olMapViewport olControlDragPanActive olControlZoomBoxActive olControlPinchZoomActive olControlNavigationActive">
<div id="OpenLayers.Map_2_events" style="position: absolute; width: 100%; height: 100%; z-index: 999; ">
<div id="OpenLayers.Control.PanZoom_5" style="position: absolute; left: 4px; top: 4px; z-index: 1004; " class="olControlPanZoom olControlNoSelect" unselectable="on">
<div id="OpenLayers.Control.ArgParser_6" style="position: absolute; z-index: 1004; " class="olControlArgParser olControlNoSelect" unselectable="on"/>
<div id="OpenLayers.Control.Attribution_7" style="position: absolute; z-index: 1004; " class="olControlAttribution olControlNoSelect" unselectable="on"/>
</div>
</div>
<script defer="defer" type="text/javascript">

var map = new OpenLayers.Map('map');
        var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
        var dm_wms = new OpenLayers.Layer.WMS(
            "Canadian Data",
            "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
            {
                layers: "bathymetry,land_fn,park,drain_fn,drainage," +
                        "prov_bound,fedlimit,rail,road,popplace",
                transparent: "true",
                format: "image/png"
            },
            {isBaseLayer: false}
        );
        map.addLayers([wms, dm_wms]);
        map.zoomToMaxExtent();
</script>
</body>
<script src="chrome-extension://bmagokdooijbeehmkpknfglimnifench/googleChrome.js"/>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:26:35+00:00Added an answer on June 3, 2026 at 2:26 am

    You’re executing JavaScript code inline. This means that the JavaScript code is immediately executed as the webbrowser encounters the particular code line. At that point, the <div id="map"> does not exist in the HTML DOM tree yet! The browser namely parses and executes HTML/JS code from top to bottom.

    You need to execute that JavaScript code after the <div id="map"> has been created and added to the HTML DOM tree. You could achieve it the following ways:

    1. Move the <script> block in the markup to after the <div id="map">:

      <h:head>
          <script src="http://openlayers.org/api/OpenLayers.js"></script>
      </h:head>
      <body>
          <div style="width:100%; height:100%" id="map"></div>
          <script type="text/javascript">
              var map = new OpenLayers.Map('map');
              var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
              "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
              map.addLayer(wms);
              map.zoomToMaxExtent();
          </script>
      </body>
      
    2. Use window.onload to execute the code only when the browser is finished creating the HTML DOM tree.

      <h:head>
          <script src="http://openlayers.org/api/OpenLayers.js"></script>
          <script type="text/javascript">
              window.onload = function() {
                  var map = new OpenLayers.Map('map');
                  var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                  "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
                  map.addLayer(wms);
                  map.zoomToMaxExtent();
              };
          </script>
      </h:head>
      

    This problem is not related to JSF or XHTML. It’s just basic HTML/JS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a jsf 1.1 portlet in weblogic 10.3, but in one scenario
Somebody knows an example of this? an application made with JSF 2.0 and EJB
I am using JSF and have made a custom servlet for loading images dynamically.
I have made a lot of progress in converting my JSF applications to book-markable
I'm using JSF 2.0 with GlassFish 3.0. I have the following Managed Bean: @ManagedBean
I am following the tutorial i found in this page http://javahunter.wordpress.com/2010/09/25/integrating-captcha-in-jsf-2-0/ to integrate a
I have a simple Login page made with JSF 2.0. Usually in every login
I have made few changes on this huge JSF page, which is full of
I have a problem with page rendering after migration from WAS 6.0 + JSF
Made solution change: I am trying to display a html table of data.. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.