Small cut-n-paste error in the example. I believe the content type for an
external JavaScript file should be "application/x-javascript":

<%@ page contentType="application/x-javascript" %>

Quoting Kris Schneider <[EMAIL PROTECTED]>:

> I'm no validator expert, but here's my take on it. Static JavaScript is
> produced
> from the <javascript> subelements of the <validator> elements in the
> validator
> config files. For example, the standard validateRequired function contained
> in
> the validator-rules.xml file that ships with Struts. Best practice seems to
> be
> to keep the static JavaScript in a single file instead of having it
> generated
> into each JSP where you want to perform validation. This can be accomplished
> by
> setting up a staticJavascript.jsp file like:
> 
> <%@ page contentType="javascript/x-javascript" %>
> <%@ taglib prefix="html"
>            uri="http://jakarta.apache.org/struts/tags-html"; %>
> <html:javascript dynamicJavascript="false"/>
> 
> Dynamic JavaScript is produced from the <form> subelements of the <formset>
> elements in the validator config files. So, in the JSP where you want to
> perform
> validation, you'd do something like:
> 
> <script type="text/javascript"
>         src="<c:url value="/staticJavascript.jsp"/>">
> </script>
> <html:javascript formName="theForm" staticJavascript="false"/>
> 
> <html:form action="/action/path"
>            onsubmit"return validateTheForm(this);">
>   ...
> </html:form>
> 
> If you're using DynaValidatorActionForm (where the validator key is the
> action
> path not the form name), I think you'll want to make sure to use the
> "method"
> attribute of the <html:javascript> tag. Otherwise you end up with dynamic
> JavaScript like:
> 
> function validate/action/path(form) {
> ...
> 
> So you'd want something like:
> 
> <script type="text/javascript"
>         src="<c:url value="/staticJavascript.jsp"/>">
> </script>
> <html:javascript formName="/action/path"
>                  method="validateTheForm"
>                  staticJavascript="false"/>
> 
> <html:form action="/action/path"
>            onsubmit"return validateTheForm(this);">
>   ...
> </html:form>
> 
> Quoting Ben Anderson <[EMAIL PROTECTED]>:
> 
> > Hi,
> > Can someone expalin the <html:javascript> tag a little bit or point me 
> > somewhere.  I'm trying to understand what the dynamic and static
> attributes
> > 
> > do.  I've read over the html tags page at the struts home page, but it 
> > doesn't explain much.
> > 
> > I've tried with every combination of static and dynamic = true or false.
> > 
> > There is javascript being generated (like validateInteger), but not a 
> > validateXXXForm function.
> > 
> > I've noticed in my app's logger that the static is generated, but after
> the
> > 
> > page has already decided it can't find it.  Also, is it possible that I'm
> 
> > going to run into problems writing the .js and then finding it because our
> 
> > actions are mapped /do/xxx/yyy/zzz?  It doesn't seem to be looking in the
> 
> > right place.
> > 
> > I've been searching all over the web and through the mail-archive for 
> > answers, but haven't found anything definitive.
> > 
> > Thanks in advance,
> > Ben Anderson
> > 
> > /************************************************************************
> > Hi,
> > 
> > I have the following in my struts-config.xml
> > 
> >     <action path="/admin/createContentType"
> >            
> type="com.xdeep.pacific.servlet.admin.forms.ContentTypesAction"
> >             name="BillingParametersForm" scope="request"
> >             input="contentTypes.jsp">
> >       <forward name="failure"
> > path="/admin/contentTypes.jsp?action=create"/>
> >       <forward name="success" path="/admin/updateBillingParameters.jsp"/>
> >     </action>
> > 
> > and in my validation.xml
> > 
> > <form-validation>
> >   <formset>
> >     <form name="BillingParametersForm">
> >       <field property="contentType" depends="required">
> >         <arg0 key="admin.prompt.contentType"/>
> >       </field>
> >     </form>
> >   </formset>
> > </form-validation>
> > 
> > and my jsp has the following form
> > 
> > <html:form action="/admin/createContentType" focus="contentType"
> >    onsubmit="validateBillingParametersForm(this);">
> > 
> > <html:text property="contentType"/>
> > <html:submit property="action" value="Create"/>
> > <html:reset value="Reset"/>
> > 
> > </html:form>
> > 
> > <html:javascript formName="BillingParametersForm"
> >    dynamicJavascript="true" staticJavascript="false"/>
> > <script language="Javascript1.1" src="staticJavascript.jsp"></script>
> > 
> > 
> > My BillingParametersForm extends
> org.apache.struts.validator.ValidatorForm
> > When the field is left blank an alert window does pop up as it should,
> but
> > after I dismiss it I get forwarded onto the success page.
> > 
> > Any suggestions on what I might be doing wrong.
> > 
> > Thanks,
> > Paul
> > 
> > I'm using Vodafone Mail - to get your free mobile email account go to
> > http://www.vodafone.ie
> > Use of Vodafone Mail is subject to Terms and Conditions
> > http://www.vodafone.ie/terms/
> > 
> > _________________________________________________________________
> > Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
> > http://join.msn.com/?page=features/junkmail
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> 
> -- 
> Kris Schneider <mailto:[EMAIL PROTECTED]>
> D.O.Tech       <http://www.dotech.com/>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to