• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

html:errors displays before submit is hit.

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

newbie question.

Well my problem is that i have a form in file "userRegistration.do" where of course I what to send back the html:errors if any that will happen when submitting it.
It works great but my problem is that userRegistration.do show form errors before the form even being submitted.

My struts-config.xml




Ask if there is any questions about my question

thank you /Robert
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

userRegistration.do show form errors before the form even being submitted.



Could you explain what you mean by this?
From which page do you see the errors?
What are the errors?
Which class creates the errors?
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got a form in userRegistration.do.

Like this:


When i first surf in to that page the html:errors displays and i only want them to show when i have submitted the form and the validate() method should be called in the actionForm.

example errors:
# The first name was blank
# The last name was blank

UserRegistrationForm(validates) creates the errors.

I hope you now see the picture
Else ask again.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems there is an actionmapping associated with the form and it is being hit as you "surf to the page". Possibly a Setup Action?

Anyway, if there is some such action you should set validate=false in its mapping.
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Marc Peabody, but I really don't understand what you mean.

Only mapping to userRegistration is the one i posted in the first post above.

If i set validate="false" it that one it will never be validated even when i press submit if i understand how things work in struts.

really appreciate your help.

/Robert
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let's back up.

How do you get to this page?
Is it a link to the jsp?
Is it a link to an Action that forwards to the jsp?
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehe great

I just type in the browser: http://localhost:8080/strutsProj/userRegistration.do

and as you can see in my first post it loads the jsp page called:
userRegistration.jsp

in that jsp page i have the form for registration.

Next you want to know?
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been thinking.. Should i put up one more action mapping to the same jsp file and with that one just forward.
And keep the other one for the form tag.

I have read that i should never point direct to a jsp page so thats why i think about this. If i just type in the jsp page directly the html:errors will work as they are supposed to.

 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah... there lies the problem.

You are entering the submitting action of the jsp.
The ActionMapping for userRegistration.do kicks in and calls the validate method of userRegistrationForm. Validation obviously does not pass because your request does not include any parameters. Since validation fails it passes the request along to the "input" of the ActionMapping, which is your userRegistration.jsp

The Address bar of your browser in Struts is a bit of a paradigm shift. We are used to it displaying the next page we want to see. In Struts, we'll typically see what we last asked the server to "do"... which usually is something associated with the previous page.

If you do not want to link directly to the jsp as you mentioned, it might be worth creating an ActionMapping called "gotoUserRegistration.do" or something to that nature. You will probably want to use a SuccessAction.
Something like:

SuccessAction you can get from Scaffold or make your own. It just returns mapping.findForward("success")

Hope this is helpful.
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah thanks, you explained what I tried to explain for you =)

I did as you described with a successAction. I wonder is this the best way to go or should i think over something?

I got a second question to.
info:I use struts 1.1
well i wonder how i can use xhtml strict.
In regular html i have this:

I have tried two ways in Struts style.

If i browse the page and take view source the start tag <html> doesnt even show.
If i use following:

I get this output in view source:
<html xmlns="http://www.w3.org/1999/xhtml"; lang="en" xml:lang="en"></html>

Why is there </html> at the end of the line?
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use the combination of those first two codeblocks there.

The main goal of <html:xhtml/> is really to force the other html:XXX tags in Struts to render as xhtml.
 
Robert Skyttberg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aha i see. Thank you.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic