Note that there are some explanatory texts on larger screens.

plurals
  1. POjsf get selectOneMenu value from actionListener of h:commandButton
    primarykey
    data
    text
    <p>I have a primefaces datatable with the attribute editable="true" so I can't edit the rows dynamically. I have two fields: an inputText and a selectOneMenu. I want to be able to add rows dynamically from the footer. I added empty field in the footer and when the user click a button, I want to add the new line to the datatable with the correct values.</p> <p>Here is the code I have:</p> <pre><code>&lt;h:form&gt; ... &lt;p:dataTable value="#{bean.myObjects}" id="myDatatable" editable="true" var="obj"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="My Datatable" /&gt; &lt;/f:facet&gt; &lt;p:column headerText="My String value"&gt; &lt;p:cellEditor&gt; &lt;f:facet name="output"&gt; &lt;h:outputText value="#{obj.myString}" /&gt; &lt;/f:facet&gt; &lt;f:facet name="input"&gt; &lt;p:inputText value="#{obj.myString}"/&gt; &lt;/f:facet&gt; &lt;/p:cellEditor&gt; &lt;f:facet name="footer"&gt; &lt;h:inputText value="#{bean.myNewObject.myString}" /&gt; &lt;/f:facet&gt; &lt;/p:column&gt; &lt;p:column headerText="My List Value"&gt; &lt;p:cellEditor&gt; &lt;f:facet name="output"&gt; &lt;h:outputText value="#{bean.myListValue ? 'yes' : 'no'}" /&gt; &lt;/f:facet&gt; &lt;f:facet name="input"&gt; &lt;h:selectOneMenu value="#{bean.myListValue}" &gt; &lt;f:selectItem itemValue="true" itemLabel="yes" /&gt; &lt;f:selectItem itemValue="false" itemLabel="no" /&gt; &lt;/h:selectOneMenu&gt; &lt;/f:facet&gt; &lt;/p:cellEditor&gt; &lt;f:facet name="footer"&gt; &lt;h:selectOneMenu value="#{bean.myNewObject.myListValue}" &gt; &lt;f:selectItem itemValue="true" itemLabel="yes" /&gt; &lt;f:selectItem itemValue="false" itemLabel="no" /&gt; &lt;/h:selectOneMenu&gt; &lt;/f:facet&gt; &lt;/p:column&gt; &lt;p:column&gt; &lt;p:rowEditor /&gt; &lt;f:facet name="footer"&gt; &lt;h:commandButton actionListener="#{bean.addRow}"&gt; &lt;f:ajax execute="myDatatable" render="myDatatable" /&gt; &lt;/h:commandButton&gt; &lt;/f:facet&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; ... &lt;/h:form&gt; </code></pre> <p>In my bean, I just have this for the addRow method:</p> <pre><code>public void addRow() { this.myObjects.add(this.myNewObject); this.myNewObject = new MyObject(); } </code></pre> <p>and the init:</p> <pre><code>@PostConstruct public void init() { this.myObjects = Controller.getAllMyObjects(); this.myNewObject = new MyObject(); } </code></pre> <p>I could precise that the bean is in ViewScope. The result is that the line is added, the string value is correct but the list value is always "no" even if I set it to true with this.myNewObject.setMyListValue(true) in the bean after instanciate the object.</p> <p>I know that this is something with to render or the execute of attributes. If I change the line:</p> <pre><code>&lt;f:ajax execute="myDatatable" render="myDatatable" /&gt; </code></pre> <p>to:</p> <pre><code>&lt;p:ajax update="@form" /&gt; </code></pre> <p>the list value is true but the string value is not set.</p> <p>How to be sure that both of my attribute are rendered and how can I get there values without submiting the whole form?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload