Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF: simple "required" validation problem

 
Javoso Torso
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning!

I have a required validation on a inputText field. If I submit without having inserted a char or a number there, it notifies the error and does not commit. And thats all ok and what I want to have.

My problem is if I want to cancel (go back to the main page) or reset (clear all giving entries and restoring the olds). If I was editing the field (so: load state was field having an entry) and let it empty: I cannot cancel or reset. I cannot go further if I do not insert something there.

By cancel or reset I would like to continue and not being forced to input something!

I had it using Struts. How is the way with JSF?

Thanks for any solution!

Regards,
Javo


PS: I realized to late that there is a special forum for JSF...
Can someone move this there?
[ January 24, 2005: Message edited by: Javoso Torso ]
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to JSF.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the attribute immediate=true to your inputText. Then when you hit cancel it won't perform the validation. You might want to take a look at this and this for some interesting issues I had when using the immediate attribute though. But for what you want, it should work perfectly.
 
Javoso Torso
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try immediate="true"


And the prob then is that I also use javaScript while cancelling.


Even that js call is being avoid if you use immediate...


so: I need to redesign...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Javoso Torso:
I try immediate="true"


And the prob then is that I also use javaScript while cancelling.


Even that js call is being avoid if you use immediate...


so: I need to redesign...


Good luck. Basically what I did is just some manual server side validation. When my action is triggered the first thing I do is validate my textfield. I'll return a FacesMessage with the error message. Just don't put any validation code in your cancel/reset action. That's really about the only way that I know of.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

By cancel or reset I would like to continue and not being forced to input something!
I had it using Struts. How is the way with JSF?

[/QB]


Have you tried putting immediate="true" in your Reset and Cancel button "only".

It doesn't works for me (but theortically it should work).
I too use javascript to erase the values of the fields having validation

For "Cancel", there is another "silly" approach.
Put your Cancel button in different form, so when you will click it, only that blank form will be submitted and since no component is present, there won't be any validation

[But I will advise to first try doing reset and cancel with immediate=true only]
[ January 24, 2005: Message edited by: K Varun ]
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Add the attribute immediate=true to your inputText. Then when you hit cancel it won't perform the validation.


Here you are ensuring that validation "must" take place before submission

immediate=true ensures events,conversion,validation should take place in APP_REQ_PHASE only for the component it is attached to and thereafter it moves to update model phase.
In short, that component goes through normal life cycle.

Other component doesnt goes through validation phases, hence, since their validation isn't done, they dont go to updateModel phase OR any of the later phases.
[ January 24, 2005: Message edited by: K Varun ]
 
Javoso Torso
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it isn�t funny? the required="true" should simplify programmers life and here are we discussing 1000 of possibilities to get it work...

I also have now some "own" validations on the server side

even if I find the solution with the second form very funny ... hacky

All these frameworks should allow to have clean code and what happen: we hack around

Regards,
Javo

PS: This will become my signature now:
I hate to hack
I hate try and error
[ January 24, 2005: Message edited by: Javoso Torso ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Varun:


Here you are ensuring that validation "must" take place before submission

immediate=true ensures events,conversion,validation should take place in APP_REQ_PHASE only for the component it is attached to and thereafter it moves to update model phase.
In short, that component goes through normal life cycle.

Other component doesnt goes through validation phases, hence, since their validation isn't done, they dont go to updateModel phase OR any of the later phases.

[ January 24, 2005: Message edited by: K Varun ]



CRAP! I meant to use immediate on the cancel button. Sorry about that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic