You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "J. Fiala" <st...@fwd.at> on 2004/07/14 11:35:48 UTC

Javascript Validation staticJavascript - Best Practices

hi there,

I've used the html:javascript tag to have the javascript code generated 
for my form.
I found out that using staticJavascript="false" I can prevent the static 
javascript code from messing up the html head.

To my mind it would be the cleanest solution to refer to the static 
javascript using
<script type="text/javascript" src="validation.jsp"></script>

Unfortunately the html:javascript code doesn't seem to allow to turn off 
the start/end script-tags. 
Looking inside the taglib API 
(struts-1.1/doc/api/org/apache/struts/taglib/html/JavascriptValidatorTag.html) 
it does only include getters for getJavascriptBegin()/getJavascriptEnd() 
but no setters, thus the code generated always looks like:
<script type="text/javascript" language="Javascript1.1"> 
<!-- Begin 
...
</script>

So the only option left seems to have the static javascript generated once 
and copy/paste it to a separate struts-validation.js file. However, if I 
update the struts version later I'll have to redo this.

Does anybody have a better idea for solving this?

Thx
J. Fiala

Re: Javascript Validation staticJavascript - Best Practices

Posted by "J. Fiala" <st...@fwd.at>.
hi bill,

I am using struts-1.1 and the <script>...</script>-tags show up in the 
jsp-generated source code.
Anyway, it works though - thx for your help!

J. Fiala





Bill Siggelkow <bi...@bellsouth.net> 
Sent by: news <ne...@sea.gmane.org>
14.07.2004 21:03
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
user@struts.apache.org
cc

Subject
Re: Javascript Validation staticJavascript - Best Practices






I am not following you, here. I thought maybe you were thinking that 
the 'staticJavascript.jsp' page generated the <script></script> tags 
around JS functions -- however, this is not the case AFAIK. I am using 
the nightly build.

J. Fiala wrote:

> hi bill,
> 
> the solution you've lined out works greatly, but I'm wondering why it is 

> not possible to turn off the <script...></script>-tag, because inside an 

> .js file it doesn't make sense to have the html tags included.
> 
> thx
> J. Fiala
> 
> 
> 
> 
> Bill Siggelkow <bi...@bellsouth.net> 
> Sent by: news <ne...@sea.gmane.org>
> 14.07.2004 14:11
> Please respond to
> "Struts Users Mailing List" <us...@struts.apache.org>
> 
> 
> To
> user@struts.apache.org
> cc
> 
> Subject
> Re: Javascript Validation staticJavascript - Best Practices
> 
> 
> 
> 
> 
> 
> Create a file called "staticJavascript.jsp" with the following content:
> ----------------------------------------------------------------
> <%@ 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="http://jakarta.apache.org/struts/tags-html" 
> prefix="html" %> 
> <html:javascript dynamicJavascript="false" staticJavascript="true"/>
> ----------------------------------------------------------------
> 
> Then in pages that use the validator include this file in the <head>(as 
> you alluded).
> 
> <head>
>    <script language="Javascript1.1" src="staticJavascript.jsp"></script>
>     ...
> 
> Now you can safely set the 'staticJavascript="false"' on the 
> html:javascript tag throughout your regular JSPs.
> 
> Good Luck!
> 
> Bill Siggelkow
> 
> J. Fiala wrote:
> 
>>hi there,
>>
>>I've used the html:javascript tag to have the javascript code generated 
>>for my form.
>>I found out that using staticJavascript="false" I can prevent the static 

> 
> 
>>javascript code from messing up the html head.
>>
>>To my mind it would be the cleanest solution to refer to the static 
>>javascript using
>><script type="text/javascript" src="validation.jsp"></script>
>>
>>Unfortunately the html:javascript code doesn't seem to allow to turn off 

> 
> 
>>the start/end script-tags. 
>>Looking inside the taglib API 
>>
> 
> 
(struts-1.1/doc/api/org/apache/struts/taglib/html/JavascriptValidatorTag.html) 

> 
> 
>>it does only include getters for getJavascriptBegin()/getJavascriptEnd() 

> 
> 
>>but no setters, thus the code generated always looks like:
>><script type="text/javascript" language="Javascript1.1"> 
>><!-- Begin 
>>...
>></script>
>>
>>So the only option left seems to have the static javascript generated 
> 
> once 
> 
>>and copy/paste it to a separate struts-validation.js file. However, if I 

> 
> 
>>update the struts version later I'll have to redo this.
>>
>>Does anybody have a better idea for solving this?
>>
>>Thx
>>J. Fiala
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Re: Javascript Validation staticJavascript - Best Practices

Posted by Bill Siggelkow <bi...@bellsouth.net>.
I am not following you, here. I thought maybe you were thinking that 
the 'staticJavascript.jsp' page generated the <script></script> tags 
around JS functions -- however, this is not the case AFAIK. I am using 
the nightly build.

J. Fiala wrote:

> hi bill,
> 
> the solution you've lined out works greatly, but I'm wondering why it is 
> not possible to turn off the <script...></script>-tag, because inside an 
> .js file it doesn't make sense to have the html tags included.
> 
> thx
> J. Fiala
> 
> 
> 
> 
> Bill Siggelkow <bi...@bellsouth.net> 
> Sent by: news <ne...@sea.gmane.org>
> 14.07.2004 14:11
> Please respond to
> "Struts Users Mailing List" <us...@struts.apache.org>
> 
> 
> To
> user@struts.apache.org
> cc
> 
> Subject
> Re: Javascript Validation staticJavascript - Best Practices
> 
> 
> 
> 
> 
> 
> Create a file called "staticJavascript.jsp" with the following content:
> ----------------------------------------------------------------
> <%@ 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="http://jakarta.apache.org/struts/tags-html" 
> prefix="html" %> 
> <html:javascript dynamicJavascript="false" staticJavascript="true"/>
> ----------------------------------------------------------------
> 
> Then in pages that use the validator include this file in the <head>(as 
> you alluded).
> 
> <head>
>    <script language="Javascript1.1" src="staticJavascript.jsp"></script>
>     ...
> 
> Now you can safely set the 'staticJavascript="false"' on the 
> html:javascript tag throughout your regular JSPs.
> 
> Good Luck!
> 
> Bill Siggelkow
> 
> J. Fiala wrote:
> 
>>hi there,
>>
>>I've used the html:javascript tag to have the javascript code generated 
>>for my form.
>>I found out that using staticJavascript="false" I can prevent the static 
> 
> 
>>javascript code from messing up the html head.
>>
>>To my mind it would be the cleanest solution to refer to the static 
>>javascript using
>><script type="text/javascript" src="validation.jsp"></script>
>>
>>Unfortunately the html:javascript code doesn't seem to allow to turn off 
> 
> 
>>the start/end script-tags. 
>>Looking inside the taglib API 
>>
> 
> (struts-1.1/doc/api/org/apache/struts/taglib/html/JavascriptValidatorTag.html) 
> 
> 
>>it does only include getters for getJavascriptBegin()/getJavascriptEnd() 
> 
> 
>>but no setters, thus the code generated always looks like:
>><script type="text/javascript" language="Javascript1.1"> 
>><!-- Begin 
>>...
>></script>
>>
>>So the only option left seems to have the static javascript generated 
> 
> once 
> 
>>and copy/paste it to a separate struts-validation.js file. However, if I 
> 
> 
>>update the struts version later I'll have to redo this.
>>
>>Does anybody have a better idea for solving this?
>>
>>Thx
>>J. Fiala
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Javascript Validation staticJavascript - Best Practices

Posted by "J. Fiala" <st...@fwd.at>.
hi bill,

the solution you've lined out works greatly, but I'm wondering why it is 
not possible to turn off the <script...></script>-tag, because inside an 
.js file it doesn't make sense to have the html tags included.

thx
J. Fiala




Bill Siggelkow <bi...@bellsouth.net> 
Sent by: news <ne...@sea.gmane.org>
14.07.2004 14:11
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
user@struts.apache.org
cc

Subject
Re: Javascript Validation staticJavascript - Best Practices






Create a file called "staticJavascript.jsp" with the following content:
----------------------------------------------------------------
<%@ 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="http://jakarta.apache.org/struts/tags-html" 
prefix="html" %> 
<html:javascript dynamicJavascript="false" staticJavascript="true"/>
----------------------------------------------------------------

Then in pages that use the validator include this file in the <head>(as 
you alluded).

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

Now you can safely set the 'staticJavascript="false"' on the 
html:javascript tag throughout your regular JSPs.

Good Luck!

Bill Siggelkow

J. Fiala wrote:
> hi there,
> 
> I've used the html:javascript tag to have the javascript code generated 
> for my form.
> I found out that using staticJavascript="false" I can prevent the static 

> javascript code from messing up the html head.
> 
> To my mind it would be the cleanest solution to refer to the static 
> javascript using
> <script type="text/javascript" src="validation.jsp"></script>
> 
> Unfortunately the html:javascript code doesn't seem to allow to turn off 

> the start/end script-tags. 
> Looking inside the taglib API 
> 
(struts-1.1/doc/api/org/apache/struts/taglib/html/JavascriptValidatorTag.html) 

> it does only include getters for getJavascriptBegin()/getJavascriptEnd() 

> but no setters, thus the code generated always looks like:
> <script type="text/javascript" language="Javascript1.1"> 
> <!-- Begin 
> ...
> </script>
> 
> So the only option left seems to have the static javascript generated 
once 
> and copy/paste it to a separate struts-validation.js file. However, if I 

> update the struts version later I'll have to redo this.
> 
> Does anybody have a better idea for solving this?
> 
> Thx
> J. Fiala


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Re: Javascript Validation staticJavascript - Best Practices

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Create a file called "staticJavascript.jsp" with the following content:
----------------------------------------------------------------
<%@ 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="http://jakarta.apache.org/struts/tags-html" 
prefix="html" %>	
<html:javascript dynamicJavascript="false" staticJavascript="true"/>
----------------------------------------------------------------

Then in pages that use the validator include this file in the <head>(as 
you alluded).

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

Now you can safely set the 'staticJavascript="false"' on the 
html:javascript tag throughout your regular JSPs.

Good Luck!

Bill Siggelkow

J. Fiala wrote:
> hi there,
> 
> I've used the html:javascript tag to have the javascript code generated 
> for my form.
> I found out that using staticJavascript="false" I can prevent the static 
> javascript code from messing up the html head.
> 
> To my mind it would be the cleanest solution to refer to the static 
> javascript using
> <script type="text/javascript" src="validation.jsp"></script>
> 
> Unfortunately the html:javascript code doesn't seem to allow to turn off 
> the start/end script-tags. 
> Looking inside the taglib API 
> (struts-1.1/doc/api/org/apache/struts/taglib/html/JavascriptValidatorTag.html) 
> it does only include getters for getJavascriptBegin()/getJavascriptEnd() 
> but no setters, thus the code generated always looks like:
> <script type="text/javascript" language="Javascript1.1"> 
> <!-- Begin 
> ...
> </script>
> 
> So the only option left seems to have the static javascript generated once 
> and copy/paste it to a separate struts-validation.js file. However, if I 
> update the struts version later I'll have to redo this.
> 
> Does anybody have a better idea for solving this?
> 
> Thx
> J. Fiala


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org