[jboss-user] [JBoss Seam] - commandLink not initially executing action when clicked
sjmenden
do-not-reply at jboss.com
Thu Aug 3 13:43:58 EDT 2006
I have a page which allows me to search for registered users to a site.
The part of the page I have a problem with is as follows, page: showUsers.jsp which makes calls to an EJB3 called userFinder
| <h:commandLink value="S" action="#{userFinder.findFirstPage}" styleClass="alpha_list">
| <f:param name="start" value="S"/>
| </h:commandLink>
|
Here is the problem. When I initially hit the showUsers.jsp page and click on the link defined above, the page refreshes but nothing happens on the page or in the console output.
HOWEVER, if I first search for a user (code not shown) THEN I click the link above, then it works and shows me all users starting with the letter S.
It seems like something contexual, but I don't understand why the #{userFinder.findFirstPage} action isn't working on the commandLink before I search for something.
| @Name("userFinder")
| @Stateful
| @Scope(ScopeType.SESSION)
| public class UserFinderBean implements UserFinder {
|
| private User example = new User();
| public User getExample() {
| return example;
| }
|
|
| private String[] searchColumns;
| public String[] getSearchColumns() {
| return searchColumns;
| }
| public void setSearchColumns(String[] searchColumns) {
| this.searchColumns = searchColumns;
| }
|
|
| private SelectItem[] searchColumnItems = new SelectItem[] {
| new SelectItem("username", "Username"),
| new SelectItem("firstName", "First"),
| new SelectItem("lastName", "Last"),
| new SelectItem("company", "Company"),
| new SelectItem("email", "Email")
| };
| public SelectItem[] getSearchColumnItems() {
| return searchColumnItems;
| }
|
| private int pageNumber = 0;
| private int pageSize = 15;
| public void setPageSize(int size) {
| pageSize = size;
| }
| public int getPageSize() {
| return pageSize;
| }
|
| public boolean isPreviousPage() {
| return userList!=null && pageNumber>0;
| }
| public boolean isNextPage() {
| return userList!=null && userList.size()==pageSize;
| }
|
| @Logger
| private Log log;
|
| @DataModel
| private List<User> userList;
|
| @DataModelSelection
| private User selectedUser;
|
| @PersistenceContext
| private EntityManager entityManager;
|
| private void executeQuery() {
| Map<String, Object> parameters = new HashMap<String, Object>();
| StringBuffer queryString = new StringBuffer();
|
| log.info("searchColumns: " + Arrays.asList(searchColumns));
|
|
| //*******************************************************//
| // Handle case when a user clicks on a letter
| //*******************************************************//
| if(start != null && !start.equals("")) {
| queryString.append(" or user.username" + " like :value or user.username like :valuetwo ");
| parameters.put("value", start + "%");
| parameters.put("valuetwo", start.toLowerCase() + "%");
| }
|
|
| // if(example.getUsername() != null ) {
| // if(example.getUsername().contains("%")) {
| // queryString.append(" and user.username like :username");
| // } else {
| // queryString.append(" and user.username = :username");
| // }
| // parameters.put( "username", example.getUsername() );
| // }
|
| if(example.getUsername() != null ) {
| int x = 0;
| for(String searchColumn : searchColumns) {
| if(example.getUsername().contains("%")) {
| queryString.append(" or user." + searchColumn + " like :" + searchColumn);
| } else {
| queryString.append(" or user." + searchColumn + " = :" + searchColumn);
| }
| parameters.put( searchColumn, example.getUsername() );
| x++;
| }
| }
|
| if(queryString.length() == 0) {
| queryString.append("select user from User user");
| } else {
| queryString.delete(0, 3).insert(0, "select user from User user where ");
| }
|
| if(order!=null) {
| queryString.append(" order by user.").append(order);
| if (descending) queryString.append(" desc");
| }
|
|
| // Properties of a JavaBean can be bound to named query parameters:
| //
| // Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size");
| // q.setProperties(fooBean); // fooBean has getName() and getSize()
| // List foos = q.list();
|
| log.info("example.username: " + example.getUsername() + " queryString: \n\n" + queryString + "\n\n");
|
| Query query = entityManager.createQuery(queryString.toString());
| for (Entry <String, Object> param : parameters.entrySet()) {
| query.setParameter( param.getKey(), param.getValue() );
| }
| userList = (List<User>) query.setMaxResults(pageSize)
| .setFirstResult(pageSize*pageNumber)
| .getResultList();
| }
|
| public String findFirstPage() {
| log.info("Find First Page");
| pageNumber=0;
| executeQuery();
| return null;
| }
|
| public String findNextPage() {
| pageNumber++;
| executeQuery();
| return null;
| }
|
| public String findPreviousPage() {
| pageNumber--;
| executeQuery();
| return null;
| }
|
| public void refresh() {
| if (userList!=null) executeQuery();
| }
|
| public String clear() {
| userList=null;
| example = new User();
| return null;
| }
|
| public User getSelection() {
| return entityManager.merge( selectedUser );
| }
|
| @Destroy @Remove
| public void destroy() {}
|
| private String order;
| private boolean descending = false;
|
| @RequestParameter
| private String orderBy;
|
| @RequestParameter
| private String start;
|
| public String reorder() {
| if (orderBy.equals(order)) {
| descending = !descending;
| }
| else {
| descending = false;
| }
| order = orderBy;
| executeQuery();
| return null;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962954#3962954
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962954
More information about the jboss-user
mailing list