p:dialog show data from the server

Components, Ajax Framework, Utilities and More.
Post Reply
Posts: 28
Joined: 19 Jun 2009, 17:45

10 Aug 2009, 03:53

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

Code: Select all

<a href="#" onclick="dlg.show()">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 ?


Wagner D
Posts: 24
Joined: 16 Jun 2009, 04:45

10 Aug 2009, 05:12

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

Code: Select all

<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:

Code: Select all

<h:commandLink id="linkCity" actionListener="#{cityHandler.searchCity}">								
	Click here for show all cities  
</h:commandLink >
Now the code for you Managed Bean ( Handler )

Code: Select all

      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

User avatar
Posts: 17714
Joined: 05 Jan 2009, 00:21
Location: Cybertron

12 Aug 2009, 01:23

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.

http://code.google.com/p/primefaces/sou ... vies.xhtml

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

Post Reply
  • Information
  • Who is online

    Users browsing this forum: arco, Google [Bot] and 14 guests