我正在为我的测试页面做一个动态搜索引擎。几天前,我在这里询问somethig以显示seach的结果,并建议我使用PrimeFaces dataGrids。我非常喜欢展示一切,但现在我还有另一个问题。
我将一个列表加载到dataGrid,该列表将是具有搜索所有结果的列表。页面第一次搜索并显示良好,但是,如果我进行另一次搜索,页面将显示新结果,与之前的结果一致(我不希望他这样做)。
例如:
第一次测试搜索(哥伦比亚)
现在当我再次搜索时,哥伦比亚并没有消失。
让我们现在尝试与墨西哥。哥伦比亚终于消失了,但现在阿根廷是坚持不懈的......
我认为解决方案只是在页面执行另一个新搜索之前清除了结果列表中的所有元素,但这不起作用。
基本模板(我这里有搜索框):
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/blueprint/screen.css" type="text/css" rel="stylesheet"
media="screen, projection"/>
<link href="css/blueprint/print.css" type="text/css" rel="stylesheet"
media="print"/>
<!--[if lt IE 8]><link rel="stylesheet" href="css/blueprint/ie.css"
type="text/css" media="screen, projection"><![endif]-->
<h:outputStylesheet name="css/default.css"/>
<h:outputScript library="js" name="calendar_es.js"/>
<title><h:outputText value="Trip Hotel, tu hotel ideal"/></title>
</h:head>
<h:body>
<div class="centerPage">
<div id="top" class="span-24 Last">
<h:form>
<table>
<tr>
<td rowspan="2"><h:graphicImage library="images"
name="hotel.png"/></td>
<td><span style="font-size: 13px;color:#113C75;font-
weight: bold;">Fecha de Entrada:</span>
<p:calendar id="fechaE"
size="8" styleClass="calendarClass" readonly="true" locale="es" value="#
{buscador.fechaE}"/></td>
<td> <span style="font-size:
13px;color:#113C75;font-weight: bold;">Fecha de Salida:
</span>
<p:calendar id="fechaF"
size="8" styleClass="calendarClass" readonly="true" locale="es" value="#
{buscador.fechaS}"/></td>
</tr>
<tr>
<td><span style="font-size: 13px;color:#113C75;font-
weight: bold;">Número de personas:</span>
<p:selectOneMenu id="nPersona" style="width:80px;
font-size: 12px;" value="#{buscador.personas}">
<f:selectItem itemLabel="1" itemValue="1"/>
<f:selectItem itemLabel="2" itemValue="2"/>
<f:selectItem itemLabel="3" itemValue="3"/>
<f:selectItem itemLabel="4" itemValue="4"/>
</p:selectOneMenu>
</td>
<td> <span style="font-size:
13px;color:#113C75;font-weight: bold;">Localidad:</span>
<p:inputText id="localidad" style="height: 20px; width:
158px;
background-color: #F9FED3;font-size:
13px;" value="#{buscador.localidad}" />
</td>
<td>
>>>>>>>>>>>>>>>>>>>HERE IS THE BUTTON AND MY AJAX<<<<<<<<<<<<<<<<
<p:commandButton value="Buscar" class="buscar"
action="#{buscador.mostrarBusqueda()}">
<f:ajax listener="#
{buscador.mostrarBusqueda()}" event="click" render=":form2"/>
</p:commandButton>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
</td>
</tr>
</table>
</h:form>
</div>
<div>
<div id="left" class="span-8">
<ui:insert name="left">
<div id="menu">
<p:button value="Iniciar Sesion" class="sesion"/>
<p:button value="Hoteles" class="hotel"/>
<p:button value="Reservas" class="reservas"/>
<p:button value="Ofertas" class="ofertas"/>
<p:graphicImage library="images" name="vista.png"
style="border: 1px solid black; margin-top:50px;margin-top:80px;"/>
</div>
</ui:insert>
</div>
<div class="span-16 Last">
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
</div>
</div>
</h:body>
<br/>
<footer>
</footer>
索引页面(模板客户端):
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:viewAction action="#{buscador.cargarPortada()}"/>
</f:metadata>
<body>
<ui:composition template="./templates/base.xhtml">
<ui:define name="content">
<h:form id="form2">
<p:dataGrid var="hotel" value="#{buscador.display}" columns="3" rows="9" paginator="true" id="hoteles" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<p:panel header="#{hotel.nombre}" style="text-align:center;width: 230px;height:139px;">
<h:panelGrid columns="1" style="width:100%;">
<p:graphicImage name="images/#{hotel.imagen}" style="width: 160px; height: 70px;"/>
<h:outputText value="#{hotel.localidad}"/>
</h:panelGrid>
</p:panel>
</p:dataGrid>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
我的bean的搜索方法......
public void mostrarBusqueda(){
displayList.clear(); <<<<< Here I clear my result List
String parametros[] = new String[1];
parametros[0] = localidad;
try{
ResultSet rs = GestorDB.getParametizada(parametros, "SELECT HOTELES.NOMBRE AS A, HOTELES.IMGHOTEL, LOCALIDADES.NOMBRE AS B FROM HOTELES INNER JOIN LOCALIDADES"
+ " ON LOCALIDADES.IDLOCALIDADES = HOTELES.LOCALIDADES_IDLOCALIDADES WHERE LOCALIDADES.NOMBRE LIKE '%' || ? || '%'");
while(rs.next()){
ResultElement res = new ResultElement(rs.getString("A"), rs.getString("IMGHOTEL"), rs.getString("B"));
displayList.add(res);
}
} catch (SQLException ex) {
Logger.getLogger(Buscador.class.getName()).log(Level.SEVERE, null, ex);
}
}
是组件错误,还是我做错了什么?