You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Bathje <mp...@ntsource.com> on 2004/01/29 19:44:42 UTC

2 unanswered questions

Hi all.

I have a few questions I've posted to the list recently that have not been
answered. 2 of them are somewhat important, and I was wondering if anybody
had any insights. I will simplify the questions in this message and include
a link to the full description.

First - how can I have multiple forms on the same page all use javascript
validation? The javascript that struts prints out for each form conflicts
with each other, and causes only the "last" form's validations to work.
Originally asked here:
http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92019.html

Second - I am working on a custom validator. The "server" side of the
validation works great, but the javascript side has some issues with
variables that contain regular expressions. It is stripping out the \
characters from the regexp so that it doesn't work. How can I access
variables as regular expressions in a custom validator?
Originally asked here:
http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92124.html

And as long as I am doing this, there are 2 other questions with no answers
yet, but they aren't quite as important to me as the above questions:
http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92020.html
http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg91959.html
(there is a thread about this, but no solution yet)

Thanks again,
Matt


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


Re: 2 unanswered questions

Posted by Matt Bathje <mp...@ntsource.com>.
Replying to myself here - but after some searching over the weekend, I found
bug 17667 - which is the same problem I have been having. Stupid me
searching for "multiple form" all this time instead of "multi-form" never
found it.

Anyways, I took the patches that had been attached to that bug already, and
updated them for the latest versions of Struts and Commons Validator (mostly
moving all the javascript fixes out of validator-rules.xml and into the
individual .js files in validator) and it is working great. Much cleaner
then the crap I had been brewing up as well.

I put the new patches back up under the bug if anybody else is interested.
(Or if they want to put this in 1.2)

Matt Bathje


----- Original Message ----- 
From: "Matt Bathje" <mp...@ntsource.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, January 29, 2004 6:00 PM
Subject: Re: 2 unanswered questions


> > I'm assuming that you've at least specified distinct values for the
> > "method" attribute for each use of <html:javascript>?
> > http://jakarta.apache.org/struts/userGuide/struts-html.html#javascript
> > (Actually, looking at the doc I see that the process when this isn't
> > specified should result in unique validate method names.)  I've never
> > actually tried to validate multiple forms in a single page.  You may
> > have simply discovered a limitation in the design of the validator
> > stuff.  If so, feel free to submit an enhancement request in
> > Bugzilla, and feel just as free (or more so) to attach patches to
> > help solve the problem!
>
> Yes, specifying the method doesn't help with the problem.
>
> I started working on a patch - and it doesn't seem like it is going to be
> struts specific. The validator javascript files (as well as the validator
> itself maybe) need to be changed so that this can be done.
>
> Basically what I have started on doing is:
>
> 1. adding a multipleForm (true|false) property to the html:javascript
tag -
> if it is true it means we want multiple js validators on the same page.
> 2. Modifying
>
org.apache.struts.taglib.html.JavascriptValidatorTag.createDynamicJavascript
> to append the formName to the javascript functions that it outputs in the
> ValidatorAction iteration loop. (If multipleForm = true)
> 3. Modifying
>
org.apache.struts.taglib.html.JavascriptValidatorTag.getJavascriptStaticMeth
> ods to alter the validator javascript if multipleForm = true. The 2 things
I
> am trying to have it do are replace the function definition with a
function
> definition that includes the form name and replace the oRequired (or
> whatever) array definition call with a call that includes the form name
(so
> oRequired = new required(); becomes oRequired = new requiredFormName();)
>
> 1 and 2 are no problems.
> 3 on the other hand is a major pain in the butt, and where alterations to
> validator instead of struts come in.
>
> First, the .js files follow very loose standards for naming. Weird things
> like oRequired for the required validator, but oMasked for the mask
> validator. Weird things like minlength and maxlength both having wacky
> upper/lower case changes all over. This makes doing String.replaceall()
> operations on the .js files extremely tricky. The .js files would need to
be
> changed to make sure they follow a standard that could be parsed properly.
>
> The second problem is that I don't even think these replace operations
> belong in struts, but in the validator code itself. (Like in
> org.apache.commons.validator.ValidatorAction.loadJavascriptFunction
> possibly) The problem here is I'm not entirely sure how to get the
> html:javascript multipleForm variable into ValidatorAction properly. I am
> also not sure if this is even the best/most elegant solution. If having it
> in the validator code is good, is loadJavascriptFunction the best place
for
> it, or is somewhere else better? Does that code actually belong in struts
or
> validator?
>
> I can hack some stuff together and use it on our own sites, but I'd really
> like to be able to contribute this stuff back so I want to make it
"right".
>
> Thats all for now, let me know what you all think.
>
> Thanks,
> Matt Bathje
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Re: 2 unanswered questions

Posted by Matt Bathje <mp...@ntsource.com>.
> I'm assuming that you've at least specified distinct values for the
> "method" attribute for each use of <html:javascript>?
> http://jakarta.apache.org/struts/userGuide/struts-html.html#javascript
> (Actually, looking at the doc I see that the process when this isn't
> specified should result in unique validate method names.)  I've never
> actually tried to validate multiple forms in a single page.  You may
> have simply discovered a limitation in the design of the validator
> stuff.  If so, feel free to submit an enhancement request in
> Bugzilla, and feel just as free (or more so) to attach patches to
> help solve the problem!

Yes, specifying the method doesn't help with the problem.

I started working on a patch - and it doesn't seem like it is going to be
struts specific. The validator javascript files (as well as the validator
itself maybe) need to be changed so that this can be done.

Basically what I have started on doing is:

1. adding a multipleForm (true|false) property to the html:javascript tag -
if it is true it means we want multiple js validators on the same page.
2. Modifying
org.apache.struts.taglib.html.JavascriptValidatorTag.createDynamicJavascript
to append the formName to the javascript functions that it outputs in the
ValidatorAction iteration loop. (If multipleForm = true)
3. Modifying
org.apache.struts.taglib.html.JavascriptValidatorTag.getJavascriptStaticMeth
ods to alter the validator javascript if multipleForm = true. The 2 things I
am trying to have it do are replace the function definition with a function
definition that includes the form name and replace the oRequired (or
whatever) array definition call with a call that includes the form name (so
oRequired = new required(); becomes oRequired = new requiredFormName();)

1 and 2 are no problems.
3 on the other hand is a major pain in the butt, and where alterations to
validator instead of struts come in.

First, the .js files follow very loose standards for naming. Weird things
like oRequired for the required validator, but oMasked for the mask
validator. Weird things like minlength and maxlength both having wacky
upper/lower case changes all over. This makes doing String.replaceall()
operations on the .js files extremely tricky. The .js files would need to be
changed to make sure they follow a standard that could be parsed properly.

The second problem is that I don't even think these replace operations
belong in struts, but in the validator code itself. (Like in
org.apache.commons.validator.ValidatorAction.loadJavascriptFunction
possibly) The problem here is I'm not entirely sure how to get the
html:javascript multipleForm variable into ValidatorAction properly. I am
also not sure if this is even the best/most elegant solution. If having it
in the validator code is good, is loadJavascriptFunction the best place for
it, or is somewhere else better? Does that code actually belong in struts or
validator?

I can hack some stuff together and use it on our own sites, but I'd really
like to be able to contribute this stuff back so I want to make it "right".

Thats all for now, let me know what you all think.

Thanks,
Matt Bathje


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


XML Entity Resolution (was Re: 2 unanswered questions)

Posted by Joe Germuska <Jo...@Germuska.com>.
Maybe you need to register a custom EntityResolver on the Digesters? 
Struts doesn't really expose this in a graceful way right now, for 
tiles and validator you could probably look at either subclassing the 
plugins and taking charge of how the Digester is configured.

See 
http://jakarta.apache.org/commons/digester/apidocs/org/apache/commons/digester/package-summary.html#doc.RegisteringDTDs

Joe


At 8:58 AM -0600 1/30/04, Matt Bathje wrote:
>  >
>>  regarding "entity includes in tiles-defs.xml (again)" -- both
>>  struts-config and tiles-definitions files can be specified using a
>>  comma-separated list of files (in web.xml for struts-config, and in
>>  the plugin descriptor in struts-config for tiles) -- isn't that a
>>  simpler way to solve the same problem of breaking down big config
>>  files?
>>
>
>The problem with that is, we have some forms (probably 5-6 of them) that
>have duplicated properties/validations. It would be nice to be able to do an
>entity include to include those duplicated validations in each form they are
>required in validation.xml.
>
>If I get some free time I am going to look into this, but as I mentioned in:
>http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92220.html
>
>I really think there is some sort of bug in either the plugin interface or
>the tiles and validator plugins specifically that make the "root" for the
>xml documents change to be %SystemRoot% or something like that.
>
>
>Matt Bathje
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org


-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
       "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
             -- Jef Raskin

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


Re: 2 unanswered questions

Posted by Matt Bathje <mp...@ntsource.com>.
>
> regarding "entity includes in tiles-defs.xml (again)" -- both
> struts-config and tiles-definitions files can be specified using a
> comma-separated list of files (in web.xml for struts-config, and in
> the plugin descriptor in struts-config for tiles) -- isn't that a
> simpler way to solve the same problem of breaking down big config
> files?
>

The problem with that is, we have some forms (probably 5-6 of them) that
have duplicated properties/validations. It would be nice to be able to do an
entity include to include those duplicated validations in each form they are
required in validation.xml.

If I get some free time I am going to look into this, but as I mentioned in:
http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92220.html

I really think there is some sort of bug in either the plugin interface or
the tiles and validator plugins specifically that make the "root" for the
xml documents change to be %SystemRoot% or something like that.


Matt Bathje


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


Re: 2 unanswered questions

Posted by Joe Germuska <Jo...@Germuska.com>.
>First - how can I have multiple forms on the same page all use javascript
>validation? The javascript that struts prints out for each form conflicts
>with each other, and causes only the "last" form's validations to work.
>Originally asked here:
>http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg92019.html

I'm assuming that you've at least specified distinct values for the 
"method" attribute for each use of <html:javascript>? 
http://jakarta.apache.org/struts/userGuide/struts-html.html#javascript
(Actually, looking at the doc I see that the process when this isn't 
specified should result in unique validate method names.)  I've never 
actually tried to validate multiple forms in a single page.  You may 
have simply discovered a limitation in the design of the validator 
stuff.  If so, feel free to submit an enhancement request in 
Bugzilla, and feel just as free (or more so) to attach patches to 
help solve the problem!


>And as long as I am doing this, there are 2 other questions with no answers

regarding "entity includes in tiles-defs.xml (again)" -- both 
struts-config and tiles-definitions files can be specified using a 
comma-separated list of files (in web.xml for struts-config, and in 
the plugin descriptor in struts-config for tiles) -- isn't that a 
simpler way to solve the same problem of breaking down big config 
files?

Sorry, no answers for the other two questions...

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
       "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
             -- Jef Raskin

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