jsf - Table doesn't want to update after input search tags -
this question has answer here:
i have weird problem, i'm sure it's related h:form placement tags. have table, above table have search form can put tags, example name or lastname , after table refreshed. , worked! reasons it's stopped working , have no idea why. in order check results of searching have refresh page or change pagination in table 10 15, after results appear. here code:
xhtml:
<h:form> <div class="row"> <div class="panel-heading text-center"> <div class="bootstrap-filestyle input-group inn"> <div class="search-criteria" style="width: 500px"> <h:inputtext value="#{clientbean.tags}" styleclass="form-control" type="text"> <f:passthroughattribute name="placeholder" value="imię, nazwisko, adres..." /> </h:inputtext> </div> <p:commandbutton type="submit" style="float:left" styleclass="btn btn-primary" value="szukaj" actionlistener="#{clientbean.getallclients()}"> <i class="icon-search icon-white"></i> </p:commandbutton> </div> </div> </div> <h:form> <p:datatable id="clientstable" style="white-space: nowrap" var="client" value="#{clientbean.getallclients()}" paginator="true" rows="15" paginatortemplate="{currentpagereport} {firstpagelink} {previouspagelink} {pagelinks} {nextpagelink} {lastpagelink} {rowsperpagedropdown}" rowsperpagetemplate="10,15"> <p:column headertext="imię"> <h:outputtext value="#{client.name}" /> </p:column> <p:column headertext="nazwisko"> <h:outputtext value="#{client.lastname}" /> </p:column> <p:column headertext="numer telefonu"> <h:outputtext value="#{client.phonenumber}" /> </p:column> <p:column headertext="adres"> <h:outputtext value="#{client.address}" /> </p:column> <p:column> <a href="klienci/#{client.id}" class="btn btn-success edit resized-font"><span class="glyphicon glyphicon-pencil"></span> edytuj</a> <a href="klienci/#{client.id}" class="btn btn-danger delete resized-font"><span class="glyphicon glyphicon-trash"></span> usuń</a> <a href="klienci/#{client.id}" class="btn btn-primary resized-font"><span class="glyphicon glyphicon-book"></span> informacje</a> </p:column> </p:datatable> </h:form> </h:form>
important code clientbean:
private string tags; public set<client> getallclients() { if (tags == null) { set<client> clients = new hashset<client>(clientdao.findall()); return clients; } return getclients(); } public set<client> getclients() { set<client> mergedclientset = new hashset<>(); string[] tags = gettags().split(" "); for(int i=0; i<tags.length; i++){ mergedclientset.addall(searchservice.getclientwithparameters(tags[i])); } return mergedclientset; } public string gettags() { return tags; } public void settags(string tags) { this.tags = tags; }
first of committing violation of w3c xhtml specification, nesting forms, can't that.
and trying achieve simple.
here's how :
jsf facelet:
<h:form prependid="true" id="main-form"> <div class="row"> <div class="panel-heading text-center"> <div class="bootstrap-filestyle input-group inn"> <div class="search-criteria" style="width: 500px"> <h:inputtext value="#{clientbean.tags}" styleclass="form-control"> <f:passthroughattribute name="placeholder" value="imię, nazwisko, adres..." /> </h:inputtext> </div> <p:commandbutton style="float:left" styleclass="btn btn-primary" value="szukaj" actionlistener="#{clientbean.dotagssearch}" update=":main-form:clients-table"> <i class="icon-search icon-white"></i> </p:commandbutton> </div> </div> </div> <p:datatable id="clients-table" style="white-space: nowrap" var="client" value="#{clientbean.clients}" paginator="true" rows="15" paginatortemplate="{currentpagereport} {firstpagelink} {previouspagelink} {pagelinks} {nextpagelink} {lastpagelink} {rowsperpagedropdown}" rowsperpagetemplate="10,15"> <p:column headertext="imię"> <h:outputtext value="#{client.name}" /> </p:column> <p:column headertext="nazwisko"> <h:outputtext value="#{client.lastname}" /> </p:column> <p:column headertext="numer telefonu"> <h:outputtext value="#{client.phonenumber}" /> </p:column> <p:column headertext="adres"> <h:outputtext value="#{client.address}" /> </p:column> <p:column> <a href="klienci/#{client.id}" class="btn btn-success edit resized-font"><span class="glyphicon glyphicon-pencil"></span> edytuj</a> <a href="klienci/#{client.id}" class="btn btn-danger delete resized-font"><span class="glyphicon glyphicon-trash"></span> usuń</a> <a href="klienci/#{client.id}" class="btn btn-primary resized-font"><span class="glyphicon glyphicon-book"></span> informacje</a> </p:column> </p:datatable> </h:form>
managedbean code snippet :
private string tags; private arraylist<client> clients; @postconstruct public void init() { clients = clientdao.findall();//must return arraylist of client } public void dotagssearch() { if (tags == null) { clients = clientdao.findall(); } else { clients = getclientsbytags(); } } public arraylist<client> getclientsbytags() { //use tags logic. //must return arraylist of clients. ... } public string gettags() { return tags; } public void settags(string tags) { this.tags = tags; } public string getclients() { return clients; } public void setclients(arraylist<client> clients) { this.clients = clients; }
}
Comments
Post a Comment