Ken Pelletier

Ranch Hand
+ Follow
since Aug 01, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ken Pelletier

validwhen will let you create validation rules in terms of the *relationship* between the property being validated and other properties. I don't believe you can use it to conditionally apply *other* rules.

A common example is the ol' password/confirmPassword pattern where the user enters the password twice and the two properties must match:



That rule says the confirmPassword property is valid only when it matches the password property. Since neither is required there, the match would also be satisfied when they're both empty. This might be suitable for a 'change password' feature which is activated only when there is input, but you'd want to apply rules to the password property regarding length, etc.

afik, there isn't a way to make *other* validation rules be conditional based on a validwhen expression.

An approach that would work is to create separate action mappings for create and modify, then applying the appropriate validations for each of those mappings.

If you had separate mappings for '/createUserRegistration' and '/modifyUserRegistration', you could then use a DynaValidatorActionForm, for example, to allow your validation to differ between those two mappings.

Those mappings could still use the same ActionForm, jsps/tiles, forwards as they do now, but the validation would be dependent on the mapping that was used.

When using DynaValidatorActionForm, the value of the validation 'form' element's 'name' attribute is the action mapping name instead of the form:



If anyone has a suggestion about conditional validation with validwhen (ie: apply a set of rules conditionally based on the test), I'd also love to hear them. I posted a similar question last week and got no response.
19 years ago
Is it possible to create a validation rule (validation.xml) that will apply a set of other rules to a given form property depending on the value of another form property?

I'm using Struts 1.2.4, and am aware of (and using) validwhen for dependent validation where a rule is expressed in terms of another property's value and a boolean expression.

I want to make the application of certain rulesets conditional on the value of another property.

One example is an industry-specific credit card that has a different format from the standard CreditCardValidator's (which is the commons validator that Struts uses out of the box for credit card).

Given a 'type' property and a 'cardNumber' property, I'd want to apply the stock CreditCardValidator rules only when the type is not the known industry-specific type code, otherwise I want to apply a simple regexp mask.

Short of creating another CreditCardType-implementing class and wiring it into my own validator rule, can this sort of thing be done in the xml validation def?
19 years ago
For a Struts webapp with modules, each module's struts-config file declares the messages-resource param to name the file to use for resolving messages in that module context.

I would like to use the JSTL <CODE><fmt:message.../></CODE> tag instead of <CODE><bean:message.../></CODE>

What is the proper way to configure the module-specific messages-resource files.

I would like to configure the bundle per module, and not use the "bundle" attribute of the <CODE><fmt:message.../></CODE> tag in my pages.
20 years ago
Yes, I've since tried this on for size and it seems a worthwhile extension to the type-safe enum pattern in cases where a bean-style getter is required. It made the tag code much cleaner, and inverting the responsibility to the model to make the property accessible (where possible) pays off in other ways, too.

Thanks again.
20 years ago
JSP
Correction: since the accessor is for a boolean with the isXXX() style, the EL expression within the test shoud have read:



A bit less expressive, perhaps.
20 years ago
JSP
Thanks for the quick, clear reply. I had a nagging feeling that this was a common need and there had to be a way around it.

I can see how geting the status values into scope in a Map keyed by a String with same name of the static var would do the trick.

For what it's worth, it got me to thinking of another possiblity: add some sugar to the status class that will allow bean-style property access for the various static values. For each static instance in the type-safe enum class, I'd add an accompanying boolean getter:



This bit of convenience api will avoid duplicating the mapping of the names (static var in one place, string key to a map in another) , keeping it all within the model's Status class.

The scriptlet code would then be:



This also then allows other bean-style property access usage (eg: velocity).

Thanks!
20 years ago
JSP
I need to test equality between a jsp attribute which contains an instance of a class, and another instance of that class that is a static member of the class.

It's the classic java typedef enum pattern where there are instances of a given class stored as static members of that class:



So in java it would be:



How is the equivalent test done in JSTL?

My usage happens to be a jsp tag file, but the issue is plainly how to do a JSTL test for equality between two instances of a class where one is a static member.



That's what I'm trying to do logically, but of course, it's not possible to embed scriptlet inside an EL test expression.
20 years ago
JSP
As is often the case, I discovered the answer only after posting.
So, for those who bump into a similar problem with xhtml rendering by Struts, it is indeed the case that included pages do NOT inherit the rendering style of their including page.
[CODE]<html:html xhtml="true">...</html:html>[CODE]
... will only affect the rendering of the outer-most page - the page in which it appears.
Each included fragment that itself uses Struts tags to render markup will have to indicate that they are to be rendered as xhtml.
If you use any method ( Tiles, <jsp:include../> ... ) to include a jsp page that also uses Struts tags, that included page must have the empty xhtml tag in it:
[CODE] <html:xhtml/> [CODE]
20 years ago
I am using Struts 1.1 final, and am having trouble getting valid xhtml to be rendered for the various input taglibs.
All of my pages use the following Struts html tag:

