创建参数化多用途自定义 Facelet 标签的最佳方法是什么
我创建了一个 Facelet 标签,用于渲染带有标签的文本输入。 这对于避免一遍又一遍地重复相同的代码非常有帮助。
尽管我正在努力处理这个单个选项卡中的不同用例(日期与文本、必需与非必需、文本区域与普通文本等),但
我最终在我的组件中拥有多个标签,所有标签都或多或少复杂的渲染属性,如下所示:
<h:inputText
onblur="makeNotEmpty(this)"
onfocus="makeNotEmptyFocus(this)"
id="#{cid}"
value="#{value}"
rendered="#{textarea!='true' and type!='email' and notrequired!='true' and nullablenumber!='true'}"
style="#{style }"
required="true"
disabled="#{disabled }">
<f:validator validatorId="notnull"/>
</h:inputText>
<h:inputText
onblur="
makeNotEmpty(this)"
onfocus="makeNotEmptyFocus(this)"
id="#{cid}"
value="#{value}"
rendered="#{type=='email'}"
style="#{style }"
required="true"
disabled="#{disabled }">
<f:validator validatorId="email" />
<f:validator validatorId="notnull"/>
</h:inputText>
当然,这不是最佳的,而且写起来相当乏味。 我认为的另一个问题是,使用这种方法,我在组件树中拥有多个具有相同 ID 的组件(我不确定这是否是一个问题,因为一次只渲染一个具有相同 ID 的项目,但我看到了一些奇怪的情况)重新创建页面树的问题让我相信这是一个问题)
我正在使用 ICEFaces 1.8.2 (但问题应该与实现无关)。 对此有什么解决办法呢?使用 ?还有别的事吗?谢谢!
I created a Facelet tag for rendering a textinput with a label.
That's very helpful when for avoiding repeating the same code over and over again.
Though I'm struggling with handling different use cases within this single tab (date vs. text, required vs. not required, textarea vs. normal text etc.)
I ended up with having multiple tags within my component all with a more or less complicated rendered attribute, like shown here:
<h:inputText
onblur="makeNotEmpty(this)"
onfocus="makeNotEmptyFocus(this)"
id="#{cid}"
value="#{value}"
rendered="#{textarea!='true' and type!='email' and notrequired!='true' and nullablenumber!='true'}"
style="#{style }"
required="true"
disabled="#{disabled }">
<f:validator validatorId="notnull"/>
</h:inputText>
<h:inputText
onblur="
makeNotEmpty(this)"
onfocus="makeNotEmptyFocus(this)"
id="#{cid}"
value="#{value}"
rendered="#{type=='email'}"
style="#{style }"
required="true"
disabled="#{disabled }">
<f:validator validatorId="email" />
<f:validator validatorId="notnull"/>
</h:inputText>
Of course that's no optimal and rather tedious to write.
One other problem I think is that using this approach I have multiple components with the same ID in the component tree (I'm not sure if that's a problem as only one item having the same ID is rendered at one time but I saw some strange problems re-creating the page tree making me belive it's a problem)
I'm using ICEFaces 1.8.2 (but the problem should be implementation independent).
What's the solution for this? Using ? Something else? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
放入 JSTL
中。它将在标签构建期间创建。顺便说一句,IceFaces 不是 JSF 实现,它是一个 JSF 组件库,应该在 JSF 实现之上运行。Mojarra 和 MyFaces 是 JSF 实现。
You can put
<f:validator>
in a JSTL<c:if>
. It will be created during tag build time.By the way, IceFaces isn't a JSF implementation, it's a JSF component library which is supposed to run on top of a JSF implementation.. Mojarra and MyFaces are JSF implementations.