Você está na página 1de 37

Principio del formulario Principio del formulario

New Person Firstname: Validation Error: Value is required. Surname: Validation Error: Value is required. Firstname: Validation Error: Value is required. Surname: Validation Error: Value is required.

Firstname: * Surname: *

Ajax Submit Non-Ajax Submit With Icon ui-button Disabled Information Firstname: jk Surname: jk
61070154446804
Final del formulario

Source
view plaincopy to clipboardprint?

1. <h:form prependId="false">
2.

3. 4. 5. 6. 7. 8.

<p:panel id="panel" header="New Person" style="margin-bottom:10px;"> <p:messages /> <h:panelGrid columns="3"> <h:outputLabel for="firstname" value="Firstname: *" /> <p:inputText id="firstname" value="#{pprBean.firstname}" required="true" label="Firstn ame"> 9. <f:validateLength minimum="2" /> 10. </p:inputText> 11. <p:message for="firstname" /> 12. 13. <h:outputLabel for="surname" value="Surname: *" /> 14. <p:inputText id="surname" 15. value="#{pprBean.surname}" required="true" label="Surname" /> 16. <p:message for="surname" /> 17. </h:panelGrid> 18. </p:panel> 19. 20. <p:commandButton value="Ajax Submit" update="panel,display" 21. actionListener="#{pprBean.savePerson}" /> 22. 23. <p:commandButton value="Non-Ajax Submit" actionListene r="#{pprBean.savePerson}" 24. ajax="false" /> 25. 26. <p:commandButton value="With Icon" actionListener="#{pprBean.savePerso n}" 27. update="panel,display" image="ui-icon ui-icon-disk" /> 28.

29.

<p:commandButton actionListener="#{pprBean.savePerson}" update="panel, display" 30. image="ui-icon ui-icon-disk" title="Icon Only"/> 31. 32. <p:commandButton value="Disabled" disabled="true" /> 33. 34. <p:panel id="display" header="Information" style="margin-top:10px;"> 35. <h:panelGrid columns="2"> 36. <h:outputText value="Firstname: " /> 37. <h:outputText value="#{pprBean.firstname}" /> 38. 39. <h:outputText value="Surname: " /> 40. <h:outputText value="#{pprBean.surname}" /> 41. </h:panelGrid> 42. </p:panel> 43. 44. </h:form>

Datatable simple row sellection 1. <h:form id="form">


2.

3. 4.
5.

<p:dataTable var="car" value="#{tableBean.carsSmall}" selection="#{tableBean.selectedCar}" selectionMode="singl e"> <f:facet name="header"> Click "View" button after selecting a row to see details </f:facet> <p:column> <f:facet name="header"> <h:outputText value="Model" /> </f:facet> <h:outputText value="#{car.model}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Year" /> </f:facet> <h:outputText value="#{car.year}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Manufacturer" /> </f:facet> <h:outputText value="#{car.manufacturer}" /> </p:column> <p:column> <f:facet name="header">

6. 8.

7. 9.

10. 11. 12. 13. 14. 15.


16.

17. 18. 19. 20. 21. 22.


23.

24. 25. 26. 27. 28. 29.


30.

31. 32.

33. 34. 35. 36.


37.

<h:outputText value="Color" /> </f:facet> <h:outputText value="#{car.color}" /> </p:column> <f:facet name="footer"> <p:commandButton value="View" image="ui-icon ui-icon-search" update="form:display" oncomplete="carDialog.show()"/> </f:facet> </p:dataTable> <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" width="200" showEffect="clip" hideEffect="fold"> <h:panelGrid id="display" columns="2" cellpadding="4">

38. 39. 40. 41.


42. 44.

43. 45. 46.


47. 49.

48. 50. 51.

<f:facet name="header"> <p:graphicImage value="/images/cars/#{tableBean.selectedCa r.manufacturer}.jpg"/> 52. </f:facet> 53. 54. <h:outputText value="Model:" /> 55. <h:outputText value="#{tableBean.selectedCar.model}" /> 56. 57. <h:outputText value="Year:" /> 58. <h:outputText value="#{tableBean.selectedCar.year}" /> 59. 60. <h:outputText value="Manufacturer:" /> 61. <h:outputText value="#{tableBean.selectedCar.manufacturer}" /> 62.

63. 64. 65. 66.


67.

<h:outputText value="Color:" /> <h:outputText value="#{tableBean.selectedCar.color}" /> </h:panelGrid> </p:dialog>

68. </h:form>
view plaincopy to clipboardprint?

1. package org.primefaces.examples.view;
2.

3. 4. 5. 6. 7.

import import import import import

java.io.Serializable; java.util.ArrayList; java.util.Date; java.util.List; java.util.UUID;

8.

9. import org.primefaces.examples.domain.Car;
10. 12.