This Struts html tag does properly render the html tag markup itself, complete with xmlns, lang and xml:lang attributes.
However, the input tags inside these pages are not rendered with the required closing tag:

Results in this:

Instead of the required:

Note the closing end tag as required by xhtml.
I am using tiles, and the outer layout for all pages is where the Struts html tag resides - I'm not sure if this is somehow causing embedded tiles with input tags to fail to recognize that they are inside of an xhtml page.
Any posts about this problem I have seen state that Struts 1.1 only requires the 'xhtml="true"' attribute on the html tag in order to solve this, but this has not been my experience.
20 years ago
Thanks!
I did a bit of further investigating and it appears that the 3.0M3 build does not have this problem with xerces being installed the system-wide 1.4.x way; lib/endorsed. At least it does not break as it did in 2.1.1.
I already have continuous checkout/build/unit test running for this project on various platforms. I'm trying my darndest to not have to make any build changes that are purely to accomodate Eclipse... so far it's been a challenge. ;-)
There was another wildcard in this that lowered the signal-to-noise for me: the cvs checkouts done via eclipse were munging jar files due to keyword expansion (i presume). While this wasn't the case on any other cvs checkout, jar files should have been checked in with -kb anyway, so I was happy to correct that and Eclipse now has not trouble with them.
Thanks - I'm optimistic that I can become productive in Eclipse quickly. I'm just evaluating whether I can make the jump. So far, so good.
I have a multi-tiered project which I've imported into Eclipse.
There is a master build, with several component builds underneath ( webapp, model, service, unittest, etc ).
An example of an intra-project dependency is that the webapp src contains imports from the service layer. The service build creates a jar in a project lib which the webapp build puts onto the compile classpath - life is good for compilation, testing, etc.
When I checkout the project into Eclipse I get lots of 'cannot be resolved' messages. The builds and tests work fine within Eclipse, but how can I avoid those messages on checkout?
Since the references indeed cannot be resolved until the referenced jar is built, I can happily ignore them, but is there a way to lower the noise?
Thanks for the response. I've already been down that path, however, and no joy.
I do have references to xercesImpl.jar and xmlAPIs.jar in the ant prefs.
Following another post elsewhere, I even tried copying them from the xerces plugin location into the ant plugin location - no effect.
I also tried running my own ant dist as opposed to the plugin by changing the ant home in Eclipse. Same symptom.
My <java> target in the ant build also uses fork="true", which should run it in a separate JVM, with its own classloaders. Elsewhere I've found (eg: JUnit) this to get around non-delegating classloaders.
I also have the xerces jars in my $JAVA_HOME/lib/endorsed, which has been rumored to be a problem, but I find that removing them from there also does not solve this problem.
Any further thoughts on this?
I have an ant target that runs a java task to generate some code from xml. Run from ouside Eclipse, either from the command line or a build tool like anthill, all is well.
I'm using 1.4.1 jvm on OS X and Linux, and have placed the xmlAPIs.jar and xercesImpl.jar in the $JAVA_HOME/lib/endorsed directories so that the classloader will prefer this parser over crimson, the built-in 1.4.1 parser.
When running the ant target in Eclipse, however, I get:
java.lang.NoClassDefFoundError: org/xml/sax/SAXException
The same appears to be true for classes in $JAVA_HOME/lib/ext (mail.jar, activation.jar). The <javac> task isn't seeing them when run from Eclipse.
What is it about running ant under Eclipse that is causing the normal classloading delegation to be circumvented?
Eclipse 2.1.1, ant 1.5.3
Thanks.
Yeah, that's pretty much exactly what I was referring to when I said:
>I use a StringBuffer and append() in an iteration over the collection
So, I take it there *is* no such animal hidden somewhere in the class libraries.
21 years ago
I often find myself having to concatenate the string values of objects in a collection into a comma-separated string.
I use a StringBuffer and append() in an iteration over the collection, but I have a nagging feeling that there's a built-in operation for this that I'm just not finding.
Is there a way to concatenate a collection of objects' string values into a string, optionally separated by another character(s) a la Perl's join( separator, array ) ?
I'd expect it to be in the Collections framework, but, apart from AbstractCollection's toString() method - which is close - I can't seem to locate it.
21 years ago