Search code examples
javatapestry

I want to post a lists with hotels in a tapestry page but this error appears over and over


I have done a few changes but i still have an error:

Render queue error in BeginRender[ShowAll:grid.rows.gridcell]: com.mycompany.licenta.pages.Hotel cannot be cast to com.mycompany.licenta.pages.Hotel

TML page:

<html t:type="layout" title="Show All"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
      xmlns:p="tapestry:parameter">

   <head>
   <title>Lista Hoteluri</title>
  </head>
   <body>
     <t:grid t:source="allHotels"/>

<br/>
      <a href="#" t:type="PageLink" t:page="Index">
      Back to the Start Page</a>
    </body>

</html>

Java Class If you need any classes feel free to ask. Thank you!

      package com.mycompany.licenta.pages;
import org.apache.tapestry5.annotations.SessionState;
import com.mycompany.licenta.util.User;
import com.mycompany.licenta.data.ListaHoteluri;
import com.mycompany.licenta.pages.Hotel;
import com.mycompany.licenta.data.IDataSource;
import java.util.List;
import java.text.Format;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
/**
 *
 * @author Alina
 */ 
public class ShowAll {
    @SessionState
private User user;
private boolean userExists;

@SessionState
private IDataSource dataSource;

@InjectPage
private Details detailsPage;
private Hotel hotel;
String onActivate()
{
    if(!userExists) return "Index";
    return null;
}

//@OnEvent(component="detailsLink")
Object onShowDetails(long id)  
       {
Hotel hotel = dataSource.getHotelById(id);
detailsPage.setHotel(hotel);
return detailsPage;
     }
public List<Hotel>getAllHotels()
{
return dataSource.getAllHotels();
}
public Hotel getHotel()
{
return hotel;
} 
public void setHotel(Hotel hotel)
{
this.hotel = hotel;
}

//Object onActivate()
//{if (!userExists) return Index.class; return null;}
} 

And the hotel class is this:-----------------------------------------------------

package com.mycompany.licenta.pages;

/**
 *
 * @author Alina
 */
public class Hotel {
   private long id;
   private String numeHotel;
   private String adresaHotel;
   private float notaGenerala;
   private int numarRecenzii;
   private int numarVizualizari;

   public Hotel()
           { 

           }
public Hotel(String numeHotel,String adresaHotel,float notaGenerala,int numarRecenzii,
        int numarVizualizari)
{
    this.numeHotel=numeHotel;
    this.adresaHotel=adresaHotel;
    this.notaGenerala=notaGenerala;
    this.numarRecenzii=numarRecenzii;
    this.numarVizualizari=numarVizualizari;
}

public String getNumeHotel()
{
return numeHotel;
}
public void setNumeHotel(String numeHotel)
{
this.numeHotel = numeHotel;
}
public String getAdresaHotel()
{
return adresaHotel;
}
public void setAdresaHotel(String adresaHotel)
{
this.adresaHotel = adresaHotel;
}
public float getNotaGenerala()
{
return notaGenerala;
}

public void setNotaGenerala(float notaGenerala)
{
this.notaGenerala = notaGenerala;
}
public int getNumarRecenzii()
{
return numarRecenzii;
}
public void setNumarRecenzii(int numarRecenzii)
{
this.numarRecenzii= numarRecenzii;
}
public int getNumarVizualizari()
{
return numarVizualizari;
}
public void setNumarVizualizari(int numarVizualizari)
{
    this.numarVizualizari=numarVizualizari;
}
public long getId()
{
    return id;
}
public void setId(long id)
{
    this.id=id;
}
}

Solution

  • Why is your Hotel class, which does not appear to be a valid tapestry page, in the pages package? pages is a special package reserved for valid Tapestry page classes. Move your model class to a package outside the pages package (don't move it to a sub package, try something like com.mycompany.licenta.data). Also make sure you don't have both a model class and a page named Hotel, and you are importing the wrong Hotel into your ShowAll page.