user3878073
user3878073

Reputation: 91

PrimeFaces dialog does not show up

hi I'm working with PrimeFaces. When I encountered this problem. I want to display the values I entered in the form while clicking the save button

and the XHTML file is

<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
          <h:head>
          <title>
          calender popup problem
          </title>


          </h:head>

<body>
    <h:form>
        <TABLE>
            <tr>
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN NAME" /></td>
                <td><p:inputText id="coupounname"  maxlength="50" value="#{office.coupounname}"/></td>
            </tr>
            <tr style="padding-top: 10px">
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN CODE" /></td>
                <td><p:inputText id="couponcode" value="#{office.coupouncode}"/></td>
            </tr>
            <tr style="padding-top:10px">
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN DESCRIPTION"/></td>
                <td><p:inputTextarea id="coupoundes" value="#{office.coupouncode}"/></td>
            </tr>
            <tr style="padding-top: 10px">
                <td><h:outputText value= "*"/></td>
                <td><h:outputText value="Discount"/></td>

           <!-- <td>
                    <p:selectOneRadio id="radiobuttons" value="#{office.percentage}">
                    <f:selectItem itemLabel="in ruppes" itemValue="ByCash"/>
                    <f:selectItem itemLabel="inpercentage" itemValue="InPercentage"/>
                    </p:selectOneRadio> 
                </td> -->
            </tr>
            <tr>
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="Validity"/></td>
                <td><p:calendar value="#{office.startdate}"/></td>
                <td><p:calendar value="#{office.enddate}"/></td>
            </tr> 
            <tr>
                <td><p:commandButton id="save" value="save" action="#{officebean.save}"/></td>
                <td><p:commandButton id="cancel" value="cancel"/></td>
            </tr>

        </TABLE>
    </h:form>
    <ui:include src="dialogs.xhtml"/>
</body>
</html>

and the dialog is stored in the file

<p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120"> 
    <h:form id="dialogform">
        <h:outputText value=" the value entered by the users were"/>
        <table>
            <tr>
                <td>name:=<h:outputText value="#{office.coupounname}"/></td>
                <td>code:<h:outputText value="#{officebean.dialogvisible}"/</td>
            </tr>
        </table>
    </h:form>
</p:dialog> 

now the bean class which contains the action for save button which sets the condition which makes the dialog visible

@ManagedBean(name="officebean")
@RequestScoped
public class Officebean {
    private List<Office>officeList;
    private Office office;
    private String Dialogvisible;

    public void save() {
        Dialogvisible="Bean";   
    }

    public List<Office> getOfficeList() {
        return officeList;
    }

    public void setOfficeList(List<Office> officeList) {
        this.officeList = officeList;
    }

    public Office getOffice() {
        return office;
    }

    public void setOffice(Office office) {
        this.office = office;
    }

    public String getDialogvisible() {
        return Dialogvisible;
    }

    public void setDialogvisible(String dialogvisible) {
        Dialogvisible = dialogvisible;
    }
}

but dialog is not showing up when save button is clicked any held would be appreciated

Upvotes: 0

Views: 12938

Answers (3)

anaccs
anaccs

Reputation: 1

First you have to know that a dialog doesn't show until you call in some way the show() function...

if the other answers don't work for you maybe you can add in dialogs.xhtml this:

firt you have to add the widgetVar variable at the dialog like something like:

<p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120" widgetVar="listdialog">

Then outside the dialog something like:

<p:remoteCommand id="rc1" name="showDialog"oncomplete="PF('listdialog').show();" />

And to finish:

<script type="text/javascript">
showDialog();
</script>

This should open your dialog as soon you open the dialogs.xhtml....

Good luck!

Upvotes: 0

Jaqen H&#39;ghar
Jaqen H&#39;ghar

Reputation: 4345

I'd guess you need to use

<h:body> instead of <body>

<p:dialog id="listdialog" widgetVar="listdialog".... >

<p:commandButton oncomplete="PF('listdialog').show()" ... />

and maybe remove visible from the dialog.

Upvotes: 1

rptmat57
rptmat57

Reputation: 3767

try

<p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog"/>

but if you want to show as a popup you are going to have to use

<p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog" oncomplete="#{p:widgetVar('listDialog')}.show();"/>

Upvotes: 0

Related Questions