【问题标题】:jsf tabledata dynamic inputtextjsf tabledata动态输入文本
【发布时间】:2013-10-16 21:04:18
【问题描述】:

我的支持 bean 中有一个列表。我想把它放在一张桌子上。我希望表格有两行 - 左侧,列表中的值,右侧输入框。这是容易的部分。这是我的代码:

<div class="table">
                <h:dataTable id="korekty" styleClass="table table-hover"
                value="#{searchBean.listX}" var="v">
                    <h:column>
                        <f:facet name="header">XXX</f:facet>
                        #{v.string}
                    </h:column>
                    <h:column>
                        <f:facet name="header">YYY</f:facet>
                        <h:inputText styleClass="form-control">
                        </h:inputText>
                    </h:column>
                </h:dataTable>
            </div>

我的问题的难点在于:在那些输入文本中,用户可能会输入一些数字。然后在点击提交按钮后,我想创建一个列表/地图/输入值的任何内容。我怎样才能做到这一点?感谢您的帮助

【问题讨论】:

    标签: jsf dynamic input datatable


    【解决方案1】:

    首先,准备一个数组或列表,其中包含给定数据的占位符以及您已获得的列表:

    List<String> initialData = ...;//initial data of n size
    String[] submittedData = new String[initialData.size()];//array of the same size
    

    然后,将&lt;h:dataTable&gt; 组件绑定到视图以访问迭代的当前行索引。这样,您可以通过将输入元素的值绑定到数组/列表中的相应对象来完成您的工作:

    <h:dataTable binding="#{table}" ... >
        <h:column>
            <f:facet name="header">YYY</f:facet>
            <h:inputText value="#{searchBean.submittedData[table.rowIndex]}" ... />
        </h:column>
    </h:dataTable>
    

    【讨论】:

    • 我收到如下错误:/secure/add_korekta.xhtml @63,88 value="#{searchBean.submittedData[table.rowIndex]}": null。可能是什么问题?我完全按照你的建议做了。
    • OK - 我将 submitData 的初始化连同 initialData 的初始化一起移到 @PostConstruct,然后它就起作用了。谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    相关资源
    最近更新 更多