0

I use composite component which has InputNumber from Primefaces extensions in its basis. I've set required attribute to true and message is not shown. Also I don't have * mark which indicates that the field is required. Here is the code:

<p:outputLabel for="maxvrednost" value="#{resources['skale.maxvrednost']}" />
        <asw:inputDecimal id="maxvrednost" bean="#{attrsBean}" column="maxvrednost" required="true" disabled="#{tip == 'brisanje'}" value="#{dto.maxvrednost}"/>
        <p:message for="maxvrednost" display="icon" />

Code for composite component is:

<cc:interface>
    <cc:attribute name="bean" required="true" type="asw.iis.common.ui.beans.CommonListBackingBean" />
    <cc:attribute name="column" required="true" type="java.lang.String" />
    <cc:attribute name="value" required="true" type="java.lang.Object" />       
    <cc:attribute name="disabled" default="false" required="false"  type="java.lang.Boolean" />
    <cc:attribute name="title" required="false" type="java.lang.String" default=""/>
</cc:interface>
<cc:implementation>
    <pe:inputNumber emptyValue="" style="text-align: right;" value="#{cc.attrs.value}" required="#{cc.attrs.required}"          
        decimalSeparator="#{applicationPropertiesBean.decimalSeparator}" disabled="#{cc.attrs.disabled}"
        decimalPlaces="#{cc.attrs.bean.findNumberOfDecimalPlaces(cc.attrs.column)}" title="#{cc.attrs.title}"
        thousandSeparator="#{applicationPropertiesBean.groupSeparator}">
    </pe:inputNumber>
</cc:implementation>
miroslav_mijajlovic
  • 1,703
  • 17
  • 31

1 Answers1

1

Not a 100% proper solution but it works for me:

<composite:interface >
    <composite:attribute name="value" required="false" type="java.lang.String" default=""></composite:attribute>
    <composite:attribute name="update" required="false" type="java.lang.String" default=""></composite:attribute>
    <composite:attribute name="process" required="false" type="java.lang.String" default=""></composite:attribute>
    <composite:attribute name="requiredMessage" required="false" type="java.lang.String" default=""></composite:attribute>
    <composite:attribute name="decimalPlaces" required="false" type="java.lang.Integer" default="0"></composite:attribute>
    <composite:editableValueHolder name="value" targets="num"></composite:editableValueHolder>
    <composite:

</composite:interface>
<composite:implementation>
<div id="#{cc.clientId}">
<pe:inputNumber id="num" roundMethod="S" decimalPlaces="#{cc.attrs.decimalPlaces}" symbol="#{applicationBean.currentCurrencySymbol}" 
    minValue="0" required="true" requiredMessage="#{cc.attrs.requiredMessage}" 
    value="#{cc.attrs.value}"></pe:inputNumber>
</div>
</composite:implementation>

Use as follows:

                    <p:outputLabel value="Enter Amount" for="amt:num"></p:outputLabel>
        <p:message for="amt:num"></p:message>
        <comp:InputCurrency id="amt" roundMethod="S" decimalPlaces="0" symbol="#{applicationBean.currentCurrencySymbol}" 
            minValue="1" requiredMessage="#{loc._('Please enter amount to withdraw!')}"
            value="#{myBean.amount}"></comp:InputCurrency>

Note that 'required' attribute is hardcoded to 'true'. If I define composite component attribute 'required' and copy the value to inputNumber 'required' property it behaves as required, but does not render the '*' mark on the label. This happens because inputNumber's 'required' attribute has not been set at render time, comes back as 'false' - not sure why, didnt have time to dig into this.

rootkit
  • 2,165
  • 2
  • 29
  • 43