Need to set component identifier attribute in JSF 1.1

Disclaimer: I understand that JSF 2.0 exists and is familiar. This question is for JSF 1.1 under IBM WebSphere .

I have heard / seen a varying degree of support for the notion that all JSF components on the page must have an identifier attribute specified at design time. When I say "ALL", I mean everything ... including components that are traditionally "output only", for example, <h:ouputText> , <h:panelGroup> , <h:panelGrid> , etc.

This question constantly arises internally in response to the occurrence of “Duplicate Component Identifiers” exceptions in the logs. Components that claim to have duplicate identifiers are sometimes identifiers generated by JSF, or are identifiers of elements that cannot be explicitly specified (for example, elements in a grid row with n-number of rows).

I am looking for some objective guidance as to which identifiers should or should (or should not) be set in relation to the gamut of JSF components.

My main problem is two options:

  • retro-active adding identifiers to everything (even things that they probably don’t need) in a crazy dash to exclude any possibility of eliminating a duplicate ID component may not be the best use of time.
  • the result of bloating in the HTML stream in run / render-time is simply ugly, for example, <span> elements with identifiers that add absolutely no constructive value to the page

ADDITION:

Based on other studies and other posts here on SO, I'm still a little confused. Which of the following is “correct” ?:

Method A: <f:subview> Indicated in the append page

 <%-- parent_page.jsp --%> <html> <f:view> <jsp:include page="included_child_page.jsp" /> </f:view> </html> <%-- included_child_page.jsp --%> <f:subview id="myID"> <h:outputText value="Some content here..." /> </f:subview> 

Method B: <f:subview> Indicated including / Parent page

 <%-- parent_page.jsp --%> <html> <f:view> <f:subview id="myID"> <jsp:include page="included_child_page.jsp" /> </f:subview> </f:view> </html> <%-- included_child_page.jsp --%> <h:outputText value="Some content here..." /> 

The vast majority of our JSPs use Method A above. We regularly get Duplicate Component ID errors from many of these pages. Several pages have been modified to use method B. We rarely / never get errors from these pages - when we do this, it is usually from components that render collections (tables / lists), where an arbitrary identifier should be generated by the implementation of Faces on runtime for this row or item.

From this experience, it was difficult for me to figure out which path should work all the time. Which method is correct ?

+4
source share
1 answer

I do not think that the specifier has ever required explicit component identifiers. If the identifier is not set by the user, the JSF should always generate it.

However, the reference implementation of JSF (RI), which, it seems to me, can be used by prehistoric WebSphere, was a very bug in 1.1, so you can suffer from errors, and not using JSF incorrectly.

+4
source

Source: https://habr.com/ru/post/1386395/


All Articles