Login Register

Problem working with Dojo + Struts2.

Hi All,

I have below code in (login.jsp) file.

<%@ taglib prefix="s" uri="/struts-tags" %>

<head>

<script type="text/javascript">
djConfig = { parseOnLoad: true }
</script>
<script src="dojoroot/dojo/dojo.js"></script>
<style type="text/css">
@import "dojoroot/dijit/themes/tundra/tundra.css";
@import "dojoroot/dojo/resources/dojo.css";
</style>
<script type="text/javascript">
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
</script>

<title>Struts 2 Login Application!</title>

<link href="<s:url value="/main.css"/>" rel="stylesheet" type="text/css"/>

</head>
<body class="tundra">
<s:form action="doLogin" method="POST">
<tr>
<td colspan="2">
Login
</td>

<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/>

<div style="float:right;clear:right;" dojoType="dijit.form.DropDownButton">
<span>Help</span>
<div dojoType="dijit.TooltipDialog" id="dialogright">
<div style="white-space:nowrap;">Help application</div>
</div>
</div>

</s:form>
</body>

When I'm executing this in struts2 using below action

action name="doLogin" class="events.Login"
result name="input">/pages/login.jsp
result name="error">/pages/login.jsp
action

When it is loading it is throwing below error in firefox console.
dojo is not defined
dojo.require("dijit.Dialog");

The same file, if I'm executing with '/pages/login.jsp' rather than 'login.action', it is working fine (it is displaying dijit.TooltipDialog) correctly.

For fixing this, I added 's:head theme="ajax" debug="true"' in section and I'm getting 2 errors in firefox console when I executing 'login.action'

Error 1: dojo._hasResource has no properties
if(typeof dojo=="undefined"){(function(){if(typeof this["djConfig"]=="undefined"...

Error 2: djConfig.baseScriptUri has no properties
getBaseScriptUri()dojo.js (line 155)
loadPath("../dijit/Dialog.js", "dijit.Dialog", undefined)dojo.js (line 187)
loadModule("dijit.Dialog", undefined, undefined)dojo.js (line 351)
require("dijit.Dialog")dojo.js (line 419)
if(djConfig.baseScriptUri.length){

Please let me know, what changes I need to do to correct this problem.

Thanks in advance.

Thanks,
Sharath.

change your script tag.

Your script src is relative so when /login.action is called, it's looking for /dojoroot/dojo/dojo.js. When you call /pages/login.jsp, it's looking for /pages/dojoroot/dojo/dojo.js.

If you change your script tag (and css imports) to begin with /pages like so:

<script src="/pages/dojoroot/dojo/dojo.js">

you should be good to do.

If you look at your firefox console, under the net tab, you can see what is coming back with 404s.

My solution looks like

My solution looks like this...

<s:url value='/dojo-release-1.1.0rc2' var='dojoRoot'/>

<script type="text/javascript" src="<s:property value='dojoRoot'/>/dojo/dojo.js"
	djConfig="parseOnLoad: true, usePlainJson: true">
</script>

Seems to work OK.