You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fea jabi <zy...@hotmail.com> on 2005/11/23 17:30:11 UTC

Re: javascript in validator -- html:javascript

why, if I can write a javascript in validator-rules.xml, I should be able to 
able to get the dialog right. using confirm of javascript.

if I give below in jsp
<html:javascript formName="SetupForm" dynamicJavascript="true" 
staticJavascript="true" />

it works fine.

But I observed that the javascript is generated on client side. Which I 
don't want.

Is there a way to execute the javascript on server-side?

What are these dynamicJavascript and staticJavascript. When should these be 
set to true?


My application requirement is the users may not have javascript enabled on 
their browsers. Can I still use this html:javascript. Or is there any oher 
alternative to do this?

in validator-rules.xml

<validator name="populate"
            classname="org.apache.struts.validator.FieldChecks"
               method="changeInPopulate"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       javax.servlet.http.HttpServletRequest"
              depends=""
                  msg="errors.setup">
         <javascript>
            <![CDATA[
                function changeInPopulate(autoPop){
                    var yesObj = document.getElementById("yesID");
                    var noObj = document.getElementById("noID");

                    if( (autoPop && (yesObj.checked))  ||
                        (!autoPop && (noObj.checked))   ) {
                        return;
                    }

                    var answer = confirm("are you sure");
                    if(!answer) {
                        if(yesObj.checked) {
                            noObj.checked=true;
                        }else {
                            yesObj.checked=true;
                        }
                    }
                }
            ]]>
         </javascript>
      </validator>




Thanks.



>From: Laurie Harper <la...@holoweb.net>
>Reply-To: laurie@holoweb.net
>To: user@struts.apache.org
>Subject: Re: javascript in validator
>Date: Tue, 22 Nov 2005 23:43:57 -0500
>
>fea jabi wrote:
>>One of the requirement in my application is that I should not use the 
>>client side javascript as the browsers the user use might not have the 
>>javascript enabled in their browsers.
>>
>>In my jsp there are 2 radio buttons. one of which is enable by default. 
>>When the user clicks on either of those he/she should be promted with some 
>>message depending on which radio button they pressed Yes/No.
>>
>>Using DynaValidatorForm.
>>
>>Can I do this in struts validator xml? if so how to do this?
>
>No, validator can check if a form is valid but it doesn't provide a way to 
>generate arbitrary prompts and dialogs. Assuming you want something like an 
>'Are you sure you want to change this option? yes/no' prompt, you'll need 
>to do that as a separate page.
>
>L.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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


Re: javascript in validator -- html:javascript

Posted by Dave Newton <ne...@pingsite.com>.
Frank W. Zammetti wrote:

> There *was* in fact a server-side Javascript technology at one point, 
> but it was short-lived, not used much and IIRC specific to Netscape's 
> old web servers.  I had the misfortune of having to deal with in app 
> developed in it probably seven or so years ago... not pleasant :)

Yeah. I figured the OP was confused enough as it was and spared him :D

Dave



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


Re: javascript in validator -- html:javascript

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Dave Newton wrote:
> JavaScript runs in the browser. If it's not enabled in the browser then 
> JavaScript won't work.

There *was* in fact a server-side Javascript technology at one point, 
but it was short-lived, not used much and IIRC specific to Netscape's 
old web servers.  I had the misfortune of having to deal with in app 
developed in it probably seven or so years ago... not pleasant :)

(Not that this is relevant really, just an interesting historical 
footnote I suppose)

Frank

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


Re: javascript in validator -- html:javascript

Posted by Dave Newton <ne...@pingsite.com>.
fea jabi wrote:

> Is there a way to execute the javascript on server-side?

Um... Simple answer is no.

> My application requirement is the users may not have javascript 
> enabled on their browsers. Can I still use this html:javascript. Or is 
> there any oher alternative to do this?

I think you're confused about JavaScript in regards to 
server-side/client-side.

JavaScript runs in the browser. If it's not enabled in the browser then 
JavaScript won't work.

You can validate things server-side, but it's different behavior: 
server-side validation runs after a submit.

That said, AJAX means that isn't necessarily true anymore and there's 
all sorts of games you can play with that, if you think you're up to it.

Dave



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