I have a composite component that encapsulates a JS component to input and validate phone numbers(https://github.com/jackocnr/intl-tel-input/)
The component has a visible inputText
and a hidden inputText
, the former is where the user writes and the later is where the actual number (including international prefixs and the like) is storted and it is the one that is sent to the component.
I am trying to use the component as a target for a "p:message", but it does not work unless I target the id of the hidden field.
The component:
[...]
<composite:interface>
<composite:attribute name="value" required="true" type="java.lang.String"/>
<composite:attribute name="required" required="true" type="java.lang.Boolean"/>
<composite:attribute name="onlyMobileNumbers" required="false" type="java.lang.Boolean" default="false"/>
<composite:editableValueHolder name="inputs" targets="telefonoHidden"/>
</composite:interface>
<composite:implementation>
<h:outputScript name="intl-tel-input/js/intlTelInput.js" />
<h:outputScript name="intl-tel-input/js/telefono.js" />
<h:outputStylesheet name="intl-tel-input/css/intlTelInput.css"/>
<p:inputText id="telefono" a:type="tel" required="#{cc.attrs.required}"/>
<p:inputText id="telefonoHidden" value="#{cc.attrs.value}"
required="#{cc.attrs.required}" requiredMessage="${i18n_gui['campoObligatorio']}"
type="hidden">
<p:ajax/>
</p:inputText>
<script>
[...]
</script>
</composite:implementation>
When I use the component (comp:telefono):
<div class="p-col-12 p-md-2">
<p:outputLabel for="telefono1" value="${i18n_gui['inicio.telefono']}"/>
</div>
<div class="p-col-12 p-md-4">
<comp:telefono id="telefono1" value="#{bean.telefono}" required="#true" onlyMobileNumbers="true"/>
<p:message for="telefono1:telefonoHidden"/>
</div>
Now, when I fill the form and leave the field blank, it shows as it should a message stating that the value is required (note that the numbers in the image are a placeholder):
, the issue is that in the for
of the p:message
I must target the inner field in the composite component, (telefono1:telefonoHidden), while in the for
of the p:outputLabel
it works by just targetting the composite component (telefono1).
While not a major issue, I would like to know if there is something that can be done so I can use just the composite component id in the p:message
, as it seems a bad idea to have this behavior depend on the implementation details of telefono
.
question from:
https://stackoverflow.com/questions/65560497/pmessage-for-attribute-does-not-work-for-composite-component-unless-it-targets 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…