11. public class TableBean { 13. 14.


static { colors = new String[10];

15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
25.

colors[0] colors[1] colors[2] colors[3] colors[4] colors[5] colors[6] colors[7] colors[8] colors[9]

= = = = = = = = = =

"Black"; "White"; "Green"; "Red"; "Blue"; "Orange"; "Silver"; "Yellow"; "Brown"; "Maroon";

26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36.
37. 38. 40. 42. 44. 46.

manufacturers = new String[10]; manufacturers[0] = "Mercedes"; manufacturers[1] = "BMW"; manufacturers[2] = "Volvo"; manufacturers[3] = "Audi"; manufacturers[4] = "Renault"; manufacturers[5] = "Opel"; manufacturers[6] = "Volkswagen"; manufacturers[7] = "Chrysler"; manufacturers[8] = "Ferrari"; manufacturers[9] = "Ford"; } private final static String[] colors; private final static String[] manufacturers; private List<Car> carsSmall; private Car selectedCar; public TableBean() { carsSmall = new ArrayList<Car>(); populateRandomCars(carsSmall, 9); }

39. 41. 43. 45. 47. 48.


49. 51. 52.

50. 53. 54. 55.

private void populateRandomCars(List<Car> list, int size) { for(int i = 0 ; i < size ; i++) list.add(new Car(getRandomModel(), getRandomYear(), getRandomM anufacturer(), getRandomColor())); 56. } 57. 58. public Car getSelectedCar() { 59. return selectedCar; 60. } 61. public void setSelectedCar(Car selectedCar) { 62. this.selectedCar = selectedCar; 63. } 64. 65. public List<Car> getCarsSmall() { 66. return carsSmall;

67. 68. }

____________sin botn directo 1. <h:form>


2.

3. 5.

<p:growl id="growl" showDetail="true"/>

4. <p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows ="10" 6. selection="#{tableBean.selectedCar}" selectionMode="singl e" 7. rowSelectListener="#{tableBean.onRowSelect}" 8. onRowSelectUpdate="display growl" 9. onRowSelectComplete="carDialog.show()" 10. rowUnselectListener="#{tableBean.onRowUnselect}" 11. onRowUnselectUpdate="growl"> 12. 13. <f:facet name="header"> 14. Select a row to display a message 15. </f:facet> 16. 17. <p:column> 18. <f:facet name="header"> 19. <h:outputText value="Model" /> 20. </f:facet> 21. <h:outputText value="#{car.model}" /> 22. </p:column> 23. 24. <p:column> 25. <f:facet name="header"> 26. <h:outputText value="Year" /> 27. </f:facet> 28. <h:outputText value="#{car.year}" /> 29. </p:column> 30. 31. <p:column> 32. <f:facet name="header"> 33. <h:outputText value="Manufacturer" /> 34. </f:facet> 35. <h:outputText value="#{car.manufacturer}" /> 36. </p:column> 37. 38. <p:column> 39. <f:facet name="header"> 40. <h:outputText value="Color" /> 41. </f:facet> 42. <h:outputText value="#{car.color}" /> 43. </p:column> 44. </p:dataTable>

45.

46. 47.
48. 50.

<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" width="200" showEffect="explode" hideEffect="explode"> <h:panelGrid id="display" columns="2" cellpadding="4">

49. 51. 52.

<f:facet name="header"> <p:graphicImage value="/images/cars/#{tableBean.selectedCa r.manufacturer}.jpg"/> 53. </f:facet> 54. 55. <h:outputText value="Model:" /> 56. <h:outputText value="#{tableBean.selectedCar.model}" /> 57. 58. <h:outputText value="Year:" /> 59. <h:outputText value="#{tableBean.selectedCar.year}" /> 60. 61. <h:outputText value="Manufacturer:" /> 62. <h:outputText value="#{tableBean.selectedCar.manufacturer}" /> 63.

64. 65. 66. 67.


68.

<h:outputText value="Color:" /> <h:outputText value="#{tableBean.selectedCar.color}" /> </h:panelGrid> </p:dialog>

69.

<p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows ="10" 70. selection="#{tableBean.selectedCar}" selectionMode="singl e" 71. rowSelectListener="#{tableBean.onRowSelectNavigate}" 72. dblClickSelect="true"> 73. 74. <f:facet name="header"> 75. Select a row to see the detail page 76. </f:facet> 77. 78. <p:column> 79. <f:facet name="header"> 80. <h:outputText value="Model" /> 81. </f:facet> 82. <h:outputText value="#{car.model}" /> 83. </p:column> 84. 85. <p:column> 86. <f:facet name="header"> 87. <h:outputText value="Year" /> 88. </f:facet> 89. <h:outputText value="#{car.year}" /> 90. </p:column> 91. 92. <p:column> 93. <f:facet name="header">

94. 95. 96. 97.


98.

<h:outputText value="Manufacturer" /> </f:facet> <h:outputText value="#{car.manufacturer}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Color" /> </f:facet> <h:outputText value="#{car.color}" /> </p:column> </p:dataTable>

99. 100. 101. 102. 103. 104. 105.


106. 108.

107.</h:form> 109.package org.primefaces.examples.view;


110.

111.import 112.import 113.import 114.import


115. 117. 119. 121.

java.io.Serializable; java.util.ArrayList; java.util.List; java.util.UUID;

116.import org.primefaces.examples.domain.Car; 118.import org.primefaces.event.SelectEvent; 120.public class TableBean { 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133.
134. static { colors = new String[10]; colors[0] = "Black"; colors[1] = "White"; colors[2] = "Green"; colors[3] = "Red"; colors[4] = "Blue"; colors[5] = "Orange"; colors[6] = "Silver"; colors[7] = "Yellow"; colors[8] = "Brown"; colors[9] = "Maroon"; manufacturers = new String[10]; manufacturers[0] = "Mercedes"; manufacturers[1] = "BMW"; manufacturers[2] = "Volvo"; manufacturers[3] = "Audi"; manufacturers[4] = "Renault"; manufacturers[5] = "Opel"; manufacturers[6] = "Volkswagen"; manufacturers[7] = "Chrysler"; manufacturers[8] = "Ferrari";

135. 136. 137. 138. 139. 140. 141. 142. 143. 144.

145.
146. 147. 149. 151. 153. 155.

manufacturers[9] = "Ford"; } private final static String[] colors; private final static String[] manufacturers; private List<Car> cars; private Car selectedCar; public TableBean() { carsSmall = new ArrayList<Car>(); populateRandomCars(carsSmall, 9); }

148. 150. 152. 154. 156. 157.


158. 160. 161.

159. 162. 163. 164.

private void populateRandomCars(List<Car> list, int size) { for(int i = 0 ; i < size ; i++) list.add(new Car(getRandomModel(), getRandomYear(), getRandom Manufacturer(), getRandomColor())); 165. } 166. 167. public Car getSelectedCar() { 168. return selectedCar; 169. } 170. public void setSelectedCar(Car selectedCar) { 171. this.selectedCar = selectedCar; 172. } 173. 174. public List<Car> getCars() { 175. return cars; 176. } 177. 178. public void onRowSelect(SelectEvent event) { 179. FacesMessage msg = new FacesMessage("Car Selected", ((Car) event. getObject()).getModel()); 180. 181. FacesContext.getCurrentInstance().addMessage(null, msg); 182. } 183. 184. public void onRowUnselect(UnselectEvent event) { 185. FacesMessage msg = new FacesMessage("Car Unselected", ((Car) even t.getObject()).getModel()); 186. 187. FacesContext.getCurrentInstance().addMessage(null, msg); 188. } 189. 190. public String onRowSelectNavigate(SelectEvent event) { 191. FacesContext.getCurrentInstance().getExternalContext().getFlash() .put("selectedCar", event.getObject()); 192. 193. return "carDetail?faces-redirect=true"; 194. } 195.}

Collector
Collector is an utility component to handle collections in JSF without writing java code.
Principio del formulario

form

Create a new book Title : * Author : * Reset Add

Title Author Operation df df Remove


-5283945226535
Final del formulario

Source


2.

collector.xhtml CreateBookBean.java

view plaincopy to clipboardprint?

1. <h:form id="form"> 3. 5. 6. 7. 8. 9.
10. <p:growl id="msgs" /> <p:panel header="Create a new book"> <h:panelGrid columns="2" id="grid"> <h:outputLabel value="Title : *" for="txt_title"></h:outputLab el> <p:inputText id="txt_title" value="#{createBookBean.book.title}" required=" true"/> 4.

11. 12. 13.


14. abel>

<h:outputLabel value="Author : *" for="txt_author"></h:outputL <p:inputText id="txt_author" required="true" value="#{createBookBean.book.author}" />

15. 16. 17. 18. 19. 20. 21. 22.


23.

<p:commandButton value="Reset" type="reset"/> <p:commandButton value="Add" update="books msgs @parent" action="#{createBookBean.reinit}" > <p:collector value="#{createBookBean.book}" addTo="#{createBookBean.books}" /> </p:commandButton> </h:panelGrid> </p:panel> <p:ajaxStatus style="width:16px;height:16px;"> <f:facet name="start"> <h:graphicImage value="../design/ajaxloading.gif" /> </f:facet> <f:facet name="complete"> <h:outputText value="" /> </f:facet> </p:ajaxStatus> <p:outputPanel id="books"> <p:dataTable value="#{createBookBean.books}" var="book"> <p:column> <f:facet name="header"> <h:outputText value="Title" /> </f:facet> <h:outputText value="#{book.title}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Author" /> </f:facet> <h:outputText value="#{book.author}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Operation" /> </f:facet> <p:commandLink value="Remove" update="form:books" process= "@this"> <p:collector value="#{book}" removeFrom="#{createBookBean.books}" /> </p:commandLink> </p:column> </p:dataTable> </p:outputPanel>

24. 25. 26. 27.


28.

29. 30. 31. 32.


33.

34. 35.
36.

37. 38. 39. 40. 41. 42.


43.

44. 45. 46. 47. 48. 49.


50.

51. 52. 53. 54. 55. 56. 57. 58. 59.


60.

61. 62.
63. 65.

64. </h:form>

view plaincopy to clipboardprint?

1. public class CreateBookBean {


2.

3. 5. 7. 8.

private Book book = new Book(); private List<Book> books = new ArrayList<Book>(); public String reinit() { book = new Book(); return null; } public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public List<Book> getBooks() { return books; } public void setBooks(List<Book> books) { this.books = books; }

4. 6.

9.

10.
11. 12.

13. 14.
15. 16.

17. 18.
19. 20.

21. 22.
23. 24.

25. 26.

27. 28. } 29.

public class CreateBookBean { private Book book = new Book(); private List<Book> books = new ArrayList<Book>(); public String reinit() { book = new Book(); } return null;

public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public List<Book> getBooks() { return books; }

}
1

public void setBooks(List<Book> books) { this.books = books; }

CONFIRM DIALOG 1. <h:form>


2.

3. 5. 6. 8. 9.

<p:growl id="messages" /> <h:panelGrid columns="1" cellpadding="5"> <h:outputText id="msg" value="#{buttonBean.text}"/> <p:commandButton value="Destroy the World" onclick="confirmation.s how()" type="button"/> </h:panelGrid> <p:confirmDialog message="Are you sure about destroying the world?" showEffect="bounce" hideEffect="explode" header="Initiating destroy process" severity="alert" widge tVar="confirmation">

4.

7.

10.

11. 12. 13.


14.

15.

<p:commandButton value="Yes Sure" update="messages" oncomplete="co nfirmation.hide()" 16. actionListener="#{buttonBean.destroyWorld}" /> 17. <p:commandButton value="Not Yet" onclick="confirmation.hide()" typ e="button" /> 18. 19. </p:confirmDialog> 20. 21. </h:form>
view plaincopy to clipboardprint?

1. package org.primefaces.examples.view;
2.

3. import javax.faces.application.FacesMessage; 4. import javax.faces.context.FacesContext; 5. import javax.faces.event.ActionEvent;


6. 8.

7. public class ButtonBean { 9. 10.


11. public void destroyWorld(ActionEvent actionEvent){ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO , "System Error", "Please try again later."); FacesContext.getCurrentInstance().addMessage(null, message); }

12. 13.
14. }

