1. Moving from page1 (page1.xhtml) to page2 (page2.xhtml)
If it is displayed page1.xhtml and we need to go to page2.xhtml we need a component that executes an action (button, href etc)This action should point to the method of a managed bean and should return a string whose value is "page2".
xhtml file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!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://xmlns.jcp.org/jsf/html"> <h:head> </h:head> <h:body> <fieldset> <legend>Go to Pag2 example</legend> <h:form> Press button to go to page 2. <br/> <h:commandButton value="Go to page2" action="#{navigator.goToPage2}"/> </h:form> </fieldset> </h:body> </html> |
Java file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | package org.ximodante.jsf.coreservletsexamples; import java.io.Serializable; import javax.faces.view.ViewScoped; import javax.inject.Named; @Named @ViewScoped public class Navigator implements Serializable { private static final long serialVersionUID = 1L; public Navigator() {} public String goToPage2() { return "page2"; } } |
No hay comentarios:
Publicar un comentario