GeeCON Prague 2014*
The moose likes JSF and the fly likes Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax "Change" Event Doesn Watch "Ajax "Change" Event Doesn New topic
Author

Ajax "Change" Event Doesn't Fire When Clicking HTML "Reset" Button

Chris Gabel
Greenhorn

Joined: Jan 17, 2011
Posts: 7
I have a JSF web app that uses ajax on a h:selectOneListbox to update another field on the screen with CSS. When I click the HTML "reset" button, the value in the h:selectOneListbox changes, but the ajax event doesn't fire.

Example: The h:selectOneListbox can contain values of USER, ACCT, NONE, EMAIL. I want to hide the Email input field and its label when "EMAIL" is not selected. As I change the drop down menu from value to value, it hides and shows the email fields as it should. If I start with "USER" selected and the email field hidden, then select "EMAIL" (which makes the email fields appear), then click the HTML "reset" button", the drop down menu changes back to "USER" but the email field is still visible. The ajax event to hide it hasn't fired.

Does anyone know why?


Code: (the drop down menu)


Code: (the email/emailLabel fields I am hiding)


Code: (CSS)
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2452
    
    8

You should use the "valueChange" event for the ajax call in your selectOneMenu and use "update=email emailLabel" instead of render. Then in the email and emailLabel, use render=<some condition> such the value in the selectOneMenu=email

From my experience render from such ajax calls sometimes doesn't work so an alternative is use disable instead. disable=false when selectOneMenu=email

Hope this help.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

The "reset" button renders as an HTML <INPUT TYPE="RESET"> control element. The HTML RESET button does not submit a form the way the SUBMIT button does. Instead, it initiates action within the client itself. The client (browser) will restore whatever values the related form had when the page was rendered.

Since AJAX is just a specialized type of form SUBMIT and RESET doesn't submit, that's why events don't fire and listeners are not invoked.


Customer surveys are for companies who didn't pay proper attention to begin with.
Chris Gabel
Greenhorn

Joined: Jan 17, 2011
Posts: 7
K. Tsang: I'm not sure what you mean. You want me to add another ajax field to the "email" inputText and "emailLabel" outputText fields? Did you want me to get rid of the conditional styleClass parameters? Something like this?



Tim Holloway: Thanks for the explanation.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2452
    
    8

Hi Chris I probably didn't explain it really good. What I really meant is something like:



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

Hint: if you value your hair follicles, put the styleClass logic into a backing bean property.

Debugging EL can be a real :censored: Plus, it's more efficient to have the java compiler evaluate the logic.
 
GeeCON Prague 2014
 
subject: Ajax "Change" Event Doesn't Fire When Clicking HTML "Reset" Button