Combos

1. <p:column headerText="Manufacturer" style="width:150px"> 2. <p:cellEditor> 3. <f:facet name="output"> 4. <h:outputText value="#{car.manufacturer}" /> 5. </f:facet> 6. <f:facet name="input"> 7. <h:selectOneMenu value="#{car.manufacturer}" > 8. <f:selectItems value="#{tableBean.manufacturers}" 9. var="man" 10. itemLabel="#{man}" 11. itemValue="#{man}" /> 12. </h:selectOneMenu> 13. </f:facet> 14. </p:cellEditor> 15. </p:column>
http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionByColumn.jsf

FILTERING
Principio del formulario

Search all fields:


gh gh Chrysler ghgh

Model e8a0a2f0 6b72723c b106e405 dbabad7a 8065159b 142080bf 1e377717 5b4bae42 ea9b266a contains
-4055233482920

Year 1966 1993 1967 1981 1968 1966 2001 1974 2004 startsWith

Manufacturer Ferrari Chrysler Ferrari Ford Volvo Volkswagen Audi Audi BMW exact

Color Black Green Maroon Black Red Green Red Red Red endsWith

Final del formulario

Source


2.

datatableFiltering.xhtml TableBean.java

view plaincopy to clipboardprint?

1. <h:form> 3. 4.
<p:dataTable var="car" value="#{tableBean.carsSmall}" emptyMessage="No cars found with given criteria">

