Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Primefaces how to work with elements placed in dataTable column header
    primarykey
    data
    text
    <p>When "selectOneMenu" is placed in the "dataTable" column header it: 1) triggers row sorting everytime it is opened or after the button next to it is clicked and "selectOneMenu" is opened (it shouldn't be like that); 2) fails to assign value to the backing bean. How can "selectOneMenu" be attached to the column header so that these problems wouldn't occur?</p> <p>*.xhtml code with dataTable which causes 1) and 2) problems:</p> <pre><code>&lt;h:form id="someForm0"&gt; &lt;p:dataTable id="sdt" var="variable" value="#{otherBean.tableModel}" rows="10"&gt; &lt;p:column sortBy="#{variable.name}" filterBy="#{variable.name}" filterMatchMode="contains" &gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Name"/&gt; &lt;h:panelGrid columns="2" cellpadding="1"&gt; &lt;p:selectOneMenu id="abc" value="#{userBean.someChars}"&gt; &lt;f:selectItem itemLabel="" itemValue="select" /&gt; &lt;f:selectItem itemLabel="AAA" itemValue="AAA" /&gt; &lt;f:selectItem itemLabel="BBB" itemValue="BBB" /&gt; &lt;f:selectItem itemLabel="CCC" itemValue="CCC" /&gt; &lt;/p:selectOneMenu&gt; &lt;h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/&gt; &lt;/h:panelGrid&gt; &lt;/f:facet&gt; &lt;h:outputText value="#{variable.name}"/&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; &lt;/h:form&gt; </code></pre> <p>Backing bean code:</p> <pre><code>@ManagedBean public class UserBean { private String someChars; public String getSomeChars() { return someChars; } public void setSomeChars(String someChars) { this.someChars = someChars; } public String submitChars() { if(getSomeChars() != null) { System.out.println("Selected chars are: " + getSomeChars()); } else { System.out.println("Selected chars are equal to null!"); } return null; } } </code></pre> <p>Here is fragment of the previously mentioned *.xhtml code, and selectOneMenu works just great when placed into the basic form:</p> <pre><code>&lt;h:form id="someForm"&gt; &lt;p:selectOneMenu id="abc" value="#{userBean.someChars}"&gt; &lt;f:selectItem itemLabel="" itemValue="select" /&gt; &lt;f:selectItem itemLabel="AAA" itemValue="AAA" /&gt; &lt;f:selectItem itemLabel="BBB" itemValue="BBB" /&gt; &lt;f:selectItem itemLabel="CCC" itemValue="CCC" /&gt; &lt;/p:selectOneMenu&gt; &lt;h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/&gt; &lt;/h:form&gt; </code></pre> <p>I think the last resort would be adding elements from the dataTable column header to the dataTable header:</p> <pre><code>&lt;h:form id="someForm1"&gt; &lt;p:dataTable id="sdt" var="variable" value="#{otherBean.tableModel}" rows="10"&gt; &lt;f:facet name="header"&gt; &lt;h:panelGrid columns="2" cellpadding="1"&gt; &lt;p:selectOneMenu id="abc" value="#{userBean.someChars}"&gt; &lt;f:selectItem itemLabel="" itemValue="select" /&gt; &lt;f:selectItem itemLabel="AAA" itemValue="AAA" /&gt; &lt;f:selectItem itemLabel="BBB" itemValue="BBB" /&gt; &lt;f:selectItem itemLabel="CCC" itemValue="CCC" /&gt; &lt;/p:selectOneMenu&gt; &lt;h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/&gt; &lt;/h:panelGrid&gt; &lt;/f:facet&gt; &lt;p:column sortBy="#{variable.name}" filterBy="#{variable.name}" filterMatchMode="contains" &gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Name"/&gt; &lt;/f:facet&gt; &lt;h:outputText value="#{variable.name}"/&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; &lt;/h:form&gt; </code></pre>
    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