primefaces-可编辑的动态表 [英] primefaces - editable dynamic table

查看:104
本文介绍了primefaces-可编辑的动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明-这不是

DISCLAIMER - THIS IS NOT DUP OF Is it possible to use p:cellEditor inside a p:columns tag? (read both first)

我正在尝试根据我的情况调整此解决方案- http: //forum.primefaces.org/viewtopic.php?f=3&t=13275

I am trying to adapt this solution to my context - http://forum.primefaces.org/viewtopic.php?f=3&t=13275

我有一个像这样的动态表

I have a dynamic table like this

Managed Bean

Managed Bean

@ManagedBean
@ViewScoped
public class MyMB implements Serializable {

private List<String> columns = new ArrayList<String>();

private List<Map<String,String>> data;

private List<Map<String,String>> filteredData;

private String defaultColumnSort;

public void onCellEdit(CellEditEvent event) {  
    System.out.println(event.getRowIndex());
}  

(...)

和xhtml

            <p:dataTable 
            var="dataRow" 
            value="#{myMB.data}" 
            paginator="true" rows="10"  
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"  
            rowsPerPageTemplate="10,50,100" 
            emptyMessage="No sites found with given criteria" 
            filteredValue="#{myMB.filteredData}"
            editable="true" 
            editMode="cell"
            sortBy="#{myMB.defaultColumnSort}"
            id="rowsTable">              
            <p:ajax event="cellEdit" listener="#{myMB.onCellEdit}"/>
 <ui:remove>
            <p:columns value="#{myMB.columns}" var="column" columnIndexVar="colIndex" sortBy="#{column}" filterBy="#{column}" filterMatchMode="contains">  
                <f:facet name="header">#{column}</f:facet>  
                <p:cellEditor>  
                    <f:facet name="output">
                        <h:outputText value="#{dataRow[column]}" />
                    </f:facet>  
                    <f:facet name="input">
                        <p:inputText id="modelInput" value="#{dataRow[column]}" style="width:96%"/>
                    </f:facet>  
                </p:cellEditor>
            </p:columns>
</ui:remove>

            <c:forEach items="#{myMB.columns}" var="column" varStatus="loop">
                <p:column headerText="#{column}">
                   <p:cellEditor>
                      <f:facet name="output">
                         <h:outputText value="#{dataRow[loop.index].value}" />
                      </f:facet>
                      <f:facet name="input">
                         <p:inputText value="#{dataRow[loop.index].value}"  />
                      </f:facet>
                   </p:cellEditor>     
                </p:column>
             </c:forEach>               

ui:remove之间的部分起作用(如果我显然删除了ui:remove标签),并向我显示了不可编辑的表.

the part between ui:remove works (if I remove the ui:remove tag obviously) and shows me the non-editable table.

我正在尝试将p:cellEditor行为添加到这些单元格中,但是由于它不适用于p:columns,因此上面的链接建议使用c:forEach将p:columns解包为多个p:column项目,并且,对于其中每个,请应用p:cellEditor.

I am trying to add the p:cellEditor behavior to these cells, but since it does not work with p:columns, the link above suggests to use c:forEach to unwrap p:columns into several p:column items and, for each one of them, apply p:cellEditor.

上面的链接还引用了无效链接-

The link above also references a dead link - https://stackoverflow.com/questions/10229453/jsf-using-primefaces-datatable-to-implement-a-generic-table-viewer-editor-based :-(

问题是:ui:remove外部的部分进行编译并向我显示了一个带有空单元格的表,所以听起来我在这里弄乱了h:outputText值的值语法.

The problem is: the part outside ui:remove compiles and shows me a table with empty cells, so it sounds like I am messing with the value syntax here for h:outputText value.

在这种情况下声明单元格内容的正确方法是什么?

我正在使用素数4.

推荐答案

问题出在这一行

<p:columns value="#{mappingEngineSearchMB.columns}" var="column" columnIndexVar="colIndex" sortBy="#{column}" filterBy="#{column}" filterMatchMode="contains">  

由于该表是可搜索的并且可以过滤,因此这些都是期望值.

since the table is searchable and can be filtered, these were expected values.

由于JSF是如此离散,所以它决定不告诉任何错误(JSF是离散的),并决定只渲染很多空表.

since JSF is so discrete, it just decided not to tell anyone the error was that (JSF is soooooooooo discrete) and decided to just render a lot of empty tables

现在表格可以正常工作了.

now the table works fine.

这篇关于primefaces-可编辑的动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