如何动态添加JSF组件
我可以动态添加 JSF 组件吗?我需要一个带有按钮的表单,该按钮应向表单添加一个
。这可能吗?
我知道这在 JavaScript 中应该是可能的。有人知道如何在 JSF 中做到这一点吗?我认为主要问题是如何通过 #{value}
获取或设置新输入的值。
Can I add JSF components dynamically? I need to have a form with a button which should add one <h:inputText>
to the form. Is this possible?
I know this should be possible in JavaScript somehow. Do anybody know how to do this in JSF? I think the major problem is how do I get or set values of new inputs via #{value}
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
或
之类的迭代组件来显示动态大小的实体List
。创建 bean@ViewScoped
以确保在同一视图上的回发过程中记住该列表,而不是一遍又一遍地重新创建。使用
的启动示例(使用
时,只需将
替换为>
和
,例如或
>):
托管 bean:
模型:
另请参阅:
Use an iterating component like
<h:dataTable>
or<ui:repeat>
to display a dynamically sizedList
of entities. Make the bean@ViewScoped
to ensure that the list is remembered across postbacks on the same view instead of recreated over and over.Kickoff example with
<h:dataTable>
(when using<ui:repeat>
simply replace<h:dataTable>
by<ui:repeat>
, and<h:column>
by e.g.<li>
or<div>
):Managed bean:
Model:
See also:
应该是这样的,
将表单标签绑定到事件的 bean 属性
,创建输入组件的新实例
并附加到您的表单
It's should be like that
Bind a form tag to the bean property
on event, create a new instance of the input component
and attach to the your form
使用
h:dataTable
动态添加元素...拥有一个您想要为dataTable提供值的任何类型的列表...在
h:dataTable
...您可以包含要在
内创建的元素标记,它将用于生成您想要动态创建的元素。
Use
h:dataTable
to add elements dynamically... Have a list of any type you want to provide values for dataTable...In
h:dataTable
... you can include the element tag to create inside<h:column>
It will be used to generate elements you want to create dynamically.