0
votes

I am trying to generate a editable datatable dynamically dependend on the resultset of an previously executed SQL-Query. Depending on which columns would have a constant value I am trying to not render them. That part of the code works just fine, everything is displayed as i would like it to be. My issues are with the cellEditor. I generate my datable as follows:

    <p:dataTable ajax="true" var="mBT" value="#{stammdaten.bbvList}" id="meldeBearbeitungsTable" editable="true" editMode="cell" scrollable="true" scrollHeight="400" style="width:600px">
    <p:ajax event="cellEdit" listener="#{stammdaten.onCellEdit}" update=":Mb:message"/>
    <c:forEach var="column" items="#{stammdaten.columns}">
        <p:column headerText="#{column.header}">
            <f:attribute name="myCol" value="#{column}" />
            <span>
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{mBT[column.property]}"></h:outputText>
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{mBT[column.property]}">
                            <p:keyFilter regEx="/[0-9]/i"/>
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </span>
        </p:column>
      </c:forEach>
    </p:dataTable>

bbvList is a List of beans with different values.

columns is a List of beans to identify the header-Texts coresponding to the respective variables.

So now the issue itself: This is how the cellEditor looks like when i click on it: Issue-Picture

So in that example i tried to edit the field with the value "8" in it. onCellEdit gets triggered (a System.out.println is getting printed on the console) but i cant actually change the value in the respective field.

Does have cellEdit issues with the forEach initialisition of the dataTable? If yes is there a way to fix it? Else what am i doing wrong?

Since only a specific component of the html-side of code isnt working as it should be i won't post unnecessary java-Code for now. If needed i will add that as well.

Hope someone can help :)

1
You generate a <p:ajax event="cellEdit" listener="#{stammdaten.onCellEdit}" update=":Mb:message"/> for each column. Don't do that, move it outside the loop. Not sure it solves anything, but it is not good - Kukeltje
Fixed that, I think i had it originally outside of the loop, got it inside in my efforts towards a solution of the problem prior to posting the question. However that sadly wasnt the source of issue. - Proph3cy
Tried removeing <f:attribute name="myCol" value="#{column}" /><span>....</span> to? In making a minimal reproducible example. Oh and what is you PF version? Tried the latest (just for this issue)? - Kukeltje
Somehow the attribute and/or span were causing the problem. Thanks for bringning me on the right track :) - Proph3cy
Next time always create a minimal reproducible example. You'd have found it yourself then. - Kukeltje

1 Answers

0
votes

Turns out the attribute and/or span where the cause of the problem. Simply removing them solved the issue with the cellEdit. following works fine :

<p:dataTable ajax="true" var="mBT" value="#{stammdaten.bbvList}" id="meldeBearbeitungsTable" editable="true" editMode="cell" scrollable="true" scrollHeight="400" style="width:600px">
  <p:ajax event="cellEdit" listener="#{stammdaten.onCellEdit}" update=":Mb:message"/>
  <c:forEach var="column" items="#{stammdaten.columns}">
    <p:column headerText="#{column.header}">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{mBT[column.property]}"></h:outputText>
                </f:facet>
                <f:facet name="input">
                    <p:inputText value="#{mBT[column.property]}">
                        <p:keyFilter regEx="/[0-9]/i"/>
                    </p:inputText>
                </f:facet>
            </p:cellEditor>
    </p:column>
  </c:forEach>
</p:dataTable>