I want to define a own textarea component that depends on Primefaces InputTextarea. I want to set the maxlenght of p:inputTextarea
only when it is set in my textarea component.
I want to set the maxlength on the p:inputTextarea
component only if the attribute is available. I tried following:
<p:inputTextarea maxlength="#{maxlength not empty ? maxlength : null}"...>
This works if a value is set, but when it is not set, the value of the primefaces component is set to 0, so that no input is possible.
Another way I've tried is to set the attribute as follows:
<c:if test="#{not empty maxlength}">
<f:attribute name="maxlength" value="#{maxlength}"/>
</c:if>
But this gives me an exception, when a maxlength is set:
ServletException: java.lang.String cannot be cast to java.lang.Integer
How can I set the attribute only if it is defined in my own component?
I found the solution, that I should use c:if
around the inputTextarea:
<c:if test="#{not empty maxlength}">
<p:inputTextarea maxlength="#{maxlength not empty ? maxlength : null}" ...>
</c:if>
<c:if test="#{empty maxlength}">
<p:inputTextarea ...>
</c:if>