primefaces panelgrid colspan not working - jsf

I'm trying to set a panelgrid inside a dialog. Everything seems to be working except the colspan. I've check this post PrimeFaces panelGrid but its year and half old. From the primefaces manual and showcase, colspan should be accepted by datatable and panelGrid.
<h:form id="idFormAddDialog">
<p:panelGrid id="idPanelAddUsers" columns="2">
<h:outputLabel for="dAddOutUser" value="Username:"></h:outputLabel>
<h:inputText id="dAddOutUser" value="#{userController.username}"></h:inputText>
<h:outputLabel for="dSelRole" value="Role:"></h:outputLabel>
<h:selectOneMenu id="dSelRole" value="#{userController.role}">
<f:selectItem itemLabel="Admin" itemValue="1"></f:selectItem>
<f:selectItem itemLabel="Researcher" itemValue="2"></f:selectItem>
<f:selectItem itemLabel="User" itemValue="3"></f:selectItem>
</h:selectOneMenu>
<h:outputLabel for="dAddINPassword1" value="Password: "></h:outputLabel>
<p:password id="dAddINPassword1" value="#{userController.password}" feedback="true"></p:password>
<p:row>
<p:column colspan="2">
<p:separator></p:separator>
<!-- <p:separator></p:separator>-->
</p:column>
</p:row>
<p:commandButton value="OK" actionListener="#{userController.addUser()}" ></p:commandButton>
<p:button value="Cancel"></p:button>
</p:panelGrid>
</h:form>
But I'm not able to find what I'm doing wrong.

First, if you want to use p:row and p:column in p:panelGrid remove columns attribute, and manage rows and column manually with p:row and p:column tags. Everything inside p:panelGrid must be inside p:row tags. Example:
<p:panelGrid id="idPanelAddUsers">
<p:row>
<p:column></p:column>
<p:column></p:column>
<p:column></p:column>
</p:row>
<p:row>
<p:column colspan="2"></p:column>
<p:column></p:column>
</p:row>
</p:panelGrid>

Related

p:selectOneMenu inside selectManyMenu trouble

I have an element selectOneMenu inside element selectManyMenu (component names have been changed).
<p:selectManyMenu id="#{id}MyItemsList" converter="#{backend.myItemsConverter}"
value="#{backend.selectedItem}"
rendered="#{backend ne null}" var="item">
<f:selectItems value="#{backend.getMyItems()}"
var="varItems"
itemLabel="#{varItems.name}" itemValue="#{varItems.id}"/>
<p:column>
<h:outputText value="#{item.name}" title="#{item.title}"/>
</p:column>
<p:column>
<p:selectOneMenu value="#{item.subId}" converter="#{backend.subItemsConverter}">
<p:ajax listener="#{backend.onSubItemClick}"/>
<f:selectItems value="#{backend.subItems}" var="varSubItems"
itemLabel="#{varSubItems.name}"
itemValue="#{varSubItems.id}"/>
</p:selectOneMenu>
</p:column>
</p:selectManyMenu>
They are displayed normally, but when I change the value of the selectOneMenu in one line, it changes in all. What am I doing wrong?
example
<p:remoteCommand name="subItemChange" action="#{backend.onSubItemChange}"
process="#this"
update="#form:ButtonsPanel"/>
<p:dataTable id="#{id}MyItemsListReadOnly" converter="#{backend.myItemsConverter}"
value="#{backend.selectedItem}"
rendered="#{backend ne null}" var="item">
<p:column style="width: 50%">
<h:outputText value="#{item.name}" title="#{item.title}"/>
</p:column>
<p:column style="width: 50%">
<p:selectOneMenu value="#{item.subId}" converter="#{backend.subItemsConverter}"
onchange="subItemChange();" >
<f:selectItems value="#{backend.subItems}" var="varSubItems"
itemLabel="#{varSubItems.name}"
itemValue="#{varSubItems.id}"/>
</p:selectOneMenu>
</p:column>
</p:dataTable>
dataTable saved my time. In addition, to call onSubItemChange from it, need to use remoteCommand. Hope this helps to somebody.

Updating a custom p:datatable from a commandButton in another datatable one solution works and other does not