5.

6. 7. 8. 9.

<f:facet name="header"> <p:outputPanel> <h:outputText value="Search all fields:" /> <p:inputText id="globalFilter" onkeyup="carsTable.filter() " style="width:150px" /> 10. </p:outputPanel> 11. </f:facet> 12. 13. <p:column filterBy="#{car.model}" 14. headerText="Model" footerText="contains" 15. filterMatchMode="contains"> 16. <h:outputText value="#{car.model}" /> 17. </p:column> 18. 19. <p:column filterBy="#{car.year}" 20. headerText="Year" footerText="startsWith"> 21. <h:outputText value="#{car.year}" /> 22. </p:column> 23. 24. <p:column filterBy="#{car.manufacturer}" 25. headerText="Manufacturer" footerText="exact" 26. filterOptions="#{tableBean.manufacturerOptions}" 27. filterMatchMode="exact"> 28. <h:outputText value="#{car.manufacturer}" /> 29. </p:column> 30. 31. <p:column filterBy="#{car.color}" 32. headerText="Color" footerText="endsWith" filterMatchMode="e ndsWith"> 33. <h:outputText value="#{car.color}" /> 34. </p:column> 35. </p:dataTable> 36. 37. </h:form> 38.

39. package org.primefaces.examples.view;


40.

41. import 42. import 43. import 44. import


45. 47. 49.

java.io.Serializable; java.util.ArrayList; java.util.List; java.util.UUID;

46. import org.primefaces.examples.domain.Car; 48. public class TableBean implements Serializable { 50. 51. 52. 53. 54.
static { colors = new String[10]; colors[0] = "Black"; colors[1] = "White"; colors[2] = "Green";

55. 56. 57. 58. 59. 60. 61.


62.

colors[3] colors[4] colors[5] colors[6] colors[7] colors[8] colors[9]

= = = = = = =

"Red"; "Blue"; "Orange"; "Silver"; "Yellow"; "Brown"; "Maroon";

63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73.
74. 75. 77. 79. 81. 83.

manufacturers = new String[10]; manufacturers[0] = "Mercedes"; manufacturers[1] = "BMW"; manufacturers[2] = "Volvo"; manufacturers[3] = "Audi"; manufacturers[4] = "Renault"; manufacturers[5] = "Opel"; manufacturers[6] = "Volkswagen"; manufacturers[7] = "Chrysler"; manufacturers[8] = "Ferrari"; manufacturers[9] = "Ford"; } private final static String[] colors; private final static String[] manufacturers; private SelectItem[] manufacturerOptions; private List<Car> carsSmall; public TableBean() { carsSmall = new ArrayList<Car>(); populateRandomCars(carsSmall, 9); manufacturerOptions = createFilterOptions(manufacturers); }

76. 78. 80. 82. 84. 85.


86. 88. 89. 90.

87.

91. 92. 93.

private void populateRandomCars(List<Car> list, int size) { for(int i = 0 ; i < size ; i++) list.add(new Car(getRandomModel(), getRandomYear(), getRandomM anufacturer(), getRandomColor())); 94. } 95. 96. public List<Car> getCarsSmall() { 97. return carsSmall; 98. } 99. 100. private int getRandomYear() { 101. return (int) (Math.random() * 50 + 1960); 102. } 103. 104. private String getRandomColor() { 105. return colors[(int) (Math.random() * 10)]; 106. } 107.

108. 109. 110.


111.

private String getRandomManufacturer() { return manufacturers[(int) (Math.random() * 10)]; } private String getRandomModel() { return UUID.randomUUID().toString().substring(0, 8); } private SelectItem[] createFilterOptions(String[] data) { SelectItem[] options = new SelectItem[data.length + 1]; options[0] = new SelectItem("", "Select"); for(int i = 0; i < data.length; i++) { options[i + 1] = new SelectItem(data[i], data[i]); } return options; } public SelectItem[] getManufacturerOptions() { return manufacturerOptions; }

112. 113. 114.


115.

116. 117.
118.

119. 120. 121. 122.


123. 125. 126.

124. 127. 128.

129. 130.}

package pe.cajapiura.com.entities; import java.io.Serializable; import javax.persistence.*; import java.util.Date; import java.util.Set; /** * The persistent class for the TB_MPU_SISTEMA database table. * */ @Entity @Table(name="TB_MPU_SISTEMA") @NamedQueries({@NamedQuery(name = "TbMpuSistema.findAll", query = "Select s from TbMpuSistema s"),@NamedQuery(name = "TbMpuSistema.findByCodigo", query = "SELECT s from TbMpuSistema s where s.sistemaCodigo=:sistemaCodigo")}) public class TbMpuSistema implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="SISTEMA_CODIGO")

