"CptnKirk" wrote : 
  | For example I don't think I'd recommend using a Home to populate a search 
prototype.  For search pages, an entity with an event scoped role combined with 
Hibernate's Criteria API + Example criterion is great.
  | 

I prefer exactly the opposite, with a Search conversation scoped component that 
holds my prototype entity during the search conversation. Gives me a lot of 
control over what the user can select on the search screen and how I handle 
this in the backend:


  | @Name("userSearch")
  | @Scope(ScopeType.CONVERSATION)
  | public class UserSearch implements Serializable {
  | 
  |     @In
  |     private UserDAO userDAO;
  | 
  |     @In
  |     private FacesMessages facesMessages;
  | 
  |     private User exampleUser;
  |     private String orderByProperty;
  |     private boolean orderDescending;
  |     private String[] ignoreProperties;
  |     private int rowCount;
  |     private int maxPageSize;
  |     private int pageSize;
  |     private int page;
  | 
  |     @DataModel
  |     private List<User> usersList;
  | 
  |     @Create
  |     public void initialize() {
  |         pageSize = 15;
  |         maxPageSize = 1000;
  |         exampleUser = new User();
  |         orderByProperty = "username";
  |         orderDescending = false;
  |         ignoreProperties = new String[]{"passwordHash", "activated", 
"createdOn"};
  |     }
  | 
  |     public void find() {
  |         page = 0;
  |         queryRowCount();
  |         if (rowCount != 0) queryUsers();
  |     }
  | 
  |     public void nextPage() {
  |         page++;
  |         queryUsers();
  |     }
  | 
  |     public void previousPage() {
  |         page--;
  |         queryUsers();
  |     }
  | 
  |     public void firstPage() {
  |         page = 0;
  |         queryUsers();
  |     }
  | 
  |     public void lastPage() {
  |         page = (rowCount / pageSize);
  |         if (rowCount % pageSize == 0) page--;
  |         queryUsers();
  |     }
  | 
  |     private void queryRowCount() {
  |         rowCount = userDAO.getRowCountByExample(exampleUser, 
ignoreProperties);
  |         if (rowCount == 0) {
  |             facesMessages.addFromResourceBundleOrDefault(
  |                 FacesMessage.SEVERITY_INFO,
  |                 "noUserFound",
  |                 "No user with given attributes was found, please try again."
  |             );
  |         }
  |     }
  | 
  |     private void queryUsers() {
  |         usersList = userDAO.findByExample(exampleUser, orderByProperty, 
orderDescending, page * pageSize, pageSize, ignoreProperties);
  |     }
  | 
  |     public boolean isNextPageAvailable() {
  |         return usersList != null && rowCount > ((page * pageSize) + 
pageSize);
  |     }
  | 
  |     public boolean isPreviousPageAvailable() {
  |         return usersList != null && page > 0;
  |     }
  |     public int getPageSize() {
  |         return pageSize;
  |     }
  | 
  |     public void setPageSize(int pageSize) {
  |         this.pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; // 
Prevent tampering
  |     }
  | 
  |     public int getRowCount() {
  |         return rowCount;
  |     }
  | 
  |     public User getExampleUser() {
  |         return exampleUser;
  |     }
  | 
  |     public void setExampleUser(User exampleUser) {
  |         this.exampleUser = exampleUser;
  |     }
  | 
  |     public String getOrderByProperty() {
  |         return orderByProperty;
  |     }
  | 
  |     public boolean isOrderDescending() {
  |         return orderDescending;
  |     }
  | 
  |     public void sortBy(String propertyName) {
  |         orderByProperty = propertyName;
  |         orderDescending = !isOrderDescending(); // Switch between ASC and 
DESC
  |         page = 0; // Reset to first page
  |         queryUsers();
  |     }
  | 
  | }
  | 

And the UI is bound to userSearch.exampleUser and the various other properties 
and methods for pagination etc.


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4039586#4039586

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4039586
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to