I tried to update a datatable from a command button in another datatable.
I am using primefaces custom components.
I had this code:
<h:panelGroup id="eid_pnlGrp" layout="block" class="row_div">
<cust:panel id="ediDetailsTbl" export="true"
refreshAction="#{eidStatusInquiryBean.searchEidStatus(subscriberContainer.accountNumber,2)}"
table="#{eidStatusInquiryBean.eidInquiryTbl}" autoPublish="true"
layout="table">
<f:facet name="preActions">
<p:column id="actionCol" exportable="false"
headerText="Sub EID">
<h:panelGroup layout="block" styleClass="commandStyle">
<p:commandButton id="actionBtn" value=" " async="true"
onstart="PF('eid_Blk').show();"
oncomplete="PF('eid_Blk').hide();"
actionListener="#{eidStatusInquiryBean.loadEidFlatDetails(cimTableUtils.getCellValue(record, 'GetEidDetails.SUB_EID')!=null?cimTableUtils.getCellValue(record, 'GetEidDetails.SUB_EID'):cimTableUtils.getCellValue(record, 'GetEidDetailsByAccountNo.SUB_EID'))}"
update=":#{p:component('eid_pnlGrp')}"
process=":#{p:component('eid_pnlGrp')}" />
</h:panelGroup>
</p:column>
</f:facet>
</cust:panel>
<cust:panel export="true" id="eid_flat_details"
rendered="#{eidStatusInquiryBean.eidFlatDetailsTbl ne null }"
table="#{eidStatusInquiryBean.eidFlatDetailsTbl}"
autoPublish="false" layout="table">
</cust:panel>
</h:panelGroup>
Now when the table was rendered. The pagination was not working.
When I made a slight change and enclosed the second cust:panel inside a panel group and updated that from the command button, it worked fine.
The changed code is:
<h:panelGroup id="eid_pnlGrp" layout="block" class="row_div">
<cust:panel id="ediDetailsTbl" export="true"
refreshAction="#{eidStatusInquiryBean.searchEidStatus(subscriberContainer.accountNumber,2)}"
table="#{eidStatusInquiryBean.eidInquiryTbl}" autoPublish="true"
layout="table">
<f:facet name="preActions">
<p:column id="actionCol" exportable="false"
headerText="Sub EID">
<h:panelGroup layout="block" styleClass="commandStyle">
<p:commandButton id="actionBtn" value=" " async="true"
onstart="PF('eid_Blk').show();"
oncomplete="PF('eid_Blk').hide();"
actionListener="#{eidStatusInquiryBean.loadEidFlatDetails(cimTableUtils.getCellValue(record, 'GetEidDetails.SUB_EID')!=null?cimTableUtils.getCellValue(record, 'GetEidDetails.SUB_EID'):cimTableUtils.getCellValue(record, 'GetEidDetailsByAccountNo.SUB_EID'))}"
update=":#{p:component('eidFlatDetails_pnlGrp')}"
process="#this :#{p:component('eid_pnlGrp')}" />
</h:panelGroup>
</p:column>
</f:facet>
</cust:panel>
<h:panelGroup id="eidFlatDetails_pnlGrp">
<cust:panel export="true" id="eid_flat_details"
rendered="#{eidStatusInquiryBean.eidFlatDetailsTbl ne null }"
table="#{eidStatusInquiryBean.eidFlatDetailsTbl}"
autoPublish="false" layout="table">
</cust:panel>
</h:panelGroup>
</h:panelGroup>
Can you please tell me why one works and the other does not
Tools: Primefaces 5.0

How can I add table in a "td" generated by primefaces?

I am developing a dynamic table with primefaces 6.0 and JSF 2.2. I have a TreeNode of name nodoRoot. I am using h:commandLink in each element for add children, rendering the p:treeNode. Each element has the same list of names and I would like to show this information of the best way.
I have this:
I would like:
Also, in the first image you can see (in red) the subtable has a header, I would like remove this.
This is my code:
<h:form id="myForm">
<h:panelGroup id="pgSystem">
<p:treeTable id="tablaSystem" class=" validate tablaNormal" style="border:none;" value="#{myBean.nodoRoot}" var="element">
<f:facet name="header">
Sistema
</f:facet>
<p:column headerText="Nombre">
<h:outputText value="#{element.nombre}" />
<h:panelGroup id="agregarParteHija#{element.id}">
<h:commandLink action="#{myBean.cargarNuevaParte(element)}">
<f:ajax render="anotherForm" execute="agregarParteHija#{element.id}"/>
<i class="material-icons small">add</i>
</h:commandLink>
</h:panelGroup>
</p:column>
<p:column headerText="Names">
<p:dataTable value="#{question.names}" var="name">
<p:column>
<h:outputText value="#{name}"/>
</p:column>
</p:dataTable>
</p:column>
</p:treeTable>
<br/>
</h:panelGroup>
</h:form>
Thank you!

