- 浏览: 104279 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
chifanbua:
我基本上在iteye上很少留言的 不过你的这个写的确实不错 用 ...
Oracle decode函数说明 -
shaoxuexue86:
谢谢啊
RMI 开发步骤 -
huxiaojun_198213:
RMIRegistHelper只是负责注册远程对象,与客户端所 ...
RMI 开发步骤 -
shaoxuexue86:
请问客户端程序ClientTest 与 RMIRegistHe ...
RMI 开发步骤 -
huxiaojun_198213:
本章节可能有一些细节方面翻译得不是很好,有出入的地方,还请各 ...
RMI动态类加载
Full Web Application Tomcat JSF Primefaces JPA Hibernate – Part 2
- 博客分类:
- JSF
Full Web Application Tomcat JSF Primefaces JPA Hibernate – Part 2
This post continues from part 1 of this tutorial.
In the “com.mb” package you will need to create the classes bellow:
About the above code:
■All ManagedBeans are responsible only for the VIEW actions; the ManagedBeans should be responsible to handle the only outcome of the business methods. There are no business rules in the ManagedBeans. It is very easy to do some business actions in the view layer but is not a good practice.
■The LoginMB class uses another ManagedBean (UserMB) there were injected inside of it. To inject a ManagedBean inside another ManagedBean you must do as bellow:■Uses the @ManagedProperty on the top of the injected ManagedBean
■Create a set method to the property like “loginMB.setUserMB(…)“
■The PersonMB class could receive refactoring actions because it is too big. The PersonMB is like that to make easer for rookie developers to understand the code faster.
Observations about @ViewScoped
You will see in the managed beans with the @ViewScoped annotation some reload and reset methods. Both methods are required to reset the objects state; e.g. a dog object would hold values from the view after a method execution (persist in the database, display values in a dialog). If the user open de create dialog and successfully create a dog this dog object will hold all values while the user stays in the same page. If the user opens the create dialog again all the data of the last recorded dog will be displayed there. That is why we have the reset methods.
If you update an object in the database the object in the user view must receive this update too, the ManagedBean objects must receive this new data. If you updated a dog name in the database the list of dog should receive this updated dog too. You can query this new data in the database or just update the managed bean values.
A developer must be aware of:
■Reload the managed bean data querying the database (the reload methods): if the fired query to reload the ManagedBean object comes with a huge amount of data his query may affect the application performance. A developer could use a datatable with lazy load. Click here to see more about Lazy Datatable.
■Reload the updated object directly in the managed bean without querying the database: imagine that the user1 updates the dog1 name in the database and at the same time user2 updates the dog2 age. The user1 will see the old data about the dog2 that could cause a database integrity issue if the user1 updates the dog2. A solution to this approach could be a version field in the database table. Before the update takes place this field would be checked. If the version field does not hold the same value found in the database an exception could be raised. With this approach if the user1 updates the dog2 the version value would not be the same.
JSFMessageUtil
In the package “com.util” create the class bellow:
This class will handle all JSF Messages that will be displayed to the user. This class will help our ManagedBeans to lose coupling between the classes.
It is also a good idea to create a class to handle the dialogs actions.
Configurations file
In the source “src” folder create the following files:
“log4.properties”
“messages.properties”
Take a look at the “lo4j.properties” the line #log4j.logger.org.hibernate.type=TRACE is commented. If you want to see the created query by the Hibernate you need to edit other configurations of the file from ERROR to DEBUG and remove the # from the line above.
You will be able to see the Hibernate executed query and its parameters.
xhtml Pages, Facelets
Let us see how to apply Facelets to a project. Create the files bellow inside the folder “/WebContent/pages/protected/templates/”:
“left.xhtml”
“master.xhtml”
“top.xhtml”
The above code will be the base for all the xhtml pages of the application. It is very important to apply the Facelets pattern to re-use the xhtml code. Bellow you can see how to apply Facelets in the xhtml page, notice that the developer just need to overwrite the desired section:
from:http://www.javacodegeeks.com/2012/07/full-web-application-tomcat-jsf_04.html
This post continues from part 1 of this tutorial.
In the “com.mb” package you will need to create the classes bellow:
package com.mb; import org.primefaces.context.RequestContext; import com.util.JSFMessageUtil; public class AbstractMB { private static final String KEEP_DIALOG_OPENED = 'KEEP_DIALOG_OPENED'; public AbstractMB() { super(); } protected void displayErrorMessageToUser(String message) { JSFMessageUtil messageUtil = new JSFMessageUtil(); messageUtil.sendErrorMessageToUser(message); } protected void displayInfoMessageToUser(String message) { JSFMessageUtil messageUtil = new JSFMessageUtil(); messageUtil.sendInfoMessageToUser(message); } protected void closeDialog(){ getRequestContext().addCallbackParam(KEEP_DIALOG_OPENED, false); } protected void keepDialogOpen(){ getRequestContext().addCallbackParam(KEEP_DIALOG_OPENED, true); } protected RequestContext getRequestContext(){ return RequestContext.getCurrentInstance(); } }
package com.mb; import java.io.Serializable; import java.util.List; import javax.faces.bean.*; import com.facade.DogFacade; import com.model.Dog; @ViewScoped @ManagedBean public class DogMB extends AbstractMB implements Serializable { private static final long serialVersionUID = 1L; private Dog dog; private List<Dog> dogs; private DogFacade dogFacade; public DogFacade getDogFacade() { if (dogFacade == null) { dogFacade = new DogFacade(); } return dogFacade; } public Dog getDog() { if (dog == null) { dog = new Dog(); } return dog; } public void setDog(Dog dog) { this.dog = dog; } public void createDog() { try { getDogFacade().createDog(dog); closeDialog(); displayInfoMessageToUser('Created With Sucess'); loadDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void updateDog() { try { getDogFacade().updateDog(dog); closeDialog(); displayInfoMessageToUser('Updated With Sucess'); loadDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void deleteDog() { try { getDogFacade().deleteDog(dog); closeDialog(); displayInfoMessageToUser('Deleted With Sucess'); loadDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public List<Dog> getAllDogs() { if (dogs == null) { loadDogs(); } return dogs; } private void loadDogs() { dogs = getDogFacade().listAll(); } public void resetDog() { dog = new Dog(); } }
package com.mb; import java.io.Serializable; import javax.faces.bean.*; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; import com.model.User; @SessionScoped @ManagedBean(name='userMB') public class UserMB implements Serializable { public static final String INJECTION_NAME = '#{userMB}'; private static final long serialVersionUID = 1L; private User user; public boolean isAdmin() { return user.isAdmin(); } public boolean isDefaultUser() { return user.isUser(); } public String logOut() { getRequest().getSession().invalidate(); return '/pages/public/login.xhtml'; } private HttpServletRequest getRequest() { return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); } public User getUser() { return user; } public void setUser(User user) { this.user = user; } }
package com.mb; import java.io.Serializable; import java.util.*; import javax.faces.bean.*; import com.facade.*; import com.model.*; import com.sun.faces.context.flash.ELFlash; @ViewScoped @ManagedBean public class PersonMB extends AbstractMB implements Serializable { private static final long serialVersionUID = 1L; private static final String SELECTED_PERSON = 'selectedPerson'; private Dog dog; private Person person; private Person personWithDogs; private Person personWithDogsForDetail; private List<Dog> allDogs; private List<Person> persons; private DogFacade dogFacade; private PersonFacade personFacade; public void createPerson() { try { getPersonFacade().createPerson(person); closeDialog(); displayInfoMessageToUser('Created With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void updatePerson() { try { getPersonFacade().updatePerson(person); closeDialog(); displayInfoMessageToUser('Updated With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void deletePerson() { try { getPersonFacade().deletePerson(person); closeDialog(); displayInfoMessageToUser('Deleted With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void addDogToPerson() { try { getPersonFacade().addDogToPerson(dog.getId(), personWithDogs.getId()); closeDialog(); displayInfoMessageToUser('Added With Sucess'); reloadPersonWithDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void removeDogFromPerson() { try { getPersonFacade().removeDogFromPerson(dog.getId(), personWithDogs.getId()); closeDialog(); displayInfoMessageToUser('Removed With Sucess'); reloadPersonWithDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public Person getPersonWithDogs() { if (personWithDogs == null) { if (person == null) { person = (Person) ELFlash.getFlash().get(SELECTED_PERSON); } personWithDogs = getPersonFacade().findPersonWithAllDogs(person.getId()); } return personWithDogs; } public void setPersonWithDogsForDetail(Person person) { personWithDogsForDetail = getPersonFacade().findPersonWithAllDogs(person.getId()); } public Person getPersonWithDogsForDetail() { if (personWithDogsForDetail == null) { personWithDogsForDetail = new Person(); personWithDogsForDetail.setDogs(new ArrayList<Dog>()); } return personWithDogsForDetail; } public void resetPersonWithDogsForDetail(){ personWithDogsForDetail = new Person(); } public String editPersonDogs() { ELFlash.getFlash().put(SELECTED_PERSON, person); return '/pages/protected/defaultUser/personDogs/personDogs.xhtml'; } public List<Dog> complete(String name) { List<Dog> queryResult = new ArrayList<Dog>(); if (allDogs == null) { dogFacade = new DogFacade(); allDogs = dogFacade.listAll(); } allDogs.removeAll(personWithDogs.getDogs()); for (Dog dog : allDogs) { if (dog.getName().toLowerCase().contains(name.toLowerCase())) { queryResult.add(dog); } } return queryResult; } public PersonFacade getPersonFacade() { if (personFacade == null) { personFacade = new PersonFacade(); } return personFacade; } public Person getPerson() { if (person == null) { person = new Person(); } return person; } public void setPerson(Person person) { this.person = person; } public List<Person> getAllPersons() { if (persons == null) { loadPersons(); } return persons; } private void loadPersons() { persons = getPersonFacade().listAll(); } public void resetPerson() { person = new Person(); } public Dog getDog() { if (dog == null) { dog = new Dog(); } return dog; } public void setDog(Dog dog) { this.dog = dog; } public void resetDog() { dog = new Dog(); } private void reloadPersonWithDogs() { personWithDogs = getPersonFacade().findPersonWithAllDogs(person.getId()); } }
package com.mb; import java.io.Serializable; import java.util.*; import javax.faces.bean.*; import com.facade.*; import com.model.*; import com.sun.faces.context.flash.ELFlash; @ViewScoped @ManagedBean public class PersonMB extends AbstractMB implements Serializable { private static final long serialVersionUID = 1L; private static final String SELECTED_PERSON = 'selectedPerson'; private Dog dog; private Person person; private Person personWithDogs; private Person personWithDogsForDetail; private List<Dog> allDogs; private List<Person> persons; private DogFacade dogFacade; private PersonFacade personFacade; public void createPerson() { try { getPersonFacade().createPerson(person); closeDialog(); displayInfoMessageToUser('Created With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void updatePerson() { try { getPersonFacade().updatePerson(person); closeDialog(); displayInfoMessageToUser('Updated With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void deletePerson() { try { getPersonFacade().deletePerson(person); closeDialog(); displayInfoMessageToUser('Deleted With Sucess'); loadPersons(); resetPerson(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void addDogToPerson() { try { getPersonFacade().addDogToPerson(dog.getId(), personWithDogs.getId()); closeDialog(); displayInfoMessageToUser('Added With Sucess'); reloadPersonWithDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public void removeDogFromPerson() { try { getPersonFacade().removeDogFromPerson(dog.getId(), personWithDogs.getId()); closeDialog(); displayInfoMessageToUser('Removed With Sucess'); reloadPersonWithDogs(); resetDog(); } catch (Exception e) { keepDialogOpen(); displayErrorMessageToUser('Ops, we could not create. Try again later'); e.printStackTrace(); } } public Person getPersonWithDogs() { if (personWithDogs == null) { if (person == null) { person = (Person) ELFlash.getFlash().get(SELECTED_PERSON); } personWithDogs = getPersonFacade().findPersonWithAllDogs(person.getId()); } return personWithDogs; } public void setPersonWithDogsForDetail(Person person) { personWithDogsForDetail = getPersonFacade().findPersonWithAllDogs(person.getId()); } public Person getPersonWithDogsForDetail() { if (personWithDogsForDetail == null) { personWithDogsForDetail = new Person(); personWithDogsForDetail.setDogs(new ArrayList<Dog>()); } return personWithDogsForDetail; } public void resetPersonWithDogsForDetail(){ personWithDogsForDetail = new Person(); } public String editPersonDogs() { ELFlash.getFlash().put(SELECTED_PERSON, person); return '/pages/protected/defaultUser/personDogs/personDogs.xhtml'; } public List<Dog> complete(String name) { List<Dog> queryResult = new ArrayList<Dog>(); if (allDogs == null) { dogFacade = new DogFacade(); allDogs = dogFacade.listAll(); } allDogs.removeAll(personWithDogs.getDogs()); for (Dog dog : allDogs) { if (dog.getName().toLowerCase().contains(name.toLowerCase())) { queryResult.add(dog); } } return queryResult; } public PersonFacade getPersonFacade() { if (personFacade == null) { personFacade = new PersonFacade(); } return personFacade; } public Person getPerson() { if (person == null) { person = new Person(); } return person; } public void setPerson(Person person) { this.person = person; } public List<Person> getAllPersons() { if (persons == null) { loadPersons(); } return persons; } private void loadPersons() { persons = getPersonFacade().listAll(); } public void resetPerson() { person = new Person(); } public Dog getDog() { if (dog == null) { dog = new Dog(); } return dog; } public void setDog(Dog dog) { this.dog = dog; } public void resetDog() { dog = new Dog(); } private void reloadPersonWithDogs() { personWithDogs = getPersonFacade().findPersonWithAllDogs(person.getId()); } }
package com.mb; import javax.faces.bean.*; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; import com.facade.UserFacade; import com.model.User; @RequestScoped @ManagedBean public class LoginMB extends AbstractMB { @ManagedProperty(value = UserMB.INJECTION_NAME) private UserMB userMB; private String email; private String password; public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String login() { UserFacade userFacade = new UserFacade(); User user = userFacade.isValidLogin(email, password); if(user != null){ userMB.setUser(user); FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); request.getSession().setAttribute('user', user); return '/pages/protected/index.xhtml'; } displayErrorMessageToUser('Check your email/password'); return null; } public void setUserMB(UserMB userMB) { this.userMB = userMB; } }
About the above code:
■All ManagedBeans are responsible only for the VIEW actions; the ManagedBeans should be responsible to handle the only outcome of the business methods. There are no business rules in the ManagedBeans. It is very easy to do some business actions in the view layer but is not a good practice.
■The LoginMB class uses another ManagedBean (UserMB) there were injected inside of it. To inject a ManagedBean inside another ManagedBean you must do as bellow:■Uses the @ManagedProperty on the top of the injected ManagedBean
■Create a set method to the property like “loginMB.setUserMB(…)“
■The PersonMB class could receive refactoring actions because it is too big. The PersonMB is like that to make easer for rookie developers to understand the code faster.
Observations about @ViewScoped
You will see in the managed beans with the @ViewScoped annotation some reload and reset methods. Both methods are required to reset the objects state; e.g. a dog object would hold values from the view after a method execution (persist in the database, display values in a dialog). If the user open de create dialog and successfully create a dog this dog object will hold all values while the user stays in the same page. If the user opens the create dialog again all the data of the last recorded dog will be displayed there. That is why we have the reset methods.
If you update an object in the database the object in the user view must receive this update too, the ManagedBean objects must receive this new data. If you updated a dog name in the database the list of dog should receive this updated dog too. You can query this new data in the database or just update the managed bean values.
A developer must be aware of:
■Reload the managed bean data querying the database (the reload methods): if the fired query to reload the ManagedBean object comes with a huge amount of data his query may affect the application performance. A developer could use a datatable with lazy load. Click here to see more about Lazy Datatable.
■Reload the updated object directly in the managed bean without querying the database: imagine that the user1 updates the dog1 name in the database and at the same time user2 updates the dog2 age. The user1 will see the old data about the dog2 that could cause a database integrity issue if the user1 updates the dog2. A solution to this approach could be a version field in the database table. Before the update takes place this field would be checked. If the version field does not hold the same value found in the database an exception could be raised. With this approach if the user1 updates the dog2 the version value would not be the same.
JSFMessageUtil
In the package “com.util” create the class bellow:
package com.util; import javax.faces.application.FacesMessage; import javax.faces.application.FacesMessage.Severity; import javax.faces.context.FacesContext; public class JSFMessageUtil { public void sendInfoMessageToUser(String message) { FacesMessage facesMessage = createMessage(FacesMessage.SEVERITY_INFO, message); addMessageToJsfContext(facesMessage); } public void sendErrorMessageToUser(String message) { FacesMessage facesMessage = createMessage(FacesMessage.SEVERITY_WARN, message); addMessageToJsfContext(facesMessage); } private FacesMessage createMessage(Severity severity, String mensagemErro) { return new FacesMessage(severity, mensagemErro, mensagemErro); } private void addMessageToJsfContext(FacesMessage facesMessage) { FacesContext.getCurrentInstance().addMessage(null, facesMessage); } }
This class will handle all JSF Messages that will be displayed to the user. This class will help our ManagedBeans to lose coupling between the classes.
It is also a good idea to create a class to handle the dialogs actions.
Configurations file
In the source “src” folder create the following files:
“log4.properties”
# Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n # Root logger option log4j.rootLogger=ERROR, stdout # Hibernate logging options (INFO only shows startup messages) log4j.logger.org.hibernate=ERROR # Log JDBC bind parameter runtime arguments #log4j.logger.org.hibernate.type=TRACE
“messages.properties”
#Actions welcomeMessage=Hello! Show me the best soccer team logo ever update=Update create=Create delete=Delete cancel=Cancel detail=Detail logIn=Log In add=Add remove=Remove ok=Ok logOut= Log Out javax.faces.component.UIInput.REQUIRED={0}: is empty. Please, provide some value javax.faces.validator.LengthValidator.MINIMUM={1}: Length is less than allowable minimum of u2018u2019{0}u2019u2019 noRecords=No data to display deleteRecord=Do you want do delete the record #Login / Roles Validations loginHello=Login to access secure pages loginUserName=Username loginPassword=Password logout=Log Out loginWelcomeMessage=Welcome accessDeniedHeader=Wow, our ninja cat found you! accessDeniedText=Sorry but you can not access that page. If you try again, that ninja cat gonna kick you harder! >= ) accessDeniedButton=You got-me, take me out. =/ #Person person=Person personPlural=Persons personName=Name personAge=Age personDogs=These dogs belongs to personAddDogTo=Add the selected Dog To personRemoveDogFrom=Remove the selected Dog from personEditDogs=Edit Dogs #Dog dog=Dog dogPlural=Dogs dogName=Name dogAge=Age
Take a look at the “lo4j.properties” the line #log4j.logger.org.hibernate.type=TRACE is commented. If you want to see the created query by the Hibernate you need to edit other configurations of the file from ERROR to DEBUG and remove the # from the line above.
You will be able to see the Hibernate executed query and its parameters.
xhtml Pages, Facelets
Let us see how to apply Facelets to a project. Create the files bellow inside the folder “/WebContent/pages/protected/templates/”:
“left.xhtml”
<!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:ui='http://java.sun.com/jsf/facelets' xmlns:h='http://java.sun.com/jsf/html' xmlns:p='http://primefaces.org/ui'> <h:body> <ui:composition> <h:form> <p:commandButton styleClass='menuButton' icon='ui-icon-arrowstop-1-e' rendered='#{userMB.admin or userMB.defaultUser}' action='/pages/protected/defaultUser/defaultUserIndex.xhtml' value='#{bundle.personPlural}' ajax='false' immediate='true' /> <br /> <p:commandButton styleClass='menuButton' icon='ui-icon-arrowstop-1-e' rendered='#{userMB.admin}' action='/pages/protected/admin/adminIndex.xhtml' value='#{bundle.dogPlural}' ajax='false' immediate='true' /> <br /> </h:form> </ui:composition> </h:body> </html>
“master.xhtml”
<?xml version='1.0' encoding='UTF-8' ?> <!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:ui='http://java.sun.com/jsf/facelets' xmlns:h='http://java.sun.com/jsf/html' xmlns:p='http://primefaces.org/ui' xmlns:f='http://java.sun.com/jsf/core'> <h:head> <title>CrudJSF</title> <h:outputStylesheet library='css' name='main.css' /> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> </h:head> <h:body> <f:view contentType='text/html; charset=UTF-8' encoding='UTF-8' > <div id='divTop' style='vertical-align: middle;'> <ui:insert name='divTop'> <ui:include src='top.xhtml' /> </ui:insert> </div> <div id='divLeft'> <ui:insert name='divLeft'> <ui:include src='left.xhtml' /> </ui:insert> </div> <div id='divMain'> <p:growl id='messageGrowl' /> <ui:insert name='divMain' /> </div> <h:outputScript library='javascript' name='jscodes.js' /> </f:view> </h:body> </html>
“top.xhtml”
<!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:ui='http://java.sun.com/jsf/facelets' xmlns:h='http://java.sun.com/jsf/html' xmlns:p='http://primefaces.org/ui'> <h:body> <ui:composition> <div id='topMessage'> <h1> <h:form> #{bundle.loginWelcomeMessage}: #{userMB.user.name} | <p:commandButton value='#{bundle.logOut}' action='#{userMB.logOut()}' ajax='false' style='font-size: 20px;' /> </h:form> </h1> </div> </ui:composition> </h:body> </html>
The above code will be the base for all the xhtml pages of the application. It is very important to apply the Facelets pattern to re-use the xhtml code. Bellow you can see how to apply Facelets in the xhtml page, notice that the developer just need to overwrite the desired section:
<!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:ui='http://java.sun.com/jsf/facelets' xmlns:h='http://java.sun.com/jsf/html' xmlns:f='http://java.sun.com/jsf/core' xmlns:p='http://primefaces.org/ui' > <h:body> <ui:composition template='/pages/protected/templates/master.xhtml'> <ui:define name='divMain'> #{bundle.welcomeMessage} :<br/> <h:graphicImage library='images' name='logoReal.png' /> </ui:define> </ui:composition> </h:body> </html>
from:http://www.javacodegeeks.com/2012/07/full-web-application-tomcat-jsf_04.html
发表评论
-
jsf+spring
2012-12-05 01:52 789附件为spring+jsf整合 -
JSF2 + Primefaces3 + Spring3 & Hibernate4 Integration Project
2012-12-05 01:04 1644This article shows how to integ ... -
JSF 2 + Spring 3 integration example
2012-12-05 00:41 1679In this tutorial, we will show ... -
primefaces cook book 源代码分享
2012-11-23 02:30 1388primefaces cook book 源代码分享 -
Full Web Application Tomcat JSF Primefaces JPA Hibernate – Part 1
2012-11-19 23:20 2600Full Web Application Tomcat JSF ... -
Lazy JSF Primefaces Datatable Pagination – Part 2
2012-11-18 19:19 1504Lazy JSF Primefaces Datatable P ... -
Lazy JSF Primefaces Datatable Pagination – Part 1
2012-11-18 19:12 1590Lazy JSF Primefaces Datatable P ...
相关推荐
Java Web JSF + Richfaces + EJB + JPA 航空订票系统是一个综合性的应用,涵盖了多种Java技术,用于构建高效的、可扩展的、易于维护的Web应用程序。在这个系统中,每项技术都有其特定的角色和功能,共同协作以实现...
在本文档中,我们将探讨如何将JavaServer Faces (JSF),Java Persistence API (JPA) 和 Spring 框架整合到一个项目中。这通常是为了构建一个完整的MVC(模型-视图-控制器)架构的应用程序,其中JSF处理用户界面,JPA...
【标题】"jsf2+primefaces+spring+hibernate案例"揭示了一个基于Java的全栈Web开发项目,它整合了几个关键的技术框架。JSF(JavaServer Faces)是Oracle公司推出的Java Web应用程序开发框架,用于构建用户界面。...
【标题】"jsf2(primefaces3)+spring+hibernate案例下载"涉及到的是一个集成开发环境,其中包含了JavaScript Server Faces (JSF) 2.0版本、PrimeFaces 3.0 UI库、Spring框架以及Hibernate ORM工具。这个案例提供了...
标题 "primefaces jsf spring3.2.4 hibernate4.2.7 maven整合" 涉及到的是一个基于Java技术栈的Web应用程序开发整合。以下是这些技术的详细说明: **PrimeFaces**:PrimeFaces是一个开源的用户界面组件库,专为Java...
Jpa spring jsf primefaces 环境最小配置
EJB+JSF+JPA全JAVAEE视频教程,EJB+JSF+JPA入门觉得有点难吗?JBOSS报错?该教程全程教你学习搭建EJB+JSF+JPA框架!!!
在本文中,我们将深入探讨如何使用Netbeans IDE进行JSF 2.0的开发,并结合Primefaces和JPA来创建高效、用户友好的Web应用程序。JSF(JavaServer Faces)是一种用于构建Java Web应用程序的MVC(模型-视图-控制器)...
TryHeroku 1-运行将其粘贴到您的java -jar目标/依赖项/ webapp-runner.jar目标/ *。... 执行C:\ Projects \ java \ maven-jsf-primefaces-heroku> java -jar目标/依赖关系/ webapp-runner.jar目标/ *。战争
PrimeFaces是一个流行的Java库,提供了丰富的UI组件,使得开发高质量的Web应用程序变得更加便捷。 首先,JSF是一个用于构建MVC(模型-视图-控制器)结构的Java EE框架,它允许开发者创建动态、交互式的Web应用。JSF...
总结,JSF PrimeFaces的`DataTable`是一个强大而灵活的组件,结合Spring框架,可以构建出高效、易于维护的Web应用。在`jsfDemo`项目中,我们可以通过`HelloJSF`了解并实践这些概念,从而更好地理解和掌握JSF ...
**JSF(JavaServer Faces)** 是Java平台上的一种用于构建用户界面的Web应用程序框架,它简化了开发人员创建和管理动态Web用户界面的过程。JSF提供了组件库、事件处理机制和生命周期管理,允许开发者通过声明式的...
### JSF+JPA+CDI 框架详解 #### 一、技术介绍 ##### Java Java 是一种被广泛使用的编程语言,以其强大的跨平台能力、丰富的类库支持及良好的安全性能受到开发者们的青睐。Java 可以应用于各种场景,如 Web 应用...
而Primefaces是JSF的一个热门扩展库,提供了丰富的UI组件和强大的功能,使得开发者能够创建更加美观、交互性强的Web应用。本教程将深入讲解如何使用JSF Primefaces进行开发。 **1. JSF基础知识** - **JSF架构**:...
**JSF2 + Primefaces3 + Spring3 & Hibernate4 集成项目详解** JavaScript Framework (JSF) 是Java平台上的一种用于构建用户界面的MVC(Model-View-Controller)框架,而Primefaces是一个基于JSF的开源UI组件库,...
这个平台包含了多个组件和服务,如Servlet、JSP(JavaServer Pages)、EJB(Enterprise JavaBeans)、JMS(Java Message Service)、JPA(Java Persistence API)以及Web服务等。JavaEE的目标是简化开发、提供可扩展...
**JSF、PrimeFaces与Hibernate CRUD操作详解** JavaServer Faces(JSF)是Java平台上的一个用于构建用户界面的Web应用程序框架,它提供了一种组件化的方式来创建动态、交互式的Web应用。PrimeFaces是一个非常流行的...
在构建企业级Java应用时,JSF(JavaServer Faces)、Spring和JPA(Java Persistence API,通常通过Hibernate实现)是一个常见的技术栈。这篇文档主要介绍了如何整合这些技术来搭建一个开发环境。 首先,JSF是一种...
**JSF(JavaServer Faces)**是Java平台上用于构建用户界面的一种组件模型框架,它简化了Web应用程序的开发。JSF提供了一种声明式的方式来创建用户界面,允许开发者通过拖拽组件并配置属性来构建页面,而不是直接...
这是jsf+spring2.5+jpa(hibernate)的jar包,很多人为了jsj环境而配置半天,在此提供jar包共享。注:除了ajax4jsf和tomahawk-1.1.3.jar,因为csdn只让我上传20mb,大家自己可以下一下自己试试。