• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Value Change Event is not working

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem is regarding valueChangeEvent.


This is the xhtml where I am setting the BooleanCheckBoxId=#{productItem.uniqueId}

<h:panelGrid columns="2" >
<h:panelGroup>
<h:selectBooleanCheckbox id="#{productItem.uniqueId}"
value="#{productItem.checkedValue}"
disabled="#{productItem.disabled}"
valueChangeListener="#{spcProductModel.productClicked}">
<a4j:support event="onclick"
oncomplete="retrieveActionText(this);"
reRender="paymentFormCard,actionText,includedForm,parametersCardForm,productsPanel,spcTemplateForm,productsPanel,#{paramPanelId}" />
</h:selectBooleanCheckbox>
</h:panelGroup>
<h:panelGroup>
<h:outputLabel>id="#{productItem.uniqueId}"</h:outputLabel>
<h:outputLabel
value=" #{productItem.productRelation.product.productName}"
for="#{productItem.uniqueId}"></h:outputLabel>
</h:panelGroup>
</h:panelGrid>

The unique ID has been generated using the following code:
String uniqueIds = prod.getUniqueId();

Thus the BooleanCheckbox is becoming equal to UniqueIds.
When I am printing the BooleanCheckBoxId in my front end for checking purpose, it reflects the changes made. But when I am fetching it as
String selectedId = (String) vce.getComponent().getId(); and printing the selectedId in logger, it remains same as it generated in the very first time.

SelectedId is remaining same as the old one, It does not change.
Is there anything I need to add?
Because it works fine for the first time. but when the value changes in the previous calling page, it does not work.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you correct your display name, I'll look at your problem.
 
Greenhorn
Posts: 17
IntelliJ IDE Netbeans IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nitrate developer kindly do the needful as suggested by the forum moderator.

That way we all get to learn from Tim.

Thanks
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A cynic might suspect that we're still dealing with a false name here, but it's close enough.

Incidentally, the sample XML would be a lot easier to read if you used the Code button to add formatting tags.

The "id=" attribute in JSF cannot be an EL expression. It must be a literal value. See http://docs.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/h/selectBooleanCheckbox.html where you'll note that the type must be java.lang.String, and not a ValueExpression (EL expression).

I am in doubt about using a valueChangeListener on the checkbox, but that's a secondary issue.
 
Russel Fleming
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks tim, for your response.
Could you please elaborate a bit more, so that I can implement that on my code?
I am a beginner in JSF.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use a variable expression to generate id values, so you'll have to make other arrangements.

My suspicion is that you are either expecting the valueChangeListener to be called when the checkbox is checked. That's not how JSF listeners work. JSF listeners listen to a form submit or ajax event. The valueChangeListener only gets called when the form is submitted and a change has been detected between the original displayed value and the value coming back from the submit. If you are doing any sort of serious processing, it should NOT be done in a valueChangeListener, it should be done in an action method. Stuff done in a valueChangeListener method only gets done if an actual value change is detected, and the listeners act before the backing bean is fully prepared for general action, so often what you do in a listener gets undone by later processing. The data isn't fully vetted, updated, and stable until the action method is invoked.

 
Russel Fleming
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are suggesting me to use ActionListener instead of ValueChangeListener?
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. I discourage Listeners. They reduce reusability, testability and maintainability. They have their place, but 95 times out of 100, an action method will do the same job as an ActionListener and do it as POJO code.
 
Russel Fleming
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please tell me how to implement action in the code I have given?
that would be very helpful.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something more like this:


Where productClicked is coded the same way you'd code a regular commandButton action method (public void productClicked(){....}). Except that unlike regular (non-AJAX) actions, the a4j action won't return a String, since you're staying on the same page. Hence it returns void.
 
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic