1

Ok banging my head against a brick wall here for the last 2 days as my validation message will not output on the JSP although validation is clearly happening...

I have set up simple validation for a required field through an action-validation.xml

<validators>
    <field name="firstname">
        <field-validator type="requiredstring">
            <message>First name is required</message>
        </field-validator>
    </field>
</validators>

Action class extends ActionSupport and interfaces ServletRequestAware, Preparable, ModelDriven

Execute, prepare and validate methods have all be overridden within the action class and its configuration is

<package name="main" namespace="/" extends="struts-default">
    <action name="myform" class="com.uk.MyFormAction">
        <interceptor-ref name="store">
            <param name="operationMode">STORE</param>
        </interceptor-ref>
        <interceptor-ref name="defaultStack" />

        <result name="update">s2/user.jsp</result>
        <result name="input">s2/user.jsp</result>
    </action>
</package>

For whatever reason the validation from the validation.xml file will not output anything within my JSP within

<s:if test="hasActionErrors()">
    <s:actionerror />
</s:if>

<s:textfield name="firstname" />

There are other fields on the page, I'm just trying to get this one to work first. I've added the interceptor store which makes no difference and faffed with the type="redirectAction" however when that is added to my input result I get an infinite loop between my validation and prepare methods for the action upon submission...

the actual configuration I'm sure is correct. When the field is present the submission goes through correctly however when it is blank struts does redirect back to the JSP but gives no error messages.

I am now totally out of ideas on what could be wrong, any suggestions please ?

Edit: Incidentally if I add a addActionError() viamy validate function it displays correctly on the page, but again the validation.xml message is missing (and should not be)

Also struts.ui.theme=simple is being used

Nearest post I can find that relates to my problem can be found here however the interceptor for messages doesn't seem to store or intercept my messages... I have tried to output the number of ActionErrors by printing the size of getActionErrors collection which returns 0 in my execute and validation functions... I'm not sure if that should return the validation.xml errors if working correctly

  • Validation messages are displayed if you use default theme. See [this answer](https://stackoverflow.com/a/15496272/573032). – Roman C Jun 22 '17 at 13:50
  • @RomanC sorry that doesn't make any sense to me ? Post doesn't seem to reference any theme, my message is written into the validation.xml. I've tried removing my struts.properties which puts it to default (xhtml?) and no messages appear still. Also default puts all sorts of HTML around my form elements which I don't want... – Dangerous Hamster Jun 22 '17 at 14:10
  • Well, it made sense for others, I don't know why you couldn't get it. Ok, since your question is too broad I can't get you a valid answer, so let you post it yourself if you got it. – Roman C Jun 22 '17 at 14:16
  • 1
    @RomanC the post refers to internationalization with the assumption that messages are already being displayed from a non properties version. I do not get any message i.e. First name is required being displayed to begin with ? I don't see how that question is too broad unless i'm missing something obvious ? – Dangerous Hamster Jun 22 '17 at 14:24
  • Too broad because you don't understand what are you doing, I will be surprised if you say that you read the link I have posted. It seems you reject it without reading. – Roman C Jun 22 '17 at 14:30
  • 1
    @RomanC clearly I have read it as I know it's about internationalization which is nothing to do with my problem. Also clearly I don't know what I'm doing hence I'm here asking for help which your also clearly not willing to help provide... – Dangerous Hamster Jun 22 '17 at 14:40

1 Answers1

1

Within the area I want the error messages printed out I have the following code

<s:if test="hasActionErrors()">
    <s:actionerror />
</s:if>

<s:if test="hasActionMessages()">
    <s:actionmessage />
</s:if>

Well the above are for ActionErrors and ActionMessages not for field errors. What you also need is

<s:fielderror />

As I've defined field errors via my action-valiation.xml file !

Helped via this post

You can also define locations for specific fields. This post explains that...

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331