如何制作JSF复合组件的网格?
我在 panelGrids 中有很多 outputLabel 和 inputText 对,
<h:panelGrid columns="2">
<h:outputLabel value="label1" for="inputId1"/>
<h:inputText id="inputId1/>
<h:outputLabel value="label2" for="inputId2"/>
<h:inputText id="inputId2/>
...
</h:panelGrid>
我希望对所有这些都具有一些行为:例如每个 inputText 具有相同的验证或相同的大小。因此,我创建了一个复合组件,其中仅包含一个 outputLabel 和一个 inputText
<my:editField value="field1"/>
<my:editField value="field2"/>
但现在当我将它们放入 gridPanel 中时,它们不会根据标签文本的长度进行对齐。我明白为什么,但我不知道如何解决。
I have lot's of outputLabel and inputText pairs in panelGrids
<h:panelGrid columns="2">
<h:outputLabel value="label1" for="inputId1"/>
<h:inputText id="inputId1/>
<h:outputLabel value="label2" for="inputId2"/>
<h:inputText id="inputId2/>
...
</h:panelGrid>
I want to have some behaviour for all of them: like same validation or same size for every inputText. So I have created a composite component which just includes an outputLabel and and an inputText
<my:editField value="field1"/>
<my:editField value="field2"/>
But now when I put them in a gridPanel, they do not get aligned depending on the length of the label text. I understand why, but I don't know how to work around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
复合组件确实被渲染为单个组件。您想改用 Facelet 标记文件。它的渲染与输出的渲染完全一样。下面是一个启动示例,假设您需要一个 3 列表单,并在第三列中包含消息字段。
在
/WEB-INF/tags/input.xhtml
中创建标签文件(或者当您想要在要包含的 JAR 文件中提供标签时,在/META-INF
中创建标签文件)在/WEB-INF/lib
中)。在
/WEB-INF/example.taglib.xml
中定义它(或者在/META-INF
中定义,当您想要在 JAR 文件中提供要包含在/WEB-INF/lib
):在
/WEB-INF/web.xml
中声明 taglib 的用法(当标签由 JAR 文件提供时不需要这样做)包含在/WEB-INF/lib
!JSF 将自动加载/META-INF
中的所有*.taglib.xml
文件。(多个taglib文件可以用分号
;
分隔)最后只需在主页模板中声明即可。
{bean.countries} 应返回一个
Map
,其中国家/地区代码作为键,国家/地区名称作为值)(
# :
希望这会有所帮助。
A composite component gets indeed rendered as a single component. You want to use a Facelet tag file instead. It gets rendered exactly as whatever its output renders. Here's a kickoff example assuming that you want a 3-column form with a message field in the third column.
Create tag file in
/WEB-INF/tags/input.xhtml
(or in/META-INF
when you want to provide tags in a JAR file which is to be included in/WEB-INF/lib
).Define it in
/WEB-INF/example.taglib.xml
(or in/META-INF
when you want to provide tags in a JAR file which is to be included in/WEB-INF/lib
):Declare the taglib usage in
/WEB-INF/web.xml
(this is not needed when the tags are provided by a JAR file which is included in/WEB-INF/lib
! JSF will auto-load all*.taglib.xml
files from/META-INF
).(multiple taglib files can be separated by semicolon
;
)Finally just declare it in your main page templates.
(the
#{bean.countries}
should return aMap<String, String>
with country codes as keys and country names as values)Screenshot:
Hope this helps.
panelGrid 中应该有一个开关来单独渲染复合组件。我对此有一个解决方案。您可以拥有单独的复合组件,而不是将它们组合在一起。在每个复合组件中,您可以使用 ui:fragments 来划分要分别属于不同列的组件。以下是我的 inputText.xhtml 的摘录:
现在这不会以 panelGrid 内的形式对齐:
所以我扩展了 GroupRenderer 的encodeRecursive 方法,以添加后标签和前字段:
There should have been a switch in panelGrid to render composite components separately. I have a solution for this. You can have separate composite components instead of clubbing them together. In each composite component you can use ui:fragments to demarcate the components you want to separately fall under different columns. Following is extract from my inputText.xhtml:
Now this will not going to align in the form which is inside the panelGrid:
So i have extended the GroupRenderer's encodeRecursive method, to add after label and a before field: