0
我正在使用JSF Primefaces,並且想要搜索並顯示結果,但結果不會顯示,我正在使用Result類型執行此操作,並且在JSF 2.1中執行了這樣的操作,而MyFaces tomahawk ,但現在primefaces這是不行的,這裏是我的代碼數據表Primefaces
<h:form id="buscar_sucursal">
<p:panel style="width: 800px">
<h:panelGrid columns="5">
<h:outputText value="Criterio: " />
<p:selectOneMenu id="citerio" value="#{SucursalesBean.criterio}">
<f:selectItem itemValue="1" itemLabel="CVE SUCURSAL"></f:selectItem>
<f:selectItem itemValue="2" itemLabel="NOMBRE"></f:selectItem>
</p:selectOneMenu>
<h:outputText value="Valor: " />
<p:inputText id="valor" value="#{SucursalesBean.valor}"></p:inputText>
<p:commandButton action="#{SucursalesBean.buscar}" value="Buscar"></p:commandButton>
</h:panelGrid>
</p:panel>
<p:dataTable id="sucursalesTable" var="suc" value="#{SucursalesBean.sucursalesTable}">
<p:column headerText="Id">
<h:outputText value=""></h:outputText>
</p:column>
<p:column headerText="Cve">
<h:outputText value="#{suc.cve_sucursal}"></h:outputText>
</p:column>
<p:column headerText="Sucursal">
<h:outputText value="#{suc.sucursal}"></h:outputText>
</p:column>
<p:column headerText="Domicilio">
</p:column>
<p:column headerText="Contraseña">
</p:column>
<p:column headerText="Accion">
<h:commandLink value="Editar"></h:commandLink>/
<h:commandLink value="Eliminar"></h:commandLink>
</p:column>
</p:dataTable>
</h:form>
和代碼我ManagedBean
public Result getSucursalesTable()
{
return this.sucursalesTable;
}
public void setSucursalesTable(Result sucursalesTable)
{
this.sucursalesTable = sucursalesTable;
}
public void buscar() throws ClassNotFoundException
{
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.valor = request.getParameter("buscar_sucursal:valor");
try
{
LoginBean loginBean = (LoginBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("LoginBean");
Connection conn = loginBean.getConectar_db();
//int id_empresa = loginBean.getId_empresa();
ArrayList<SucursalesBean> al = new ArrayList<SucursalesBean>();
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
//ResultSet rs = st.executeQuery("SELECT *FROM clientes WHERE id_cliente='"+request.getParameter("id_cliente")+"';"); // AND id_contribuyente='' AND id_empresa=''
//if(request.getParameter("sucursales:id_sucursal") != null)
//rs = st.executeQuery("SELECT *FROM sucursales WHERE id_sucursal='"+request.getParameter("sucursales:id_sucursal")+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';"); // AND id_contribuyente='' AND id_empresa=''
if(getCriterio().toString() != null)
{
if(getCriterio().toString().equals("1"))
rs = st.executeQuery("SELECT cve_sucursal,sucursal FROM sucursales WHERE cve_sucursal='"+this.valor+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
if(getCriterio().toString().equals("2"))
rs = st.executeQuery("SELECT *FROM sucursales WHERE sucursal LIKE '%"+this.valor+"%' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
}
this.sucursalesTable = ResultSupport.toResult(rs);
//this.sucursalesTable = rs;
//setSucursalesTable(ResultSupport.toResult(rs));
/*while(rs.next())
{
//out.println("<tr><td>"+rs.getString("sucursal")+"</td><td>"+rs.getString("cve_sucursal")+"</td><td>"+rs.getString("telefono")+"</td><td>"+rs.getString("e_mail")+"</td><td>"+rs.getString("calle")+"</td><td><a href='sucursales.jsp?accion=editar&id_sucursal="+rs.getString("id_sucursal")+"'>Editar</a></td><td></td></tr>");
//setId_sucursal(String.valueOf(rs.getInt("id_sucursal")));
setCve_sucursal(rs.getString("cve_sucursal"));
setSucursal(rs.getString("sucursal"));
al.add(this);
}
this.sucursalesTable = al;*/
}
catch(SQLException ex)
{
}
}
我不想爲了使用列表類型使用序列化對象因爲我認爲要做一些本應該很簡單的事情的代碼太多了,即使它不是這樣最好的答案。
我懷疑這是Primefaces是否支持Result類型,或者我失去了這一點,也許這就是爲什麼這個方法不起作用。
任何幫助,我真的很感激感謝提前
你好謝謝回答我的問題,我已嘗試使用ajax =「false」,因爲您默認情況下已將其設置爲true,現在在請求後刷新頁面並向我顯示下一個錯誤: – user2206592
/sucursales.xhtml @ 71,63 value =「#{suc.cve_sucursal}」 :Propiedad'cve_sucursal'no hallada en el tipo javax.servlet.jsp.jstl.sql.ResultImpl – user2206592
看來SucursalesBean.sucursalesTable是Result類型,它不是一個集合。我相信,數據表只能顯示集合中的內容。所以我不知道最簡單的你,但我想你需要一些DTO類來包含查詢的結果,就像這裏:http://stackoverflow.com/questions/8597382/how-to-show-hibernate-query -result-in-primefaces-datatable –