I have an editable table with dynamic columns. When I edit a line, all fields are displayed correctly. But when I click the Save icon, the value of my first item is being written to the wrong column. Basically, I have an undefined number of translation files, and I want to display and edit them. These files have content such as
<entry key="contractlist_fleetmanager_status_ALL_STATUSES">All statuses</entry>
and for de
<entry key="contractlist_fleetmanager_status_ALL_STATUSES">Alle Zustรคnde</entry>
In the example, I have 3 different translation files de, en and fr. Columns: en fr and de. But in the hashmap translation element, that empty field appears first, and then fr and en.
[de=Alle Zustรคnde, null, null, null, null, null, null, null, null, fr=All statuses, en=All statuses, null, null, null, null, null]
When I debug and look at handleRowEdit, the selectedItem value is mixed. The first element now has the value of field en instead of field de.
[de=All statuses, null, null, null, null, null, null, null, null, fr=All statuses, en=All statuses, null, null, null, null, null]
Is this because en is the first column (columns: en fr de) in my stylesheet? How can i solve this?
This is my bean code
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)); } }
And this is my jsf code
<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>
I am using simple 3.2 elements on tomcat 7