• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Struts 2: How do I change markup of field errors?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, forgive me if this has been answered but I couldn't find the solution anywhere. I am learning struts 2 and am having trouble customizing the way my error messages display. by default, they appear above the input with a generated <tr>, <td>, and <span> tag. I want to change this so I can render them by (to the right of) the field.

All the documentation says to modify the .ftl file and place it in the /template/{theme} folder in webroot. The problem with this is that I have no idea what .ftl file the validation framework is using!

Thanks in advance for any answers. I must be missing something, because i cannot believe is should be this difficult to change HTML.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took a quick look and it looks to me like the location of the error message is being controlled by the validation.js file for the xhtml theme (the theme I assume you are using). I also took a look, at it looks to me like if you want to override that js you'll need to override the form-validate.ftl to look for the js file in the location you specify.
 
William Nelson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response. That looks like the file(s) I need.

In the meantime, I was able to get the desired outcome by just changing my theme to simple, and modified the fielderror.ftl file directly.

For anyone else looking at this, copy the template.simple.fielderror.ftl file from struts-core into a directory in your webroot named /template/simple/. For my purposes, I modified the file to not use <ul> and <li> tags. The framework will automatically pick up these changes.

My JSP fielderror now looks like this:

<s:form action="DriverAdd" theme="simple">
<s:textfield name="driver.firstName" required="true" />
<s:fielderror>
<s : param value="%{'driver.firstName'}" />
</s:fielderror
<s:submit />
</s:form>

I left out formatting and labels for sake of simplicity. Hope this helps anyone else looking to do something like this.

[ October 24, 2008: Message edited by: William Nelson ]

[ October 24, 2008: Message edited by: William Nelson ]
[ October 24, 2008: Message edited by: William Nelson ]
 
I'm so happy! And I wish to make this tiny ad happy too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic