4

我有一个带有动态列的可编辑表。当我编辑一行时,所有字段都正确显示。但是当我单击“保存”图标时,我的第一个元素的值被写入错误的列。基本上我有未定义数量的翻译文件,我想显示和编辑它们。这些文件的内容如下

<entry key="contractlist_fleetmanager_status_ALL_STATUSES">All statuses</entry>

而对于德

<entry key="contractlist_fleetmanager_status_ALL_STATUSES">Alle Zustände</entry>

示例 我有 3 个不同的翻译文件 de、en 和 fr。列如下:en fr 和 de。但是在 hashmap 翻译项中,是先获取 de,然后是一些空字段,然后是 fr 和 en。

[de=Alle Zustände, null, null, null, null, null, null, null, null, fr=All statuses, en=All statuses, null, null, null, null, null]

当我调试并查看 handleRowEdit 时,selectedItem 值混淆了。第一个元素现在已经具有 en 字段的值,而不是 de 字段。

[de=All statuses, null, null, null, null, null, null, null, null, fr=All statuses, en=All statuses, null, null, null, null, null]

这是因为 en 是我的 primefaces 表中的第一列(列是: en fr de )吗?我该如何解决这个问题?

这是我的 bean 代码

private TranslationItem selectedItem;
    private List<TranslationItem> translationItems;
    private List<ColumnModel> columns = new ArrayList<ColumnModel>();

public Translation() {
        createDynamicColumns();
    }

public String handleRowEdit(TranslationItem selectedItem) throws IOException {
        setSelectedItem(selectedItem);
        getLog().debug("rowedit");
        return "";
    }
public List<ColumnModel> getColumns() {
        return columns;
    }

public List<TranslationItem> getTranslationItems() throws IOException {
        if (translationItems == null) {
            translationItems = new ArrayList<TranslationItem>();

            Properties[] props = new Properties[localeItems().length];
            int i = 0;
            for (String locale : localeItems()) {
                FileInputStream in = new FileInputStream(SiteConfig.getInstance().getDefaultConfigPath() + File.separator
                        + "language_" + locale + ".xml");
                props[i] = new Properties();
                props[i].loadFromXML(in);
                in.close();
                i++;
            }

            Enumeration<Object> keys = props[0].keys();

            while (keys.hasMoreElements()) {
                String key = (String) keys.nextElement();

                i = 0;
                Map<String, String> value = new LinkedHashMap<String, String>() {
                    @Override
                    public String put(String key, String value) {
                        return super.put(key, value);
                    }
                };
                for (String locale : localeItems()) {
                    value.put(locale, props[i].getProperty(key));
                    i++;
                }

                translationItems.add(new TranslationItem(key, value));
            }
        }
        return translationItems;
    }
public void createDynamicColumns() {

        String columnTemplate = "";
        for (String locale : localeItems()) {
            columnTemplate += locale + " ";
        }
        String[] columnKeys = columnTemplate.split(" ");
        columns.clear();

        for (String columnKey : columnKeys) {
            columns.add(new ColumnModel(columnKey, columnKey));
        }
    }
//inner class TranslationItem 
    public class TranslationItem {
        private String key;
        private Map<String, String> value;

        public TranslationItem() {

        }

        public TranslationItem(String key, Map<String, String> value) {
            this.key = key;
            this.value = value;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public Map<String, String> getValue() {
            return value;
        }

        public void setValue(Map<String, String> value) {
            this.value = value;
        }

        public String getValueLocale(String locale) {
            return value.get(locale);
        }
    }

    //inner class ColumnModel
    static public class ColumnModel implements Serializable {

        private String header;
        private String property;

        public ColumnModel(String header, String property) {
            this.header = header;
            this.property = property;
        }

        public String getHeader() {
            return header;
        }

        public String getProperty() {
            return property;
        }
    }

这是我的jsf代码

<p:dataTable id="translationtable" styleClass="ptable100" var="translation" value="#{adminTranslation.translationItems}" width="100%" height="200" widgetVar="translation"
                                        emptyMessage="#{msg.all_lists_no_records_found}" editable="true" rowKey="#{translation.key}" rowIndexVar="rowIndex" selection="#{adminTranslation.selectedItem}" selectionMode="single"
                                        resizableColumns="true" sortMode="multiple"
                                        paginator="true" rows="20" rowsPerPageTemplate="5,10,20,50,100" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}  #{msg.all_lists_numberOfRowsDisplayed_label} {RowsPerPageDropdown}"      
                >    
                    <p:ajax event="rowEdit" listener="#{adminTranslation.onEdit}" update="translationtable" />
    <p:columns value="#{adminTranslation.columns}" headerText="#{column.header}" var="column" columnIndexVar="colIndex" 
                        sortBy="#{translation.value[column.property]}" filterBy="#{translation.value[column.property]}" filterMatchMode="contains" 
                        filterPosition="top" filterStyle="float:right;width: 200px;" styleClass="ui-editable-column">  

                        <p:column >
                            <p:cellEditor> 
                        <f:facet name="output"><h:outputText value="#{translation.value[column.property]}"/></f:facet>  
                            <f:facet name="input"><h:inputText value="#{translation.value[column.property]}" styleClass="input ilarge" /></f:facet>
                           </p:cellEditor>
                        </p:column>

                </p:columns> 
<p:column >
                    <p:commandLink id="rowEditLink" actionListener="#{adminTranslation.handleRowEdit(translation)}" ajax="true" >  
<p:rowEditor id="edit"/>
                        </p:commandLink>
                </p:column>
            </p:dataTable>

我在 tomcat 7 上使用 primefaces 3.2

4

0 回答 0