将动态表单的多个提交值映射到单个 bean 属性
我有以下 JSF 表单:
<h:form>
<ui:repeat value="#{list.categories}" var="cat">
<h:selectOneRadio id="sel1Rad" value="#{list.choose}" layout="pageDirection">
<f:selectItems value="#{list.names}"/>
</h:selectOneRadio>
</ui:repeat>
<h:commandButton id="submit" action="#{list.submit}" value="Submit"/>
</h:form>
和一个名为 list
的组件。变量 cat
被注入到组件中,由方法 list.getNames()
使用。我想要发生的是为每个无线电组调用 list.choose()
。我不确定 JSF 是否可以实现这一点。每个 selectOneRadio
或 selectOneMenu
组都有一个不同的单独方法。
由于我有未知数量的类别,我不能/不想为每个可能的选择定义一个方法。
当我提交表单时,我所有的选择都会在 POST 中发送,我只是不知道告诉 Seam 如何将它们分派到我的组件的正确方法。
任何帮助表示赞赏!
I've got the following JSF form:
<h:form>
<ui:repeat value="#{list.categories}" var="cat">
<h:selectOneRadio id="sel1Rad" value="#{list.choose}" layout="pageDirection">
<f:selectItems value="#{list.names}"/>
</h:selectOneRadio>
</ui:repeat>
<h:commandButton id="submit" action="#{list.submit}" value="Submit"/>
</h:form>
And a component named list
. The variable cat
is injected to the component, used by the method list.getNames()
. What I am trying to have happen is to have list.choose()
be called for each radio group. I'm not sure if this is possible with JSF. There is a distinct separate method for each selectOneRadio
or selectOneMenu
group.
Since I have an unknown number of categories, I can't / don't want to define a method for each possible choice.
When I submit the form, all my choices are sent in the POST, I just don't know the correct way to tell Seam how to dispatch them to my component.
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
#{list.choose}
设为由当前迭代类别标识的数组、Collection 或 Map。Map
(其中键代表类别,值代表所选选项)可能是最简单的。这是一个可以在这里工作的 MCVE 。
结合
Make
#{list.choose}
an array, Collection or Map which is identified by currently iterated category. AMap<String, String>
wherein the key represents the category and the value represents the selected option is probably the easiest.Here's a MCVE which works right here.
in combination with