• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a4j:repeat and generated Id problem

 
raluca jucan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have the following problem.
I am trying to set an id for a component in a a4j:repeat but my settings are overwritten. My code looks something like:
<a4j:repeat value="#{array}" var="entry" rowKeyVar="index">
<h:inputText value="#{entry.name}" required="true" id="entry" ... />
.....
Now, all of this is within a form and the required attribute works perfectly, but I also want to mark the input field with red (border) when an error occurs.
I am using FacesContext.getCurrentInstance().getClientIdsWithMessages() to get all Ids where an error occured, check if my id is in there and mark the field. The problem is it marks all the fields in my a4j:repeat with the "entry" id.
So I've tried to give a unique id like "entry#{index}" ... but the id I set gets overwritten and the field is not marked and on top of that the error message is no longer displayed.
It works in all other cases, just for the elements in the a4j:repeat not.
Does anybody know how can I see if the error message for a component is displayed or not (method to return true or false or something like that) so that I can also mark the input ?

Thanks


 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "id" attribute has 2 values in JSF.

At the JSF source level, components have simple IDs.

However, the generated HTML has more more complex IDs that are synthesized out of both the simple ID and an amalgam of its parent IDs.

Specifically, JSF has what's called a naming container. When you make a component a child of a naming container, the container ID becomes part of the generated low-level ID. An h:form, for example, is a naming container, so "h:inputText id=ssn", in a form with ID of "form1" results in a low-level ID of "form1:ssn".

However, ui:repeat is not a naming container. It's a graphical iteration directive that's frequently misused as a looping construct by people who haven't yet learned to keep logic off the JSF View templates. An h:dataTable is a naming container. So if you use it instead of ui:repeat, you can get unique IDs automatically.

As a side note, JSF works with the simple (JSF) ids. However, JavaScript and CSS operate on the generated HTML, so they need the full low-level ids.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic