Answer the question
In order to leave comments, you need to log in
Dynamic tables in primefaces?
Hello, there is such a page written in primefaces.
As you can see in the picture, there is a button to add a group (at the same time it is written to the database) and a table is formed. Also, under each table there is a button to add a row to the table above (there is a number in the name of the button, this is the id of the group into which the row should be inserted).
Table in the category database:
Question: how can it be implemented so that when the button (Add Row) is pressed, a row is added to this particular table? So far, when I click, a line with group_id 43 is simply added to the database (depending on which button to click)
A little code)
.xhtml
<h:form id="form1">
<p:growl id="msgs" showDetail="true"/>
<p:panel>
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="naimenovanie" value="Название группы:"/>
<p:inputText id="naimenovanie" value="#{shemaProektaController.shemaProektaModel.name}"
required="true" requiredMessage="Введите название группы"/>
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="5">
<p:commandButton value="Добавить группу" update="@form"
action="#{shemaProektaController.addGroup}"/>
</h:panelGrid>
</p:panel>
</h:form>
<h:form prependId="false">
<h:panelGroup id="panel">
<ui:repeat value="#{shemaProektaController.shemaProektaModelList}" var="sp">
<p:dataTable id="table"
value="#{sp}"
var="list"
style="overflow: auto">
<f:facet name="header">
<p:outputLabel value="#{sp.name}"/>
</f:facet>
<p:column headerText="id"
style="text-align: center; width: 20px">
<h:outputText value="#{}"/>
</p:column>
<p:column headerText="name"
style="width: 100px">
<h:outputText value="#{}"/>
</p:column>
<p:column headerText="kaf"
style="width: 100px">
<h:outputText value="#{}"/>
</p:column>
<p:column headerText="client"
style="width: 100px">
<h:outputText value="#{}"/>
</p:column>
<p:column headerText="itogo"
style="width: 100px">
<h:outputText value="#{}"/>
</p:column>
</p:dataTable>
<h:panelGrid>
<p:commandButton update="" action="#{shemaProektaController.addRow}" value="Добавить строку#{sp.id}">
<f:setPropertyActionListener target="#{shemaProektaController.test}" value="#{sp.id}" />
</p:commandButton>
</h:panelGrid>
</ui:repeat>
</h:panelGroup>
</h:form>
public void addRow(){
try {
modelRow.setGroupId(new Long(test));
ShemaProektaDAO.insertRow(modelRow);
} catch (SQLException e) {
e.printStackTrace();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question