Code reviewer
Code reviewer

Reputation: 27

web application J SF prime faces

i am developing java web-based application , i am using jsf 2.2 and prime faces, I am facing this problem : i have two buttons the first is delete and the other one is edit , the delete button open a confirmation dialog that has another two buttons yes/no , the edit button open a edit dialog , my problem that when i click the yes button in the confirmation dialog it dose not work but when i remove the edit dialog from the code and restart the program the yes button works fine. i hope to find a solution that could help me keep the edit dialog in the code and make the yes button work fine.

page code sample :

 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:hftl="http://hftl.org"
xmlns:hf="http://xmlns.jcp.org/jsf/composite/tags"
template="../../templates/template.xhtml"
xmlns:e="http://primefaces.org/extension">

<ui:param name="pageTitle" value="#{messages['account.search']}" />




<ui:define name="content">


<h:form>

            <p:commandButton value="delete" onclick="PF('deletedlg').show()" 
                         id="delBtn" />


            <p:commandButton value="edit" onclick="PF('editDlg').show()"  id="edtBtn"/>

        <p:dataTable var="admin" value="#{adminBean.getLazyDataModel()}"
            paginator="true" rows="10"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} 
     {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
            rowsPerPageTemplate="5,10,15" id="dataTable" lazy="true"
            binding="#{adminBean.dataTable}"
            selection="#{adminBean.selectedEntity}" selectionMode="single">


            <p:column headerText="id">
                <h:outputText value="#{admin.id}" id="xxxx" />
            </p:column>

            <p:column headerText="username">
                <h:outputText value="#{admin.username}" id="asdssasd" />
            </p:column>



        </p:dataTable>



        <p:dialog header="Notice" widgetVar="deletedlg" modal="true"
            showEffect="fade" hideEffect="fade" resizable="false" id="deletedlg">

                <p:outputPanel style="text-align:center;">



                    <h:outputText value="are you sure you want to delete" />

                    <p:commandButton value="Yes"
                        actionListener="#{adminBean.onDleteClicked()}"  id="yesBtn" />

                    <p:commandButton value="No" onclick="PF('deletedlg').hide()" id="noBtn" />

                </p:outputPanel>

        </p:dialog>

        <p:dialog header="Edit" widgetVar="editDlg" modal="true"
            showEffect="fade" hideEffect="fade" resizable="false" id="editDlg">
                <p:outputPanel style="text-align:center;">

                    <hf:textBox componentId="userNameTxt" label="username"
                        value="#{adminBean.entity.username}"
                        placeholder="enter user name here" />
                    <hf:textBox componentId="passwordTxt" label="passsword"
                        value="#{adminBean.entity.password}"
                        placeholder="enter password here" isPassword="true" />
                    <hf:textBox componentId="rPasswordTxt" label="passsword"
                        value="#{adminBean.rPassword}" placeholder="enter password here"
                        isPassword="true" />

                    <p:commandButton value="save"
                        actionListener="#{adminBean.onEditSaveClicked()}" id="saveBtn"/>

                </p:outputPanel>
        </p:dialog>

</ui:define>

Upvotes: 0

Views: 100

Answers (1)

Robert
Robert

Reputation: 488

After simplifying your code a little and trying it out myself, I may have found what is causing your problem. To start out with, I had the same behavior as you describe. Then I modified these two lines: (removing the parenthesis at the end)

actionListener="#{myController.onDleteClicked}"

actionListener="#{myController.onEditSaveClicked}"

Here is the full sample I used:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:p="http://primefaces.org/ui">


    <h:form>
        <p:commandButton value="delete" onclick="PF('deletedlg').show()" id="delBtn" />
        <p:commandButton value="edit" onclick="PF('editDlg').show()" id="edtBtn"/>
        <p:column headerText="id">
            <h:outputText value="#{myForm.id}" id="xxxx" />
        </p:column>
        <p:column headerText="username">
            <h:outputText value="#{myForm.username}" id="asdssasd" />
        </p:column>

        <p:dialog header="Notice" widgetVar="deletedlg" modal="true"
                  showEffect="fade" hideEffect="fade" resizable="false" id="deletedlg">
            <p:outputPanel style="text-align:center;">
                <h:outputText value="are you sure you want to delete" />
                <p:commandButton value="Yes" actionListener="#{myController.onDleteClicked}"  id="yesBtn" />
                <p:commandButton value="No" onclick="PF('deletedlg').hide()" id="noBtn" />
            </p:outputPanel>
        </p:dialog>

        <p:dialog header="Edit" widgetVar="editDlg" modal="true"
                  showEffect="fade" hideEffect="fade" resizable="false" id="editDlg">
            <p:outputPanel style="text-align:center;">
                <p:commandButton value="save"
                                 actionListener="#{myController.onEditSaveClicked}" id="saveBtn"/>
            </p:outputPanel>
        </p:dialog>
    </h:form>
</ui:composition>

Hope this helps!

Upvotes: 1

Related Questions