private String sistemaCodigo; @Column(name="SISTEMA_DESCRIPCION") private String sistemaDescripcion; @Column(name="SISTEMA_ESTADO") private String sistemaEstado; @Temporal( TemporalType.DATE) @Column(name="SISTEMA_FECHAINACT") private Date sistemaFechainact; @Temporal( TemporalType.DATE) @Column(name="SISTEMA_FECHAREG") private Date sistemaFechareg; @Column(name="SISTEMA_NOMBRE") private String sistemaNombre; @Column(name="SISTEMA_RUTA") private String sistemaRuta; @Column(name="SISTEMA_RUTACONTING") private String sistemaRutaconting; //bi-directional many-to-one association to TbMpuFlujo @OneToMany (mappedBy="tbMpuSistema") private Set<TbMpuFlujo> tbMpuFlujos; //bi-directional many-to-one association to TbMpuMenu @OneToMany(mappedBy="tbMpuSistema") private Set<TbMpuMenu> tbMpuMenus; //bi-directional many-to-one association to TbMpuUsusistema @OneToMany(mappedBy="tbMpuSistema") private Set<TbMpuUsusistema> tbMpuUsusistemas; //bi-directional many-to-one association to TbMpuVersionsist @OneToMany(mappedBy="tbMpuSistema") private Set<TbMpuVersionsist> tbMpuVersionsists; public TbMpuSistema() { } public String getSistemaCodigo() { return this.sistemaCodigo; } public void setSistemaCodigo(String sistemaCodigo) { this.sistemaCodigo = sistemaCodigo; } public String getSistemaDescripcion() { return this.sistemaDescripcion; } public void setSistemaDescripcion(String sistemaDescripcion) {

this.sistemaDescripcion = sistemaDescripcion; } public String getSistemaEstado() { return this.sistemaEstado; } public void setSistemaEstado(String sistemaEstado) { this.sistemaEstado = sistemaEstado; } public Date getSistemaFechainact() { return this.sistemaFechainact; } public void setSistemaFechainact(Date sistemaFechainact) { this.sistemaFechainact = sistemaFechainact; } public Date getSistemaFechareg() { return this.sistemaFechareg; } public void setSistemaFechareg(Date sistemaFechareg) { this.sistemaFechareg = sistemaFechareg; } public String getSistemaNombre() { return this.sistemaNombre; } public void setSistemaNombre(String sistemaNombre) { this.sistemaNombre = sistemaNombre; } public String getSistemaRuta() { return this.sistemaRuta; } public void setSistemaRuta(String sistemaRuta) { this.sistemaRuta = sistemaRuta; } public String getSistemaRutaconting() { return this.sistemaRutaconting; } public void setSistemaRutaconting(String sistemaRutaconting) { this.sistemaRutaconting = sistemaRutaconting; } public Set<TbMpuFlujo> getTbMpuFlujos() { return this.tbMpuFlujos; } public void setTbMpuFlujos(Set<TbMpuFlujo> tbMpuFlujos) { this.tbMpuFlujos = tbMpuFlujos;

} public Set<TbMpuMenu> getTbMpuMenus() { return this.tbMpuMenus; } public void setTbMpuMenus(Set<TbMpuMenu> tbMpuMenus) { this.tbMpuMenus = tbMpuMenus; } public Set<TbMpuUsusistema> getTbMpuUsusistemas() { return this.tbMpuUsusistemas; } public void setTbMpuUsusistemas(Set<TbMpuUsusistema> tbMpuUsusistemas) { this.tbMpuUsusistemas = tbMpuUsusistemas; } public Set<TbMpuVersionsist> getTbMpuVersionsists() { return this.tbMpuVersionsists; } public void setTbMpuVersionsists(Set<TbMpuVersionsist> tbMpuVersionsists) { this.tbMpuVersionsists = tbMpuVersionsists; } }

_____________________________GestionaSitema--Inserta
<?xml version="1.0" encoding="ISO-8859-1" ?> <!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.prime.com.tr/ui"> <f:view> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Gestionar Sistemas</title> </h:head> <h:body> <h:form id="form_save"> <h:messages/> <h:panelGrid columns="3"> <h:outputLabel value="Codigo" for="Codigo" />

<h:inputText value="#{listaSistemaBean.sistema.sistemaCodigo}" id="name" required="true"/> <h:message for="Codigo"/> for="Descripcion" /> <h:outputLabel value="Descripcion"

<h:inputText value="#{listaSistemaBean.sistema.sistemaDescripcion}" id="email" required="true"/> <h:message for="Descripcion"/> <h:outputLabel value="Nombre" for="Nombre" /> <h:inputText value="#{listaSistemaBean.sistema.sistemaNombre}" id="Nombre" required="true"/> <h:message for="Nombre"/> <h:outputLabel value="Ruta" for="Ruta" /> <h:inputTextarea value="#{listaSistemaBean.sistema.sistemaRuta}" id="message" required="true"/> <h:message for="Ruta"/> <h:outputText value="" /> <h:commandButton action="#{listaSistemaBean.save()}" value="Guardar" /> <h:outputText value="" /> </h:panelGrid> </h:form> </h:body> </f:view> </html>

Modificar y coger fila

1. <h:form id="form">
2.

3. 5. 7. 8. 9.

<p:growl id="msgs" showDetail="true" /> <p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}"> <p:column headerText="Model"> <h:outputText value="#{car.model}" /> </p:column> <p:column headerText="Year"> <h:outputText value="#{car.year}" /> </p:column> <p:column headerText="Manufacturer"> <h:outputText value="#{car.manufacturer}" /> </p:column> <p:column headerText="Color"> <h:outputText value="#{car.color}" /> </p:column> <p:column style="width:100px">

