aspose file tools*
The moose likes Struts and the fly likes Struts 2 - How do I remove validation messages from fields? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - How do I remove validation messages from fields?" Watch "Struts 2 - How do I remove validation messages from fields?" New topic
Author

Struts 2 - How do I remove validation messages from fields?

Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi,

I'm using struts 2 in my project and I don't want to display error messages on top of fields. What I need to know is, how do I customize validation framework so it will not show messages on top of each field which validation has failed??? This causes a mess up with my css design!!!

I have already configured the error messages to appear on top of pages when some validation error occurs but I was not able to disable the field messages to appear. I'm sure there's some way to accomplish that.

[]s
Marcos Maia.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

Use the "simple" theme: Struts 2 FAQ: Who do the form tags put table tags around controls


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977


Tx for this tip.That's what i need. The simple theme is not an option for me as I'll loose tooltips and will have to manually add label to fields. But following your suggestion I found out how to customize a template for my needs.

http://struts.apache.org/2.1.6/docs/template-loading.html
http://struts.apache.org/2.1.6/docs/extending-themes.html

Struts 2 rocks!



[]s
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

Let us know how it works out. There's been a lot of discussion about templates being painful to work with (I've never tried). We can always use another point of view.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

They're not difficult if you're comfortable with templating languages. There are several includes for most tags, but the contents of each are (usually) self-explanatory.
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi,

I took a quick look yesterday(1 hour) and as I'm not confortable with template languages it does not seemed too trivial. I have tryied some modification on template files but with no success. I'm using Appfuse and I already have found 3 templates under /template/xhtml and nothing seems to change when I change this templates. I think I'm still doing something wrong. I'll post my progress here.
Follows the template I believe I should customize to meet my requirements (controlheader-core.ftl):


[]s


Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
I have foun some more good information on xhtml theme on struts site: http://struts.apache.org/2.1.6/docs/xhtml-theme.html . Including a note on changing error message.

[]s
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I can't really read that.

Did you extract them to your classpath or webapp?
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hum... I'll try posting it again!


Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
See,

what I'm trying to acoplish is removing the message from the field but leaving the icon(warning) on label side to show which fields have failed validation. The messages I'll leave on top only, wich is default using struts Appfuse templates.

[]s
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I wrote: Did you extract them to your classpath or webapp?

The code that displays field messages is still there:
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi,

after a bit of modification I'm almost where I wanna to be. I have changed label entry to not became red anymore when error occurs so it's now like:


Also I have removed error message and left warnin icon:

The only thing I'm not able to do yet is to post the warnin icon on top(on label side) .
The icon is actually pushing the textfield and being placed on it's left side. I'd like it to be after the label text for the field, same line.

What I have is like:

label for field
icon - textfield

I want it to be like:

label for field - warning icon
textfield

I still didn't get which code fragment places a line between label and icon.



Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
It's done.

It took me 3.5 hours to acomplish this task. This time I have used to post here, some reading and research on web and trying with code changes in templates. For someone who never had work with template languages before I believe its a fair time. My final word on this is that doesn't look that hard to learn Freemarker templates and customizing the ones already there is not such a big deal.

In my final template i moved the place where warning icon was placed on template and it's working as expected now.


[]s

Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
I'm posting images from what I get here.....

well...

I was not able to post images from blogspot so I'm posting a link to a post where you can see the images:

http://mmaiacupoffcoffe.blogspot.com/2009/03/struts-2-customizando-elementos-de-form.html

The post is in portuguese(I'm from Brazil) but you'll easily find the images(the only ones on this link).

Tx for tips and help provided.
regards,
[]s
Marcos Maia


Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
The correct link to my blog post on this: http://mmaiacupofcoffee.blogspot.com/2009/03/struts-2-customizando-elementos-de-form.html

[]s
Marcos Maia
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 - How do I remove validation messages from fields?