title: JSF Datatable "elegant" way to edit the content of a row
body: <p><strong>EDIT1</strong>:
  As suggested by Valentin Jacquemin i implemented it with one <code>List&lt;Entry&lt;String,String&gt;&gt;</code>
  however, when i now change a value, tomcat throws an error:
  error message:</p>
  
  <pre><code>    SEVERE: /bvDesktop_RuleOverviewAddActionNode.xhtml at line 111 and column 115 value="#{paramListKVs.value}": Property 'value' not writable on type java.lang.Object
  javax.el.PropertyNotFoundException: /bvDesktop_RuleOverviewAddActionNode.xhtml at line 111 and column 115 value="#{paramListKVs.value}": Property 'value' not writable on type java.lang.Object
  </code></pre>
  
  <p>And the corresponding line in my xhtml:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;p:dataTable id="paramListKV" var="paramListKVs" value="#{ruleTreeBeanAddActionNode.paramListKV}" editable="true" editMode="cell"&gt;
      &lt;p:column&gt;
          &lt;f:facet name="header"&gt;List Key&lt;/f:facet&gt;
              &lt;h:outputText value="#{paramListKVs.key}"/&gt;
      &lt;/p:column&gt;
      &lt;p:column&gt;
          &lt;p:cellEditor id="paramListKVsEditTest"&gt; 
               &lt;f:facet name="header"&gt;List Value&lt;/f:facet&gt;
               &lt;f:facet name="output"&gt;&lt;h:outputText value="#{paramListKVs.value}"/&gt;&lt;/f:facet&gt;
               --&gt;&lt;f:facet name="input"&gt;&lt;p:inputText value="#{paramListKVs.value}" style="width:96%" /&gt;&lt;/f:facet&gt;&lt;--
          &lt;/p:cellEditor&gt;
      &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>marked by --> and &lt;--.
  I don't know what java tries to write the code to. I'm not even sure if <code>value="#{paramListKVs.value}"</code>is correct. Any ideas?</p>
  
  <hr>
  
  <p>I have a particular problem i was able to solve, but i feel like my solution is more like a dirty way. I hope that there is a more elegant way to do this, but i wasn't able to find one (searched so). So here is my problem:</p>
  
  <p>I'm currently creating a rule-based framework for automated processing of some files and I want to give our editors the possibility to create those rules in a nice and easy web interface. 
  I already have the required websites,datamodel and so on. However one particular problem is, that an Action-Rule can have a <code>Set of Properties Key-Value</code> wise. I choose a <code>TreeMap</code>. Now i want to be able to <code>add</code>, <code>delete</code> and <code>edit</code> the cells in the representing datatable. </p>
  
  <p>Java:
  createActioNode:</p>
  
  <pre><code>@ManagedBean
  public class RuleTreeBeanAddActionNode {
  ...
          private TreeMap&lt;String,String&gt; actionParamMap = new TreeMap&lt;String,String&gt;(); 
  
          private String paramKeyToAdd = "";
  
          private String paramValueToAdd = "";
  
          private int paramKeyIndex;
  
          private String valueToChange;
  
          private String keyForInfo;
  
          private UIComponent datatable;
  
          public void addKeyValueToMap() {
  
              if((paramKeyToAdd != null || !paramKeyToAdd.equals("")) &amp;&amp; (paramValueToAdd != null) || !paramValueToAdd.equals("")) {
              unusedActionParamKeys.remove(paramKeyToAdd);
              usedActionParamKeys.add(paramKeyToAdd);
  
              actionParamsAsListKeys.add(paramKeyToAdd);
              actionParamsAsListValues.add(paramValueToAdd);
  
              actionParamMap.put(paramKeyToAdd, paramValueToAdd);
              actionParamMapEntries = new ArrayList&lt;Entry&lt;Integer, String&gt;&gt;((Collection&lt;? extends Entry&lt;Integer, String&gt;&gt;) actionParamMap.entrySet());
              userSession.setAttribute("actionParamMap", actionParamMap);
              userSession.setAttribute("unusedActionParamKeys", unusedActionParamKeys);
              userSession.setAttribute("usedActionParamKeys", usedActionParamKeys);
              userSession.setAttribute("tempSelectorWorkOn", "");
              userSession.setAttribute("tempRuleId", "");
  
              userSession.setAttribute("actionParamsAsListKeys", actionParamsAsListKeys);
              userSession.setAttribute("actionParamsAsListValues", actionParamsAsListValues);
  
              paramKeyToAdd = "";
              paramValueToAdd = "";
             }
          }
  
          public void setValueToChange(String valueToChange) {
              DataTable dt = (DataTable)datatable;
              String id = String.valueOf(paramKeyIndex);
              Entry&lt;String, String&gt; temp = (Entry&lt;String, String&gt;)dt.getRowData();
              actionParamMap.put((String) temp.getKey(), valueToChange);
      }
  
          //getter and setter
  </code></pre>
  
  <p>createActionNode.xhtml</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;tr&gt;
      &lt;td&gt;Action Parameter &lt;/td&gt;
      &lt;td&gt;
          &lt;p:dataTable binding="#{ruleTreeBeanAddActionNode.datatable}" 
                       rowKey="test" 
                       rowIndexVar="paramKeyIndex" 
                       id="paramKeysValues" 
                       var="params" 
                       value="#{ruleTreeBeanAddActionNode.actionParamMapEntries}" 
                       editable="true" 
                       editMode="cell"&gt;
              &lt;p:column id="keys"&gt;
                  &lt;f:facet name="header"&gt;Param Key&lt;/f:facet&gt;
                  &lt;h:outputText value="#{params.key}"/&gt;
              &lt;/p:column&gt;
              &lt;p:column id="values"&gt;
                  &lt;f:facet name="header"&gt;Param Value&lt;/f:facet&gt;
                  &lt;p:cellEditor id="paramValueEdit"&gt;  
                     &lt;f:facet name="output"&gt;&lt;h:outputText value="#{params.value}"/&gt;&lt;/f:facet&gt;  
                     &lt;f:facet name="input"&gt;&lt;p:inputText id="evinput" value="#{ruleTreeBeanAddActionNode.valueToChange}" style="width:96%"/&gt;&lt;/f:facet&gt;  
                  &lt;/p:cellEditor&gt;  
              &lt;/p:column&gt;
          &lt;/p:dataTable&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Param To Value&lt;/td&gt;
      &lt;td&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;p:selectOneMenu id="paramKeys" value="#{ruleTreeBeanAddActionNode.paramKeyToAdd}"&gt;
                          &lt;f:selectItems value="#{ruleTreeBeanAddActionNode.unusedActionParamKeys}"/&gt;
                      &lt;/p:selectOneMenu&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;p:inputText id="paramValue" value="#{ruleTreeBeanAddActionNode.paramValueToAdd}"/&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;p:commandButton id="addParam" value="+" action="#{ruleTreeBeanAddActionNode.addKeyValueToMap}" update="paramKeysValues,paramKeys,paramValue"/&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/td&gt;
  &lt;/tr&gt;    
  </code></pre>
  
  <p>I understood that i need to return not the map but the entry set, so that the datatable can iterarte through it. So when i edit a record in the cell, the function<br>
  <code>#{ruleTreeBeanAddActionNode.valueToChange}</code> is called on a change. However to retrieve the actual record and thus the key and value to change in the map, i have to go over the <code>UIComponent</code> of <code>Datatable</code>, retrieve the edited record,save the map and rebuild the entry set.<br/> 
  <strong>So my actual question is</strong>, is this the recommended way? Did i oversee something that would make my world much easier? Has someone else implemented something like this?  </p>