4. 6.

10.

11. 12. 13.


14.

15. 16. 17.


18.

19. 20. 21.


22.

23.

24. 25.

<h:panelGrid columns="3" styleClass="actions" cellpadding="2">

<p:commandButton update=":form:display" oncomplete="carDia log.show()" image="ui-icon ui-icon-search" title="View"> 26. <f:setPropertyActionListener value="#{car}" target="#{ tableBean.selectedCar}" /> 27. <f:setPropertyActionListener value="#{false}" target=" #{tableBean.editMode}" /> 28. </p:commandButton> 29. <p:commandButton update=":form:display" oncomplete="carDia log.show()" image="ui-icon ui-icon-pencil" title="Edit"> 30. <f:setPropertyActionListener value="#{car}" target="#{ tableBean.selectedCar}" /> 31. <f:setPropertyActionListener value="#{true}" target="# {tableBean.editMode}" /> 32. </p:commandButton> 33. <p:commandButton update=":form:display" oncomplete="confir mation.show()" image="ui-icon ui-icon-close" title="Delete"> 34. <f:setPropertyActionListener value="#{car}" target="#{ tableBean.selectedCar}" /> 35. </p:commandButton> 36. </h:panelGrid> 37. </p:column> 38. 39. </p:dataTable> 40. 41. <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" id="carDlg" 42. width="300" showEffect="fade" hideEffect="explode" modal="tr ue"> 43. 44. <h:panelGrid id="display" columns="2" cellpadding="4" style="margi n:0 auto;"> 45. 46. <f:facet name="header"> 47. <p:graphicImage value="/images/cars/#{tableBean.selectedCa r.manufacturer}.jpg"/> 48. </f:facet> 49. 50. <h:outputText value="Model:" /> 51. <h:panelGroup> 52. <h:outputText value="#{tableBean.selectedCar.model}" style ="font-weight:bold" rendered="#{!tableBean.editMode}"/> 53. <p:inputText value="#{tableBean.selectedCar.model}" render ed="#{tableBean.editMode}" required="true" label="Model"/> 54. </h:panelGroup> 55. 56. <h:outputText value="Year:" /> 57. <h:panelGroup> 58. <h:outputText value="#{tableBean.selectedCar.year}" style= "font-weight:bold" rendered="#{!tableBean.editMode}"/> 59. <p:inputText value="#{tableBean.selectedCar.year}" rendere d="#{tableBean.editMode}" required="true" label="Year"/> 60. </h:panelGroup> 61.

62. 63. 64.

<h:outputText value="Manufacturer:" /> <h:panelGroup> <h:outputText value="#{tableBean.selectedCar.manufacturer} " style="font-weight:bold" rendered="#{!tableBean.editMode}"/> 65. <h:selectOneMenu value="#{tableBean.selectedCar.manufactur er}" rendered="#{tableBean.editMode}"> 66. <f:selectItems value="#{tableBean.manufacturers}" var=" man" itemLabel="#{man}" itemValue="#{man}" /> 67. </h:selectOneMenu> 68. </h:panelGroup> 69. 70. <h:outputText value="Color:" /> 71. <h:panelGroup> 72. <h:outputText value="#{tableBean.selectedCar.color}" style ="font-weight:bold" rendered="#{!tableBean.editMode}"/> 73. <h:selectOneMenu value="#{tableBean.selectedCar.color}" re ndered="#{tableBean.editMode}"> 74. <f:selectItems value="#{tableBean.colors}" var="color" itemLabel="#{color}" itemValue="#{color}" /> 75. </h:selectOneMenu> 76. </h:panelGroup> 77. 78. <f:facet name="footer"> 79. <p:outputPanel rendered="#{tableBean.editMode}" layout="bl ock" style="text-align:right"> 80. <p:commandButton value="Save" update="cars msgs" action Listener="#{tableBean.save}" 81. oncomplete="onEditComplete(xhr,status,a rgs)" image="ui-icon ui-icon-check"/> 82. <p:commandButton value="Cancel" onclick="carDialog.hide ()" type="button" image="ui-icon ui-icon-close"/> 83. 84. </p:outputPanel> 85. </f:facet> 86. </h:panelGrid> 87. 88. </p:dialog> 89. 90. <p:confirmDialog message="Are you sure?" width="200" 91. showEffect="explode" hideEffect="explode" 92. header="Confirm" severity="alert" widgetVar="confirmati on"> 93. 94. <p:commandButton value="Yes sure" update="cars" actionListener="#{ tableBean.delete}" oncomplete="confirmation.hide()"/> 95. <p:commandButton value="Not yet" onclick="confirmation.hide()" typ e="button" /> 96. 97. </p:confirmDialog> 98. 99. </h:form> 100.

1. package org.primefaces.examples.view;
2.

3. 4. 5. 6. 7.

import import import import import

java.io.Serializable; java.util.ArrayList; java.util.Date; java.util.List; java.util.UUID;

8.

9. import org.primefaces.examples.domain.Car;
10. 12.

