Dale Newfield wrote:
Allen Gilliland wrote:
Would you mind sharing a couple details about how you have it
configured, because if it's working for you then I suppose I must be
doing something wrong? I am using Struts 2.0.5.
Sure. I'll just mirror your snippets with my own. I am also using 2.0.5.
What I have in my struts.xml file is ...
<action name="MyForm!*" method="{1}" class="mypackage.MyForm">
<result name="input">/WEB-INF/jsps/MyForm.jsp</result>
</action>
I have explicit mappings for each action, so what the the validation.xml
file should be named is easier to see:
<action name="editProfile" class="userAction" method="edit">
<result name="success">/WEB-INF/pages/userForm.jsp</result>
<result name="error">/WEB-INF/pages/userHome.jsp</result>
</action>
<action name="saveUser" class="userAction" method="save">
<result name="cancel" type="redirect">users.xhtml</result>
<result name="input">/WEB-INF/pages/userForm.jsp</result>
<result name="success" type="redirect">users.xhtml</result>
<result name="addAnother"
type="redirect">editUser.xhtml?method=Add&from=list</result>
</action>
and I have UserAction-saveUser-validation.xml
ahhh, that would probably make it easier. i don't think i ever played
with it enough to try that because i'm lazy :/
for you, I'm tempted to say the file should be
MyForm!*-save-validation.xml ? or maybe MyForm!save-validation.xml (no
method, but a more specific action name?) I'd bet your problem is what
that struts is looking for the wrong file. Any way to stick in some
logging to tell you what it thinks the action name is, and what it
thinks the method name is?
you are right, the problem was that I just didn't have the right name
for the validation file and you example helped me figure out why. i
guess it isn't enough to just put the method name in the middle part of
the validation file name, it needs the full action name including the
method for it to work. so this is what works ...
MyForm-MyForm!save-validation.xml
seems a little redundant, but at least it's working =) thanks for the help!
is there a wiki page or something that i should be adding this too? i
think the current documentation ...
http://struts.apache.org/2.x/docs/validation.html
http://struts.apache.org/2.x/docs/action-configuration.html#ActionConfiguration-WildcardMethod
didn't really show exactly the right thing to do, so it would help to
fix those up.
-- Allen
Using this I can access MyForm.action to get to the default view
showing an empty form, and I can post the form to MyForm!save.action
and it executes the save() method on my action.
My urls would be "/editProfile.xhtml" and "/saveUser.xhtml"
Then in mypackage I have a file called MyForm-save-validation.xml with
this in it ...
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator
1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="property">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>property is required</message>
</field-validator>
</field>
</validators>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator
1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="user">
<field-validator type="visitor">
<param name="appendPrefix">false</param>
<message/>
</field-validator>
</field>
</validators>
One part of my User-validation.xml includes:
<field name="user.address.city">
<field-validator type="requiredstring">
<message key="errors.required"/>
</field-validator>
</field>
and I just tested that if I try to change my address to have no city the
validation rejects the form submission and sends me back to the form
with errors added in the appropriate places.
If I define just MyForm-validation.xml it works as expected and is
called to validate on all methods used on the action, but nothing
happens when I just have the MyForm-save-validation.xml file.
I'd bet due to the expanded-at-runtime nature of your action definition
that the file it's looking for is not the one you'd expect it to be
looking for. I can attest that if it finds the method-specific file it
does perform the validation. This isn't a solution, but it at least
gives you a more specific portion of the struts code to dig through. :-)
Just because the ActionName-validation.xml file is no longer in your
.war doesn't mean it's been removed from the directory tree where
your container expands stuff...
True, but that's why I clean that out each time I update my app.
Besides, my real problem is not that the 2 files are conflicting with
each other, it's that when I just have a
ActionName-MethodName-validation.xml file then nothing happens. No
validation on that action at all.
I was assuming you had the same problem I had: Back when I had a
form-validation.xml file and I realized I just wanted it to happen for a
single method, I changed the name to form-method-validation.xml, but it
took me 20 minutes to figure out why I was still failing the validation
that shouldn't have been happening--I'd never removed the
form-validation.xml file from tomcat's work directory :-)
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]