Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

JSF, javascript and textbox values

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to display value in jsf textbox from javascript code? When I do that with readonly="true" , an error occurs, Transaction aborted..However with attribute readonly = "false", record is saved? I dont understand the logic behind this. Can anyone help me ? Here is my code:

The textboxes are as follows:

Saloon Keeper
Posts: 25466
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
Before I answer that, I want to point out that JSF backing beans are not Controllers.

In JSF, the Controllers are in the FacesServlet and in the tags. Developers only supply Models (backing beans) and View Templates (xhtml). The executable logic in backing beans is not Controller code. The sole purpose of an MVC Controller is to synchronize data between a Model and a View, not to provide business logic.

Now that I've finished being pedantic, here's your answer:

JSF uses a concept called a naming container. Normally, every ID in an XML file must be unique, per the XML spec, but JSF View Templates are reduced to HTML code and certain constructs end up up producing more than 1 id-associated element. The most obvious example of this would be a field within a dataTable, where the field would be generated for every row in the displayed HTML TABLE.

To work around this, the true ID's of these objects is not the same ID as the one you specified in your View Template. Instead, the name of the element is concatenated with the name of its naming container. And if that naming container appears within another naming container, that name is concatenated as well.

So, for example, for the text control named "ssn" on the third row of table "t1" within form "inforForm", the actual ID would be something like "infoForm:t1:2:ssn".

JavaScript works on the generated HTML, not on the JSF, so when JavaScript needs access to HTML elements the getElementById function needs the expanded ID, not the JSF ID. When in doubt, display the page source in your browser to see the expanded IDs on the actual HTML.

Note that if you do not supply an explicit ID for a JSF element, one will be automatically generated. For example: "j_132". These IDs cannot be reliably predicted, however, and are subject to change without warning, so if you need a predictable ID, supply one explicitly.
This guy is skipping without a rope. At least, that's what this tiny ad said:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic