Board index JavaServer Faces General p:dialog show data from the server

p:dialog show data from the server

Components, Ajax Framework, Utilities and More.

Posts: 28
I was looking for a solution ,where I can display a list of values retrieved from the server in a dialogue window .I found "p:dialog" can be used to display popup windows.I got the window coming as popup.I am using
<a href="#" onclick="">Show Dialog</a> 
             <p:dialog header="Enter FirstName" width="400px" widgetVar="dlg" visible="false">

TO show the window and is working fine.But I want to retrieve some values from the server and show the window;basically on clicking the hyperlink.

Can anybody suggest me something ?


Posts: 24
Hello Shaiju!
I needed to do something like you!
So, I will post my solution below:

- In your jsp page you put this code for p:dialog

<p:dialog id="dialog1" header="Select an City" width="400px" widgetVar="dlg" visible="#{ not empty cityHandler.cityList}"  close="true" fixedCenter="true"> 
         <p:dataTable value="#{cityHandler.cityList}"
            var="item" width="50%"
            rendered="#{not empty cityHandler.cityList}"
            paginator="true" rows="10" >
            <p:column resizable="true" sortable="true">
                 <f:facet name="header">
                    <h:outputText value="City Name" />                                    
                <h:outputText value="#{item.city_name}"/>                                                           
            <p:column resizable="true" sortable="true">
               <f:facet name="header">
               <h:outputText value="State" />                                    
               <h:outputText value="#{item.state.state_name}"/>                                                           

In the same jsp you put:
<h:commandLink id="linkCity" actionListener="#{cityHandler.searchCity}">                        
   Click here for show all cities 
</h:commandLink >

Now the code for you Managed Bean ( Handler )

      private List<City> cityList;
       //Getters and setters

    * Do the search for all cities
    * @param e
   public void pesquisaCidadesPorNome( ActionEvent e ){
      Session session = HibernateUtil.currentSession();
      CityDAO dao = new CityDAO(session);   
      List<City> lista = dao.searchAll( );

I´m hope this solution helps you!!! The secret is control the visibility/rendered of your p:dialog using not empty cityHandler.cityList.

Best regards!

Wagner @ Brazil

Posts: 15639
Location: Cybertron

I've done something like this in a project, basically my dialog has a panelGrid that is updated with PrimeFaces ajax. There's an example in prime-moviecollector. ... vies.xhtml

See that dialog's content is updated with a p:commandLink and oncomplete event displays the dialog.
PrimeFaces Lead

Return to General