Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problems getting Ajax to work properly

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am having a problem getting Ajax to work correctly. In the xhtml file I have here I am using Ajax to render some input being enabled or disabled, and it works correctly. However, further down I am also using Ajax to render an included xhtml file which contains a <h:selectOneMen/> amongst other controls, and is tagged with id="photoEnabled". When the checkbox is not checked, a dummy display tagged by id="photoDisabled" is show in its place simply for a tidy presentation on the page, and is disabled.

For some reason this does not work, and I do not understand why. However, if I replace:

it does work correctly, but the problem is that further up on the page and not shown here, I have some other input fields, and when the status of the checkbox is changed, the fields are cleared because the whole form is rendered, which I do not want.

The relevant xhtml code is here, with the two Ajax tags shown, one which works and the other which does not.

In my Java class I have various getters and setters, which all work correctly, include those associated with the checkboxes, and dummy Ajax method which does nothing but appears to be required.

Part of the code is here:

I am having a similar problem with some checkboxes earlier in the listing, and for them to work I have to use "@form" rather than specific ids, so again input fields are cleared when a checkbox is clicked.

Can someone kindly help me with the strange situation which I do not understand, and should some code be placed in the updateCheck() method in my bean?

Many thanks and I look forward to an interesting reply.
 
Saloon Keeper
Posts: 24332
167
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
Although I haven't been able to work extensively with the f:ajax tag, my experience with the RichFaces equivalent tells me that these things can be touchy sometimes. One thing you might try is to qualify the render targets like so: "@form.photoEnabled".

Reading the generated HTML can't hurt, although that sort of stuff tends to render rather cryptically.
 
Christopher Sharp
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks, and in the mean time the problem seems to have been resolved. The problems seems to have been that ui:fragment does not generate HTML, and I associated an id with a component, the same ui"fragment tag, that may not be rendered. So I kept the Ajax code as previously, namely:

then changed the code that does the rendering to this:

which now appears to work correctly, and does not affect the rest of the form.

The part above the comment is rendered when the check box is checked, and the part below is rendered as a disabled component when the check box is not checked. I am doing this as it looks better than making the menu appear when the check box is checked.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic