Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JSF and the fly likes Ajax & Myfaces problem - pages reloads with commandButton. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax & Myfaces problem - pages reloads with commandButton." Watch "Ajax & Myfaces problem - pages reloads with commandButton." New topic

Ajax & Myfaces problem - pages reloads with commandButton.

A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
I have a JSP page with simple MyFaces components like an inputText, a div and a commandButton. What I want is whatever the user types in the textbox should get into the innerHtml of the div element on click of the button. I am trying to use Ajax for this. I am using Strategy 3 from here
So I have a separate Servlet and the response is returned to the JSP.
When I test, I see that the response is captured by JSP page and the div element gets the data into it.... but just for a second or so. After that the page appears to reload and the div resets.

On further research, I found out that the page reload happens whenever I click on a commandButton in a JSF page, even if there is no Ajax call or action or onclick call. I cannot understand this specific behaviour of commandButton. The Ajax call works perfectly when I use onkeypress event on the textbox.

Can someone please advise what I must to do make the commandButton work with my Ajax call. Why is the page reloading when I click JSF commandButton component?

Thanks in advance.
[ November 24, 2006: Message edited by: A. Dusi ]
It is sorta covered in the JavaRanch Style Guide.
subject: Ajax & Myfaces problem - pages reloads with commandButton.
Similar Threads
JSF tags in Ajax response
To view row specific data by clicking on the row link
How to update the screen without reloading jsp/sertvlet ?
JSP with two forms
providing navigation without clicking a button