Primefaces's p:rowExpansion not working inside p:outputPanel?

I'm currently working with primeface's p:rowExpansion and noticed that it's not working inside a p:outputPanel. Here's a sample code:
<p:commandButton action="#{xxxSearchBean.search()}" value="Search" update="messages resultPanel" styleClass="button"></p:commandButton>
<p:outputPanel id="resultPanel">
<p:panel rendered="#{xxxSearchBean.hasResults()}">
<ui:include src="xxxSearchView.xhtml">
<ui:param name="searchBean" value="#{xxxSearchBean}" />
</ui:include>
</p:panel>
</p:outputPanel>
The included view:
<p:accordionPanel activeIndex="0">
<p:tab title="Criminal Results">
<p:dataTable var="c" value="#{searchBean.results}">
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{c.lastname}" />
</p:column>
<p:column headerText="First Name">
<h:outputText value="#{c.firstname}" />
</p:column>
<p:rowExpansion>
<p:panelGrid columns="4"
columnClasses="form-field-label,value,form-field-label,value">
<h:outputText value="Label" />
<h:outputText value="Value" />
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
</p:tab>
</p:accordionPanel>
The above code successfully show the result grid when there are results, but when I click the rowExpansion it doesn't work.
When I moved out the panel and remove the rendered property, the row expansion worked. But I don't want to show the grid on page load :-(
Any idea?
I don't know if <p:rowExpansion> really doesn't work with <p:outputPanel>. But since you don't need any special features of <p:outputPanel>, you can just use <h:panelGroup> instead. :)
I was able to solved the problem by changing the backing bean annotation from #Model to #Conversation scope, then start the conversation the moment the view is render.

Multiple error messages for one input field

I am creating a form using facelets. One input field looks like this:
<p:inputText id="initials" value="#{dilution.initials}" />
dilution is a entity bean and the initials field has two validation constraints set on it. One size constraint and one regex pattern constraint. My problem is getting error messages for both constraints to display next to the input field. Using the <h:message> only display one of the messages and using <h:messages> displays all input fields error messages or nothing (when I tried setting <h:messages for="initials" autoUpdate="true" />).
Is there any simple way to do this?
The full form:
<h:form id="addDilForm">
<p:panel>
<p:messages autoUpdate="true" showDetail="TRUE" />
<p:panelGrid>
<f:facet name="header" >
<p:row><p:column colspan="3">Ny spädningsfaktor</p:column></p:row>
</f:facet>
<p:row>
<p:column colspan="1">
<p:outputLabel for="sampT">Provtyp</p:outputLabel>
</p:column>
<p:column>
<p:selectOneMenu id="sampT" required="true" value="#{dilution.dilution.sampleType.ID}" >
<f:selectItem itemLabel="-" itemValue="" />
<f:selectItems value="#{SampleTypeController.samples}" var="samp" itemLabel="#{samp.name}" itemValue="#{samp.ID}" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:message for="sampT" />
</p:column>
</p:row>
<p:row>
<p:column>
<p:outputLabel for="initials">Initialer</p:outputLabel>
</p:column>
<p:column >
<p:inputText id="initials" value="#{dilution.initials}" />
</p:column>
<p:column>
<p:message for="initials" />
</p:column>
</p:row>
<f:facet name="footer">
<p:row>
<p:column colspan="3">
<p:commandButton value="Save" action="#{dilution.save()}" update="addDilForm" icon="ui-icon-check" />
</p:column>
</p:row>
</f:facet>
</p:panelGrid>
</p:panel>
</h:form>
Using the <h:message> only display one of the messages
Just use <h:messages> with the plural "s" instead of <h:message> while keeping the for attribute.
<h:messages for="initials" />
The <p:messages> works the same way, only with a different UI.

Resources