[
https://issues.apache.org/jira/browse/MYFACES-4026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15143891#comment-15143891
]
Leonardo Uribe commented on MYFACES-4026:
-----------------------------------------
I see the intention. The clientId is something that is controlled by the
rendering engine that in some cases needs to be "calculated" in order to get
the final identifier in the html markup. So you cannot really assign a clientId
to an id, because in breaks the concept.
To do what you want it is necessary to override the composite component
renderer. That's possible if you provide a custom componentType and then
override the rendererType. Example:
{code:java}
public class InputHtml extends HtmlInputText implements NamingContainer,
UniqueIdVendor {
public static final String COMPONENT_TYPE = "org.apache.myfaces.InputHtml";
public static final String DEFAULT_RENDERER_TYPE =
"org.apache.myfaces.InputHtml";
public InputHtml() {
setRendererType(DEFAULT_RENDERER_TYPE);
}
{code}
and finally provide a custom renderer that behaves just like the default one,
but insert the required markup before and after the content.
I think there is not a bug here, this issue should be closed as won't fix.
> Composite Component cc.clientId not usable in custom tag
> --------------------------------------------------------
>
> Key: MYFACES-4026
> URL: https://issues.apache.org/jira/browse/MYFACES-4026
> Project: MyFaces Core
> Issue Type: Bug
> Components: General
> Affects Versions: 2.1.17
> Reporter: Thomas Herzog
> Priority: Trivial
> Attachments: demo.zip
>
>
> If you use the cc.clientId in a custom tag, then the wrong ids are generated.
> {code:xml}
> <composite:implementation>
> <cure:grid id="#{cc.clientId}">
> <cure:gridRow>
> <cure:gridCol width="12">
> my col
> </cure:gridCol>
> </cure:gridRow>
> </cure:grid>
> </composite:implementation>
> {code}
> Here we need an id otherwise an update on this component will fail since
> there wouldn't be an html node on the client side which contents can be
> replaced by an update. There are some cases where the composite component is
> not allowed to define an div which holds the client id.
> {code:xml}
> <composite:implementation>
> <!-- Would break grid container specification -->
> <div id="#{cc.clientid}">
> <cure:gridRow>
> <cure:gridCol width="12">
> my col
> </cure:gridCol>
> </cure:gridRow>
> <div>
> </composite:implementation>
> {code}
> We think this is caused by the fact that the cc.clientId is accessed during
> build view time and gets cached in the UIComponentBase. At this time the
> cc.clientId is empty. This seems to be a common issue, because cc.clientId
> can never be accessed at build view time.
> {code:title="UIComponentBase#getClientId"}
> @Override
> public String getClientId(FacesContext context)
> {
> if (context == null)
> {
> throw new NullPointerException("context");
> }
> if (_clientId != null)
> {
> return _clientId;
> }
> ...
> }
> {code}
> {code:xml|title="one of the custom tags we use"}
> <ui:composition
> xmlns:c="http://java.sun.com/jsp/jstl/core"
> xmlns:f="http://java.sun.com/jsf/core"
> xmlns:h="http://java.sun.com/jsf/html"
> xmlns:p="http://primefaces.org/ui"
> xmlns:ui="http://java.sun.com/jsf/facelets">
>
> <c:set var="styleClass" value="#{not empty styleClass ? styleClass : ''}"
> />
> <c:set var="style" value="#{not empty style ? style : ''}" />
> <c:set var="rendered" value="#{not empty rendered ? rendered : true}" />
> <c:set var="isFormRow" value="#{not empty isFormRow and isFormRow}" />
>
> <c:if test="#{not empty id}">
> <h:panelGroup id="#{id}" layout="block" styleClass="#{isFormRow
> ? 'form-row' : ''} #{styleClass} ui-grid-row" style="#{style}"
> rendered="#{rendered}">
> <ui:insert/>
> </h:panelGroup>
> </c:if>
>
> <c:if test="#{empty id}">
> <h:panelGroup layout="block" styleClass="#{isFormRow ?
> 'form-row' : ''} #{styleClass} ui-grid-row" style="#{style}"
> rendered="#{rendered}">
> <ui:insert/>
> </h:panelGroup>
> </c:if>
>
> </ui:composition>
> {code}
> {code:html|title="resulting html"}
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head></head>
> <body>
> <form id="myForm1" name="myForm1" method="post"
> action="/jsf2-basic-portlet/index.xhtml"
> enctype="application/x-www-form-urlencoded">
> <div id="composite1:composite1" class=" ui-grid ui-grid-responsive">
> <div class=" ui-grid-row">
> <div class=" ui-grid-col-12">
> my col
> </div>
> </div>
> </div>
> <input type="hidden" name="myForm1_SUBMIT" value="1" /><input
> type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState"
> value="puXzCX78lsGwm5D7TAEgUKup9vm0hFpybGfw7y1R85EQt46s" />
> </form>
> <form id="myForm2" name="myForm2" method="post"
> action="/jsf2-basic-portlet/index.xhtml"
> enctype="application/x-www-form-urlencoded"><span
> id="myForm2:composite2:myOutputText">OutputText</span><input type="hidden"
> name="myForm2_SUBMIT" value="1" /><input type="hidden"
> name="javax.faces.ViewState" id="javax.faces.ViewState"
> value="puXzCX78lsGwm5D7TAEgUKup9vm0hFpybGfw7y1R85EQt46s" /></form>
> </body>
> </html>
> {code}
> I have an sample which I could provide but here is no option to upload it.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)