M Turner

Greenhorn
+ Follow
since Dec 16, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by M Turner

Hmm - OhGoshNL huh.. well I'm definitely new to OGNL, but the following gave the same error as above:

13 years ago
Thanks for your thoughts Dave. My mind also went to reordering interceptors but then I knew I was in too deep...

Here's what I'm really getting at... I need to have only one error message for 3 fields - but I want to also test for whitespace which is build into requiredstring.. however that is a FieldValidator. So I tried the following:



which doesn't work and gives an error in my logs:

com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn Got result of null when trying to get Boolean.

I guess my real question is.. is there a nice way to test for whitespce in OGNL?


13 years ago
Right. So if I want to validate everything in validate(), can I still leverage the Xwork type validators?

OR

Can I switch the ordering of the validation calls such that the validate() method is called first .. then the xml?
13 years ago
I don't know if this will work for you, but here's an example from one blogger on how to modify the response object by using a custom interceptor:

http://omkarp.blogspot.com/search/label/Struts%202

Good Luck
13 years ago
Can I still leverage the type validators in my validate() method if I'm not using an xml file? I need to override validate() for my form validation, but still want to leverage some of the type validators from the framework. Is there an example of how to use the type validators without the xml? In Struts 1x, I would have used GenericTypeValidator - do I have to add Commons Validation to my project on top of the XWorks Validation to get type validators?

Thanks
13 years ago
After further digging I found that "expression" is the only true non-field validator which explains the behavior I was seeing.
13 years ago
I'm not seeing the short-circuiting in my validations behaving as I would expect according to the following documentation:


A plain Validator (non FieldValidator) that gets short-circuited will completely break out of the validation stack. No other validators will be evaluated and plain validators takes precedence over field validators meaning that they get evaluated in the order they are defined before field validators get a chance to be evaluated.



My validations are defined as:



I would expect that only 1 error message would be displayed, since it's supposed to "completely break out of the validation stack", however, I see 3 error messages. Plus, my field validations are still executing.

My goal is that if any of the strings is blank, the user will get only one message and the other field validations will get short-circuited. Do I have to use an expression to accomplish this?

TIA
13 years ago
Whether you put a given validation in an xml file or into the Java action depends on how complex the validation is. If you have validations that fit with in standard parameters that can be checked using the "bundled" validation types like "required,email,stringlength" then put those in your validation.xml file. If your validations are more complex then you can action's use the validation() method. In fact, you can use both together.

13 years ago
Oops - I read the example too fast. The blogger states..

Both options need the CookieInterceptor to be configured for the action that needs to receive cookies.



Hope this helps someone
13 years ago
I'm using the following blog post on using cookies in Struts 2

http://omkarp.blogspot.com/2007/07/working-with-cookies-in-struts2.html

So I'm implementing CookiesAware in the following way:



However, in my Action's execute() method when I test the value of cookiesMap it's is null. I have also put a breakpoint in the setCookiesMap() method and have found that it never gets called.

Finally, I have looked at the struts-default stack and noticed that CookieInterceptor is not part of the default stack. Do we need it in order for CookiesAware to work?

Thanks,
Marcella
13 years ago
Maggie,

Although the IDE puts a copy of struts.xml in your WEB-INF/classes folder when it builds your project. You will need to have a copy in your /src folder. Mine is in the root of my Java Resources/src folder.

Also, my IDE blows up when in "dev mode" - I don't recommend it.

Good luck,
Marcella
13 years ago
It's also called tiles-def.xml - I don't think the name matters as long as you put the same file name in your web.xml. Here'e the documentation:

http://tiles.apache.org/framework/tutorial/basic/pages.html

There are lots of tutorials online.. G/L
13 years ago
My model object has an XMLGregorianCalendar for a birthDate attribute. So I have created a custom converter which takes the string and converts it. Birthdate is also a required field.

My converter is global - I have it listed in the xworks-conversion.properties file

What's happening is that if the user types in a string which is not parseable by the MM/dd/yyyy pattern, the conversion error is thrown (great np there) HOWEVER the "required" validation error is thrown ALSO, so the screen shows up with the invalid message and the required message PLUS the birthDate field is blank.

I thought that ValidationAware was supposed to retain the user's original value? Also, I understand that the model object will not have a populated birthDate because the conversion failed, but is there a way to short-circuit the "required" validation if a conversion error occurs.

P.S I tried adding the following to the action-validation.xml file - in order to save the user's original entry :



However, the value isn't repopulated and now the "invalid" error is shown twice. I also tried adding "short-circuit="true" to the field-validator, but it didn't short-circuit the "required" logic.

Thanks
13 years ago
What does your tiles.xml page look like? Do you have a definition for AddCategory that extends your base page definition?



Once you have all of your definitions, your struts.xml action mappings will refer to your tiles definitions:

13 years ago
Hi,

You need to have a unique tiles definition for each page that you want on your navigation. The new tiles definitions will override only the body element I suspect if you want all of the other parts of the page to be the same. Then in your navigation links will point to the tile definition you have created in your tiles.xml.

Good Luck
13 years ago