You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Karr, David" <da...@attws.com> on 2002/08/20 00:57:24 UTC

Tiles+Validator: Correct way to reference staticJavascript.jsp fi le?

I'm trying to build a simple prototype appliction which is using both Tiles
and Validator.  I got my Tiles code working pretty well, and then I started
integrating Validator.  I've also gotten this working, but I'm wondering if
there's a better way to do some of the things I did.

I have a "/mainBody.jsp" which is referenced from the Tiles definition.
Inside this JSP is the form to be validated.  The path to the layout JSP is
"/layout/basicLayout.jsp".

I have the following line just past the end of my "</form>" tag in
"mainBody.jsp":

<html:javascript formName="mainForm"
                 dynamicJavascript="true" staticJavascript="false"/>

I have the following line as the last line before the "</body>" tag in
"/layout/basicLayout.jsp":

<script language="Javascript1.1"
src="/ourapp/staticJavascript.jsp"></script>

Where "/ourapp/staticJavascript.jsp" looks like this (taken directly from
the struts-validator example):
-----------------
<%@ page language="java" %>
<%-- set document type to Javascript (addresses a bug in Netscape according
to a web resource --%>
<%@ page contentType="application/x-javascript" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>

<html:javascript dynamicJavascript="false" staticJavascript="true"/>
-----------------

So, with this structure, the eventual layed out page has a single reference
to the static javascript file, and any embedded forms will have embedded
references to the dynamic javascript for each form.

This structure appears to work.  The only slight nit I have with this is the
hardcoded reference to the context root of the application name in the
"<script>" element in the layout JSP.  I found that just using
"/staticJavascript.jps" didn't work.

Is this the best way to do this?

Re: Tiles+Validator: Correct way to reference staticJavascript.jsp fi le?

Posted by Cedric Dumoulin <ce...@apache.org>.
   Hello,

   To be independent from you application name, use

<script language="Javascript1.1"
src="<%=request.getContextPath()%>/staticJavascript.jsp"></script>

   Cedric

Karr, David wrote:

 >I'm trying to build a simple prototype appliction which is using both 
Tiles
 >and Validator.  I got my Tiles code working pretty well, and then I 
started
 >integrating Validator.  I've also gotten this working, but I'm 
wondering if
 >there's a better way to do some of the things I did.
 >
 >I have a "/mainBody.jsp" which is referenced from the Tiles definition.
 >Inside this JSP is the form to be validated.  The path to the layout 
JSP is
 >"/layout/basicLayout.jsp".
 >
 >I have the following line just past the end of my "</form>" tag in
 >"mainBody.jsp":
 >
 ><html:javascript formName="mainForm"
 >                 dynamicJavascript="true" staticJavascript="false"/>
 >
 >I have the following line as the last line before the "</body>" tag in
 >"/layout/basicLayout.jsp":
 >
 ><script language="Javascript1.1"
 >src="/ourapp/staticJavascript.jsp"></script>
 >
 >Where "/ourapp/staticJavascript.jsp" looks like this (taken directly from
 >the struts-validator example):
 >-----------------
 ><%@ page language="java" %>
 ><%-- set document type to Javascript (addresses a bug in Netscape 
according
 >to a web resource --%>
 ><%@ page contentType="application/x-javascript" %>
 ><%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
 >
 ><html:javascript dynamicJavascript="false" staticJavascript="true"/>
 >-----------------
 >
 >So, with this structure, the eventual layed out page has a single 
reference
 >to the static javascript file, and any embedded forms will have embedded
 >references to the dynamic javascript for each form.
 >
 >This structure appears to work.  The only slight nit I have with this 
is the
 >hardcoded reference to the context root of the application name in the
 >"<script>" element in the layout JSP.  I found that just using
 >"/staticJavascript.jps" didn't work.
 >
 >Is this the best way to do this?
 >
 >
 >




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>