lazy datatable ManyToOne tables

UI Components for JSF
Post Reply
jhony.freire
Posts: 5
Joined: 30 Sep 2017, 22:36

14 Apr 2018, 01:12

Hi, i'm usin lazy datatable. But i have this problem.

In my datatable take any field

Code: Select all

  <p:dataTable var="f" lazy="true">... <p:column   headerText="NIE"  filterBy="#{f.hacendado.hacdnicif}" width="5%" sortBy="#{f.hacendado.hacdnicif}" >
				<h:outputText value="#{f.hacendado.hacdnicif}" />		
		</p:column>
The lazy code i have this.

Code: Select all

 String filterProperty = it.next();
                        Object filterValue = filters.get(filterProperty);
                        Field campo = finca.getClass().getDeclaredField(filterProperty); //
                        campo.setAccessible(true);
                        String fieldValue = String.valueOf(campo.get(finca));
This generate this error:

Code: Select all

 java.lang.NoSuchFieldException: hacendado.hacdnicif
	at java.lang.Class.getDeclaredField(Class.java:2070)
	at regantes.lazyDataModel.LazyFinca.load(LazyFinca.java:70)
The class Finca

Code: Select all

 public class Finca implements java.io.Serializable {
	....
	private Hacendado hacendado;
	....
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "finidhacendado")
	public Hacendado getHacendado() {
		return this.hacendado;
	}
	
	public void setHacendado(Hacendado hacendado) {
		this.hacendado = hacendado;
	}
The propertie hacdnicif is the class Hacendado
¿How do i get this data?

i try add any property in the class Finca

Code: Select all

  private String hacdnicif;
	
	public String getHacdnicif() {
		return getHacendado().getHacdnicif();
	}
    ..column datatable <p:column   headerText="DNI"  filterBy="#{f.hacdnicif}" width="5%" >
	<h:outputText value="#{f.hacendado.hacdnicif}" />		
</p:column>
but this return **fieldValue : null**

Thanks for help.
PrimeFaces 6.0
JSF 2.2
Glasfish 4 server

jhony.freire
Posts: 5
Joined: 30 Sep 2017, 22:36

14 Apr 2018, 15:29

Resolved

add property in class finca

private String hacdnicif;
public String getHacdnicif() {
return hacdnicif;
}
and use in the datatable for filter :
<p:column headerText="DNI" filterBy="#{f.hacdnicif}" width="5%" sortBy="#{f.hacendado.hacdnicif}" >
<h:outputText value="#{f.hacendado.hacdnicif}" />
</p:column>

and the lazy code implement this.

String filterProperty = it.next();
Object filterValue = filters.get(filterProperty);
if (filterProperty.contains("hacnombre")){
fieldValue = finca.getHacendado().getHacnombre();
} else if (filterProperty.contains("hacdni")){
fieldValue = finca.getHacendado().getHacdnicif();
}//.... for field manytoone
else{
Field campo = finca.getClass().getDeclaredField(filterProperty); //
campo.setAccessible(true);
fieldValue = String.valueOf(campo.get(finca));
}
PrimeFaces 6.0
JSF 2.2
Glasfish 4 server

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Apr 2018, 10:10

please edit your previous post and format the code

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: APTEMKA and 39 guests