Meaningless Drivel is fun!*
The moose likes JSF and the fly likes a4j:repeat and generated Id problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "a4j:repeat and generated Id problem" Watch "a4j:repeat and generated Id problem" New topic
Author

a4j:repeat and generated Id problem

raluca jucan
Greenhorn

Joined: Nov 13, 2008
Posts: 1
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

Joined: Jun 25, 2001
Posts: 15960
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
 
subject: a4j:repeat and generated Id problem
 
Similar Threads
Changing appearance of form fields with validation errors
won't create tables with jaws.xml
Struts: How does indexed data get into a Form Bean?
Error while using <a4j:support>
radio buttons in a table, "index" attribute of t:radio