11. public class TableBean { 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
25. static { colors = new String[10]; colors[0] = "Black"; colors[1] = "White"; colors[2] = "Green"; colors[3] = "Red"; colors[4] = "Blue"; colors[5] = "Orange"; colors[6] = "Silver"; colors[7] = "Yellow"; colors[8] = "Brown"; colors[9] = "Maroon"; manufacturers = new String[10]; manufacturers[0] = "Mercedes"; manufacturers[1] = "BMW"; manufacturers[2] = "Volvo"; manufacturers[3] = "Audi"; manufacturers[4] = "Renault"; manufacturers[5] = "Opel"; manufacturers[6] = "Volkswagen"; manufacturers[7] = "Chrysler"; manufacturers[8] = "Ferrari"; manufacturers[9] = "Ford"; } private final static String[] colors; private final static String[] manufacturers; private List<Car> cars; private Car selectedCar; private boolean editMode; public TableBean() {

26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36.
37. 38. 40. 42. 44. 46. 48.

39. 41. 43. 45. 47. 49.

50.
51. 53. 54.

cars = new ArrayList<Car>(); populateRandomCars(cars, 50); }

52. 55. 56. 57.

private void populateRandomCars(List<Car> list, int size) { for(int i = 0 ; i < size ; i++) list.add(new Car(getRandomModel(), getRandomYear(), getRandomM anufacturer(), getRandomColor())); 58. } 59. 60. public Car getSelectedCar() { 61. return selectedCar; 62. } 63. public void setSelectedCar(Car selectedCar) { 64. this.selectedCar = selectedCar; 65. } 66. 67. public List<Car> getCars() { 68. return cars; 69. } 70. 71. private int getRandomYear() { 72. return (int) (Math.random() * 50 + 1960); 73. } 74. 75. private String getRandomColor() { 76. return colors[(int) (Math.random() * 10)]; 77. } 78. 79. private String getRandomManufacturer() { 80. return manufacturers[(int) (Math.random() * 10)]; 81. } 82. 83. private String getRandomModel() { 84. return UUID.randomUUID().toString().substring(0, 8); 85. } 86. 87. public void delete() { 88. carsSmall.remove(selectedCar); 89. } 90. 91. public boolean isEditMode() { 92. return editMode; 93. } 94. 95. public void setEditMode(boolean editMode) { 96. this.editMode = editMode; 97. } 98. } 99.

<?xml version="1.0" encoding="ISO-8859-1" ?> <!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.prime.com.tr/ui"> <f:view> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Lista de Sistemas</title> </h:head> <h:body> <h:form prependId="false"> <p:dataTable var="sist" value="#{listaSistemaBean.lista}" paginator="true" rows="5" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" binding="#{listaSistemaBean.tblLista}" selection="#{listaSistemaBean.sistema}" selectionMode="single" dynamic="true" paginatorPosition="bottom" rowsPerPageTemplate="5,10,15" loadingMessage="Procesando..." rowSelectListener="#{listaSistemaBean.onRowSelect}" onRowSelectUpdate="display growl" onRowSelectComplete="carDialog.show()" rowUnselectListener="#{listaSistemaBean.onRowUnselect}" onRowUnselectUpdate="growl"> <p:column> <!-value="Codigo" /> <!-<f:facet name="header"> <h:outputText </f:facet> --> <h:outputText value="#{sist.sistemaCodigo}" /> -->

<p:cellEditor> <f:facet name="output"> <h:outputText value="#{sist.sistemaCodigo}" /> </f:facet> <f:facet name="input"> <p:inputText value="#{sist.sistemaCodigo}" style="width:100%"/> </f:facet> </p:cellEditor> </p:column> <p:column> <f:facet name="header"> value="Nombre" /> </f:facet> <h:outputText

<h:outputText value="#{sist.sistemaNombre}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Estado" /> </f:facet> <h:outputText value="#{sist.sistemaEstado}" /> </p:column> <p:column headerText="Options"> <p:rowEditor /> </p:column> </p:dataTable> </h:form> </h:body> </f:view> </html>

Mi consulta en el jpa es esta @NamedQuery(name = "TbMpuSistema.findByLike", query = "SELECT s from TbMpuSistema s where s.sistemaCodigo like:arg or s.sistemaNombre like:arg") mi metodo en el ebj est asi @SuppressWarnings("unchecked") @Override public List<TbMpuSistema> listarFiltro(String arg){ List<TbMpuSistema> lista = null; Query q = em.createNativeQuery("TbMpuSistema.findByLike"); //lista =q.getResultList(); lista =q.setParameter("arg", arg).getResultList(); return lista; } mi metodo en el bean private String filtroSistema; public void setFiltroSistema(String filtroSistema) { this.filtroSistema = filtroSistema; } public String getFiltroSistema() { return filtroSistema; } public List<TbMpuSistema> buscarFiltro(){ InitialContext ctx;

try { ctx = new InitialContext(); SistemaEJBRemote service = (SistemaEJBRemote) ctx .lookup("ejb/SistemaEJB"); lista = new ArrayList<TbMpuSistema>(service.listarFiltro(this.filtroSistema)); } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return lista; }

