• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF, javascript and textbox values  RSS feed

 
Aneek kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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:

 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!