i'm writing a web application in tapestry. In my application i want to use friendly urls. Now i'm able to to render the url page like this:
http://localhost:8080/page/page-name
wat i want to do is to render URLs like this:
http://localhost:8080/page-name
All pages are stored on a Postgresql DB. I'm currently using Tapestry 5.4-beta16 and i've already read the tapestry documentation:
http://tapestry.apache.org/url-rewriting.html
http://blog.tapestry5.de/index.php/2010/09/06/new-url-rewriting-api/
Now, this is the Class for list all pages stored on the DB (Only for test)
public class Pages {
@Inject
private Session session;
@Property
List<it.garuti.tapestrycms.entities.Pagine> pagine;
@Property
private it.garuti.tapestrycms.entities.Pagine pagina;
void setupRender() {
pagine = session.createCriteria(it.garuti.tapestrycms.entities.Pagine.class).list();
}
}
And this is the class for show the page content:
public class Page {
@Property
private Page page;
@Inject
private Logger logger;
@Inject
private Session session;
@Inject
Request request;
@InjectPage
Index index;
@Property
private String slug;
void onActivate(String slug) {
this.slug = slug;
}
Object onActivate() {
if (session.createCriteria(Pagine.class)
.add(Restrictions.eq("slug", slug)).uniqueResult() == null)
return new HttpError(404, "Resource not found");
return null;
}
String onPassivate() {
return slug;
}
void setupRender() {
page = (Pages) session.createCriteria(Pages.class)
.add(Restrictions.eq("slug", slug)).uniqueResult();
}
}
And finally the Entity for Pages:
@Entity
@Table(name = "pages", schema = "public")
public class Pages implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pagine_seq")
@SequenceGenerator( name= "pagine_seq", sequenceName = "pagine_id_seq")
@Column(name = "id", unique = true, nullable = false)
private long id;
@Column(name = "titolo", nullable = false, length = 60, unique = true)
private String titolo;
@Column(name = "slug", nullable = false, length = 60, unique = true)
private String slug;
@Column(name = "contenuto", nullable = false, columnDefinition = "TEXT")
private String contenuto;
@Column(name = "data_creazione", nullable = false)
private Date dataCreazione;
@Column(name = "data_modifica")
private Date dataModifica;
@Column(name = "stato", nullable = false)
private String stato;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "utente_id", nullable = false)
private Users user;
getter and setter...
....
}
Tank You Lorenzo