Escolar Documentos
Profissional Documentos
Cultura Documentos
Os 10
Tarso Bessa
A maioria dos desenvolvedores web que j trabalharam ou trabalham com algum framework action-like acabam tendo grandes dificuldades ao desenvolverem com JSF.
10 Mau hbito
9 Mau hbito
SOLUO?
session?
Myfaces Tomahawk [t:saveState] Myfaces Orchestra Myfaces Trinidad [pageFlowScope] JBoss Seam JBoss Richfaces [a4j:keepAlive] etc
8 Mau hbito
SOLUO?
Simplesmente
REDIRECT
7 Mau hbito
Alterar o estado de algum componente no lado cliente [browser] atravs de javascript e esperar que isso seja entendido pelo JSF
Firebug
SOLUO?
6 Mau hbito
<h:dataTable value="#{users}" var="user"> <h:column ...> <h:commandLink value="X" action="#{bean.remove}" > <f:param name="id" value="#{user.id}"/> </h:commandLink> </h:column> </h:dataTable>
public void remove(){ Integer id = new Integer( facesContext.getExternalContext(). getRequestParametersMap(). get(id) ); User user = search(id); if(user != null){ ... } }
SOLUO?
Pensar mais orientado a objetos e deixar com que os componentes troquem objetos e no chaves primrias
<h:dataTable value="#{users}" var="user"> <h:column ...> <h:commandLink value="X" action="#{bean.remove}" > <f:setPropertyActionListener value="#{user}" target="#{bean.user}"/> </h:commandLink> </h:column> </h:dataTable>
public void setUser(User user){ this.user = user; } public void remove(){ if(user != null){ // ... } }
5 Mau hbito
Restore View
Process Validations
Render Response
Invoke Application
//immediate=false private UIInput input; //immediate=true public void calcTaxes(ActionEvent e) { String dateStr = (String) input.getSubmittedValue(); Date date = convertDate ( dateStr ); if( date.after ( otherDate ) ) { //calculate } }
SOLUO?
private Date date; //immediate=false public void calcTaxes(ActionEvent e) { if( date.after ( otherDate ) ) { //calculate } }
A quem recorrer?
4 Mau hbito
public class LoginPhaseListener implements PhaseListener { //on RESTORE_VIEW public void afterPhase(PhaseEvent e) { if( !isLoggedIn() && !isLogin() ){ //navigate to login page } } }
SOLUO?
Usar /faces/* ou *.jsf quando se tem pginas em xhtml pode levar a uma exposio do cdigo fonte.
3 Mau hbito
Uma das melhores maneiras de matar a escalabilidade da aplicao a utilizao indiscriminada da session
SOLUO?
2 Mau hbito
SOLUO?
public class Bean { @PostConstruct public void initialize(){ this.users = service.findAllUsers(); } public List<User> getUsersList() { return this.users; } }
public class Bean { public void search(ActionEvent e){ this.users = service.findUsers( ); } public List<User> getUsersList() { return this.users; } }
1 Mau hbito
JSF LIFECYCLE
JSF LIFECYCLE
JSF LIFECYCLE
SOLUO?
http://balusc.blogspot.com /2006/09/debug-jsf-lifecycle.html
Concluindo..
Perguntas?
Obrigado!
twitter.com/rponte twitter.com/tarsobessa