So i have this JSF code that will show a column of datatable and each of column must be filled. I also put the rowEdit button in the right side. so before the user fill the data, they must click the rowEdit button on the right side. This is the code :
<p:panel header="Form Data">
<p:panelGrid columns="1">
<div class="grid-flex-column">
<div class="col">
<div class="box">
<div class="field-grid">
<h:outputLabel value="Fullname:" />
<h:outputLabel value="NIK:" />
<h:outputLabel value="Departement:" />
<h:outputLabel value="Division:" />
<h:outputLabel value="Position:" />
</div>
</div>
</div>
<div class="col">
<div class="box">
<p:commandButton value="Add Column" action="#{dtStrukView.onAddNew()}"
update="form" styleClass="ui-button-outlined" />
</div>
</div>
<div class="col">
<div class="box">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable value="#{dtStrukView.strukPembayaranList}" var="struk" editable="true">
<p:ajax event="rowEdit" listener="#{dtStrukView.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{dtStrukView.onRowCancel}" update=":form:msgs"/>
<p:column headerText="Keterangan">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{struk.keterangan}" required="true" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{struk.keterangan}" required="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Tanggal Kuitansi">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{struk.tanggalKuitansi}" required="true" />
</f:facet>
<f:facet name="input">
<p:datePicker value="#{struk.tanggalKuitansi}" monthNavigator="true" pattern="dd/MM/yyyy" required="true"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Jumlah">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{struk.jumlah}" required="true" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{struk.jumlah}" required="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Upload Tanda Tangan">
<p:cellEditor>
<f:facet name="output">
<p:fileUpload id="uploader1" mode="simple" skinSimple="true" styleClass="block mb-5"
title="my custom title" accept=".jpg,.jpeg,.png" />
</f:facet>
<f:facet name="input">
<p:fileUpload id="uploader2" mode="simple" skinSimple="true" styleClass="block mb-5"
title="my custom title" accept=".jpg,.jpeg,.png" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6rem">
<p:rowEditor editTitle="Edit Row" cancelTitle="Cancel Edit" saveTitle="Save Row"/>
</p:column>
</p:dataTable>
</div>
</div>
</div>
</p:panelGrid>
<div class="grid justify-content-end">
<div class="col-4" >
<div class="box" style="padding-left: 90%">
<p:commandButton value="Save Data" update="form" action="#{dtStrukView.save}" icon="pi pi-check" validateClient="true" />
</div>
</div>
</div>
</p:panel>
When user click “Add Column” on the top, there will be add more column shows in the bottom and each of column have the rowEdit button to user fill the data. When user click the rowEdit button, each column will editable and must be required to fill. When there’s one column that not filled, notification will show up and tell the user to fill that column. How to make the column required to fill and show the message that we custom?
Diti Merita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The <h:outputText>
doesn’t support the required
attribute. It’s only supported on UIInput
components.
Just add a <h:inputHidden ... required="true">
to each <f:facet name="output">
along the <h:outputText>
.
E.g.
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{struk.keterangan}" />
<h:inputHidden value="#{struk.keterangan}" required="true" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{struk.keterangan}" required="true" />
</f:facet>
</p:cellEditor>