Y n mi interface esta asi <f:facet name="header"> <p:outputPanel> <h:outputText value="Buscar todos los campos:" /> <h:inputText id="txtParametro" value="#{listaSistemaBean.filtroSistema}" size="50" style="width:350px;"> </h:inputText> <p:commandButton value="Filtrar" image="uiicon ui-icon-search" actionListener="#{listaSistemaBean.buscarFiltro()}"/> </p:outputPanel> </f:facet> Pero me da este error: Exception [EclipseLink-4002] (Eclipse Persistence Services 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLSyntaxErrorException: [SQL0104] Smbolo TBMPUSISTEMA no vlido. Smbolos vlidos: ( END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER. Error Code: -104 Call: TbMpuSistema.findByLike Query: DataReadQuery(sql="TbMpuSistema.findByLike") at org.eclipse.persistence.exceptions.DatabaseException.sqlException(Databas eException.java:333) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processE xceptionForCommError(DatabaseAccessor.java:1420) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExe cuteCall(DatabaseAccessor.java:676)

at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeC all(DatabaseAccessor.java:526) at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCal l(AbstractSession.java:1729) at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientS ession.java:234) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.exe cuteCall(DatasourceCallQueryMechanism.java:207) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.exe cuteCall(DatasourceCallQueryMechanism.java:193) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.exe cuteSelectCall(DatasourceCallQueryMechanism.java:264) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.exe cuteSelect(DatasourceCallQueryMechanism.java:246) at org.eclipse.persistence.queries.DataReadQuery.executeNonCursor(DataReadQu ery.java:192) at org.eclipse.persistence.queries.DataReadQuery.executeDatabaseQuery(DataRe adQuery.java:148) at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java: 808) at org.eclipse.persistence.queries.DataReadQuery.execute(DataReadQuery.java: 134) at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(Databas eQuery.java:711) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQ uery(UnitOfWorkImpl.java:2842) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(Ab stractSession.java:1521) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(Ab stractSession.java:1503) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(Ab stractSession.java:1477) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQue ryImpl.java:484) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryI mpl.java:741) at pe.cajapiura.com.beans.SistemaEJB.listarFiltro(SistemaEJB.java:115) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI mpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSe curityManager.java:1052) at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecur ityManager.java:1124) at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java: 5367) at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(Inte rceptorManager.java:801) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(Syste mInterceptorProxy.java:162) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(S ystemInterceptorProxy.java:144) at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI mpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(Int erceptorManager.java:862) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(Inte rceptorManager.java:801) at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(Intercep torManager.java:371) at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339) at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327) at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocat ionHandler.java:206) at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjec tInvocationHandlerDelegate.java:79) at $Proxy186.listarFiltro(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI mpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateI nvoke(StubInvocationHandlerImpl.java:241) at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(S tubInvocationHandlerImpl.java:152) at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(Cod egenStubBase.java:227) at pe.cajapiura.com.beans.__SistemaEJBRemote_Remote_DynamicStub.listarFiltro (pe/cajapiura/com/beans/__SistemaEJBRemote_Remote_DynamicStub.java) at pe.cajapiura.com.beans._SistemaEJBRemote_Wrapper.listarFiltro(pe/cajapiur a/com/beans/_SistemaEJBRemote_Wrapper.java) at pe.cajapiura.com.Bean.listaSistemaBean.buscarFiltro(listaSistemaBean.java :100) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI mpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737) at javax.el.BeanELResolver.invoke(BeanELResolver.java:467) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254) at com.sun.el.parser.AstValue.invoke(AstValue.java:228) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression. java:105) at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpr essionActionListener.java:148) at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) at javax.faces.component.UICommand.broadcast(UICommand.java:300) at javax.faces.component.UIData.broadcast(UIData.java:1093) at org.primefaces.component.datatable.DataTable.broadcast(DataTable.java:630 ) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationP hase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:153 4) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve .java:281) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve .java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java: 655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:59 5) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionL ockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java: 326) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:22 7) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapp er.java:170) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter. java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtoco lChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:10 4) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90 )

at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask. java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java :59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool. java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.r

http://www.compujuy.com.ar/postx.php?id=86

AUTOCOMPLETE

1. <h:form> 2. <p:growl id="messages" showDetail="true"/>


3.

4. 5. 6. 7. 9.

<p:autoComplete value="#{autoCompleteBean.selectedPlayer}" completeMethod="#{autoCompleteBean.completePlayer}" var="player" itemLabel="#{player.name}" itemValue="#{player}" converter="player"/> <p:commandButton value="Submit" update="player messages" />

8. 10.

11.

<h:outputText id="player" value="Selected: #{autoCompleteBean.selected Player.name}" /> 12. </h:form>

package org.primefaces.examples.view; import java.util.ArrayList; import java.util.List; import org.primefaces.examples.domain.Player; import org.primefaces.examples.view.PlayerConverter; public class AutoCompleteBean { private Player selectedPlayer; private List<Player> players;

public AutoCompleteBean() { players = PlayerConverter.playerDB; } public Player getSelectedPlayer() { return selectedPlayer; } public void setSelectedPlayer(Player selectedPlayer) { this.selectedPlayer = selectedPlayer; } public List<Player> completePlayer(String query) { List<Player> suggestions = new ArrayList<Player>(); for(Player p : players) { if(p.getName().startsWith(query)) suggestions.add(p); } return suggestions; } }

//____// package org.primefaces.examples.view; import java.util.ArrayList; import java.util.List; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException;

import org.primefaces.examples.domain.Player; public class PlayerConverter implements Converter { public static List<Player> playerDB; static { playerDB = new ArrayList<Player>(); playerDB.add(new Player("Messi", 10)); playerDB.add(new Player("Bojan", 9)); playerDB.add(new Player("Henry", 14)); playerDB.add(new Player("Iniesta", 8)); playerDB.add(new Player("Villa", 7)); playerDB.add(new Player("Xavi", 6)); playerDB.add(new Player("Puyol", 5)); playerDB.add(new Player("Afellay", 20)); playerDB.add(new Player("Abidal", 22)); playerDB.add(new Player("Alves", 2)); playerDB.add(new Player("Pique", 3)); playerDB.add(new Player("Keita", 15)); playerDB.add(new Player("Busquets", 16)); playerDB.add(new Player("Adriano", 21)); playerDB.add(new Player("Valdes", 1)); playerDB.add(new Player("Thiago", 30)); } public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) { if (submittedValue.trim().equals("")) { return null; } else { try { int number = Integer.parseInt(submittedValue);

for (Player p : playerDB) { if (p.getNumber() == number) { return p; } }

} catch(NumberFormatException exception) { throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player")); } }

return null; }

public String getAsString(FacesContext facesContext, UIComponent component, Object value) { if (value == null || value.equals("")) { return ""; } else { return String.valueOf(((Player) value).getNumber()); } } } __________________COMBOS______________________________ http://www.primefaces.org/showcase-labs/ui/selectOneMenu.jsf

Você também pode gostar