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