Editing a record with Daialog framework of primefaces

0

I am a beginner in the world java and java web, starting with jsf, primefaces and I have a problem that I can not solve. I have a dataTable listing some data, I have the ajax event to select a field in the table and an edit button. when doing this it should open a modal window with the data to do the editing, which I can not do.

Modal window code:

public void abrirDialogo() {
    Map<String, Object> options = new HashMap<>();
    options.put("modal", true);
    options.put("resizable", false);
    options.put("width", 400);
    options.put("height", 300);

    RequestContext.getCurrentInstance().openDialog("frmEstadosMan", options, null);
}

Event code ajax

<p:ajax event="rowSelect"/>

Edit button code

<p:commandButton title="Editar" value="Editar" icon="fa fa-edit"   
        action="#{estadosBean.abrirDialogoEdt}" process="@this"> 
<f:setPropertyActionListener target="#{estadosBean.estado}" value="#{estado}" />
</p:commandButton>

Sometimes I've edited the code, the edit window has opened, but it's empty, without the grid line data that was selected.

    
asked by anonymous 18.07.2017 / 15:41

1 answer

0

If you follow the example primefaces can help you ...

link

In the commandButton has a setPropertyActionListener that arrows the car object for the selected and oncomplete opens your multiCarDialog dialog box by displaying variable data.

<p:dataTable id="basicDT" var="car" value="#{dtSelectionView.cars1}">
    <p:column headerText="Id">
        <h:outputText value="#{car.id}" />
    </p:column>
    <p:column headerText="Year">
        <h:outputText value="#{car.year}" />
    </p:column>
    <p:column style="width:32px;text-align: center">
         <p:commandButton update=":form:carDetail" oncomplete="PF('carDialog').show()" icon="ui-icon-search" title="View">
            <f:setPropertyActionListener value="#{car}" target="#{dtSelectionView.selectedCar}" />
        </p:commandButton>
    </p:column>
</p:dataTable>

Dialog Box

<p:dialog header="Car Info" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
    <p:outputPanel id="carDetail" style="text-align:center;">
        <p:panelGrid  columns="2" rendered="#{not empty dtSelectionView.selectedCar}" columnClasses="label,value">
            <f:facet name="header">
                <p:graphicImage name="demo/images/car/#{dtSelectionView.selectedCar.brand}-big.gif"/> 
            </f:facet>

            <h:outputText value="Id:" />
            <h:outputText value="#{dtSelectionView.selectedCar.id}" />

            <h:outputText value="Year" />
            <h:outputText value="#{dtSelectionView.selectedCar.year}" />

            <h:outputText value="Color:" />
            <h:outputText value="#{dtSelectionView.selectedCar.color}" style="color:#{dtSelectionView.selectedCar.color}"/>

            <h:outputText value="Price" />
            <h:outputText value="$#{dtSelectionView.selectedCar.price}" />
        </p:panelGrid>
    </p:outputPanel>
</p:dialog>

Of course for editing, you will need to put a form in the dialog box with the components you want and a button to save the information ...

    
08.08.2017 / 22:10