Page 1 of 1
p:dialog show data from the server
Posted: 10 Aug 2009, 03:53
by shaiju.ck
Hi,
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 ?
Shaiju
Re: p:dialog show data from the server
Posted: 10 Aug 2009, 05:12
by Wagner D
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" />
</f:facet>
<h:outputText value="#{item.city_name}"/>
</p:column>
<p:column resizable="true" sortable="true">
<f:facet name="header">
<h:outputText value="State" />
</f:facet>
<h:outputText value="#{item.state.state_name}"/>
</p:column>
</p:dataTable>
</p:dialog>
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( );
setCityList(lista);
}
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
Re: p:dialog show data from the server
Posted: 12 Aug 2009, 01:23
by cagatay.civici
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.