jQuery in Action, 3rd edition
The moose likes JSF and the fly likes first button click reloads page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "first button click reloads page" Watch "first button click reloads page" New topic

first button click reloads page

Tammy Easterby

Joined: Jan 31, 2007
Posts: 28
Has anyone ever had this happen to them? You load a JSF page, and you click on a submit button, and all it does is refresh the page.

Does anyone know why that happens?
rajani varma
Ranch Hand

Joined: Dec 21, 2006
Posts: 30
Hello Tammy,
There can be lot of reasons for this to happen,
1. If there is no action attribute defined
2. If there are any validation errors in the page, then the action method in the bean is not invoked and just the page refreshes.
3. If Navigation is not defined in the facesConfig.xml, then the same page refreshes....

Hope this helps you...

Tammy Easterby

Joined: Jan 31, 2007
Posts: 28
hi rajani,

thank you very much for the info.

the action is defined. when you click a button, the action is supposed to fire, and then the same page is supposed to come back with refreshed data. so i guess all that's left is maybe there's a validation error on the page. does that sound reasonable? and how would i check that?

- tammy
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Add a <h:messages /> tag to your page for displaying validation messages.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Tammy Easterby

Joined: Jan 31, 2007
Posts: 28
OK. I added <h:messages and there aren't any.
So I'm doing some System.out's and discovered that it looks like it's doing an extra "restore view" cycle.

I'm using an SDO to talk to the database. So it calls the methods to fetch the information TWICE on the first button click, thereby resetting anything that was entered on the form. On the second button click, the method to fetch info from the database is called once, and the information entered on the form is saved.

Any ideas?
Ravindra Rawat
Ranch Hand

Joined: Dec 09, 2004
Posts: 34
Try using immediate="true" on the submit button. If it works then probably it has something to do with validations.

Are there any valueChangeListeners on the page? if yes, try adding Sysouts there, Also check if FacesContext.responseComplete is being invoked anywhere in bean?

Hope it helps.

David O'Meara

Joined: Mar 06, 2001
Posts: 13459


This is your third and last request to fix your display name.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

Tammy Easterby

Joined: Jan 31, 2007
Posts: 28
Thanks, everyone, for your help. I did try immediate="true" on the submit button. That didn't work. Everyone who mentioned validations was correct. As soon as I added a numeric validation to the fields I was trying to capture it was fine. I think JSF goes through the validations phase whether you are doing error checking or not. If you are *not* doing error checking, it will hit this phase and refresh the page on you. Good to know.

Thanks again, everyone.
I agree. Here's the link: http://aspose.com/file-tools
subject: first button click reloads page
It's not a secret anymore!