How to create a composite component which switches between inputText and inputSecret?

懵懂的女人 提交于 2019-12-04 16:17:36
BalusC

Use a view build time tag like JSTL <c:if> or <c:choose> instead of the JSF component's rendered attribute. View build time tags are evaluated during constructing the JSF component tree, while the rendered attribute is only evaluated during generating HTML based on the JSF component tree (and thus you still end up with both components with the same ID in the JSF component tree!).

E.g.

<c:if test="#{not cc.attrs.secret}">
    <h:inputText id="input" />
</c:if>
<c:if test="#{cc.attrs.secret}">
    <h:inputSecret id="input" />
</c:if>

See also:


Unrelated to the concrete problem, the myId doesn't make sense. Just give those a fixed ID. In case the reason was the inability to reference them from outside by ajax, head to Referring composite component ID in f:ajax render.

Whether or not the component is actually rendered doesn't matter.Both components will still exist in the view's internal component tree and will require a unique id. We ran into this problem as well.

We suffixed the id with a _1 and _2 and if we need to get a hold of the id inside javaScript, we use JQuery's partial matchers.

In your case, can you not make your bean's getMyId() method return a different id based on the value of the secret property?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!