I am using SPring JS 2.3.0.RELEASE (which uses dojo 1.6): I tried adding widgets to my page but it never renders
I am using pages through tiles so here's the layout template shopper.jspx
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:spring="http://www.springframework.org/tags">
<jsp:output doctype-root-element="HTML" doctype-system="about:legacy-compat" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<jsp:output omit-xml-declaration="true" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="stylesheet" type="text/css" href="/resources/dojo/resources/dojo.css"/>
<link rel="stylesheet" type="text/css" href="/resources/dijit/themes/nihilo/nihilo.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/screen.css" />
<c:url var="rootUrl" value="/resources/"/>
<script type="text/javascript" djconfig="parseOnLoad: true" src="${rootUrl}dojo/dojo.js"><jsp:text></jsp:text> </script>
<script type="text/javascript" src="${rootUrl}spring/Spring.js">
<jsp:text></jsp:text>
</script>
<script type="text/javascript" src="${rootUrl}spring/Spring-Dojo.js">
<jsp:text></jsp:text>
</script>
<script type="text/javascript">
dojo.require("dojo.parser");
</script>
<title>My Shopping</title>
</head>
<body class="nihilo">
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="submenu" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" ignore="true" />
</body>
</html>
and here's the home.jspx template which overrides body attribute
<?xml version="1.0" encoding="UTF-8" ?>
<div id="page" class="roundedCorners" xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:form="http://www.springframework.org/tags/form">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<c:url var="rootUrl" value="/resources/"/>
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.layout.ContentPane");
dojo.addOnLoad(function()
{
// create a BorderContainer as the top widget in the hierarchy
var bc = new dijit.layout.BorderContainer({style: "height: 100%; width: 100%;"});
// create a ContentPane as the left pane in the BorderContainer
var cp1 = new dijit.layout.ContentPane({
region: "left",
style: "height: 100px",
content: "hello world"
});
bc.addChild(cp1);
// create a TabContainer as the center pane in the BorderContainer,
// which itself contains two children
var tc = new dijit.layout.TabContainer({region: "center"});
var tab1 = new dijit.layout.ContentPane({title: "tab 1"}),
tab2 = new dijit.layout.ContentPane({title: "tab 2"});
tc.addChild( tab1 );
tc.addChild( tab2 );
bc.addChild(tc);
// put the top level widget into the document, and then call startup()
dojo.byId("inbox").addChild(bc.domNode);
bc.startup();
});
</script>
<div id="inbox" class="panel roundedCorners">
<div id="inboxContainer" dojo-data-type="dijit.layout.BorderContainer">
</div>
</div>
</div>
I do not see any of these widgets getting rendered when I load the page. Also the browser console shows the error:
dojo.byId("inbox").addChild is not a function
[Break On This Error]
dojo.byId("inbox").addChild(bc.domNode);
despite having the djconfig="parseOnLoad: true"
configuration in place.
Update: hereś the initial declarative syntax I tried but could not get it to work.
shopper.jspx
:
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:tiles="http://tiles.apache.org/tags-tiles"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:spring="http://www.springframework.org/tags">
<jsp:output doctype-root-element="HTML"
doctype-system="about:legacy-compat" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<jsp:output omit-xml-declaration="true" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="stylesheet"
href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dijit/themes/nihilo/nihilo.css"
media="screen"/>
<link rel="stylesheet" type="text/css" href="/resources/css/screen.css" />
<!-- load dojo and provide config via data attribute -->
<script
src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad: true">
<jsp:text></jsp:text>
</script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.AccordionPane");
</script>
<title>My Shopping</title>
</head>
<body class="nihilo">
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="submenu" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" ignore="true" />
</body>
</html>
the declarative home.jspx
I copied from dojo tutorial:
<?xml version="1.0" encoding="UTF-8" ?>
<div id="page" xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:form="http://www.springframework.org/tags/form">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<div id="inbox" data-dojo-type="dijit.layout.BorderContainer" style="width: auto; height:auto" >
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">Top pane</div>
<div data-dojo-type="dijit.layout.AccordionContainer" data-dojo-props="region:'leading'">
<div data-dojo-type="dijit.layout.AccordionPane" title="pane #1">accordion pane #1</div>
<div data-dojo-type="dijit.layout.AccordionPane" title="pane #2">accordion pane #2</div>
<div data-dojo-type="dijit.layout.AccordionPane" title="pane #3">accordion pane #3</div>
</div>
<div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region:'center'">
<div data-dojo-type="dijit.layout.ContentPane" title="tab #1">tab pane #1</div>
<div data-dojo-type="dijit.layout.ContentPane" title="tab #2">tab pane #2</div>
<div data-dojo-type="dijit.layout.ContentPane" title="tab #3">tab pane #3</div>
</div>
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'trailing'">Trailing pane</div>
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">Bottom pane</div>
</div>
</div>
in screen.css
I have defined the following:
body {
margin: 0;
padding: 0;
background-color: #EAECEE;
font-family: Verdana, sans-serif;
font-size: 12px;
}
#page {
background: #ffffff;
margin-left: auto;
margin-right: auto;
-moz-box-shadow: 0 0 5px 3px #999;
-webkit-box-shadow: 0 0 5px 3px #999;
}
And I get no widgets rendered in when I access the page.
Fixed: Was ignoring the fact about how dijit places divs, I removed the styles applyed through "page" div id and fixed the height and width as follows:
<div xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:form="http://www.springframework.org/tags/form">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<div data-dojo-type="dijit.layout.BorderContainer" style="width: auto; height:600px;" >
You are declaring a border container in markup and also trying to create one programmatically.
Try this:
Change
<div id="inboxContainer" dojo-data-type="dijit.layout.BorderContainer">
</div>
to
<div id="inboxContainer" style="width:800px; height: 600px"></div>
create the border container
var bc = new dijit.layout.BorderContainer({}, dojo.byId("inboxContainer"));
...
// dojo.byId("inbox").addChild(bc.domNode); // remove this
This line of code fails because dojo.byId returns a domNode and a domNode does not have an addChild method.
I also changed the width and height. Using height: 100% requires all the dom nodes above it in the hierarchy (html, body, roundedCorners, inbox) to also have height: 100% and I couldn't verify in the code posted that this was the case, so eliminate this potential problem for now by specifying a direct height. Once, its working, you can change it back.