[jboss-user] [JBoss Seam] - Re: commandLink not initially executing action when clicked
sjmenden
do-not-reply at jboss.com
Thu Aug 3 17:10:58 EDT 2006
Below is the showUsers.jsp.
What I want to use is allow the user to click on the R or the S and for that to bind to the userFinder.findFirstPage which will look for the start variable which is set to R or S and find all users that start with and R or S and return the list.
As I said before, when going to the page for the first time, the link will just refresh the page and do nothing and no output, however, if I first search for a user, then I click on the R or the S links, then it all works.
showUsers.jsp:
| <h:form>
| <table>
| <tr >
| <td><h2>Users</h2></td>
| </tr>
| <div>
| <table>
| <tr>
| <td align="left">
| ...
| ...
| ...
| <h:commandLink value="R" action="#{userFinder.findFirstPage}">
| <f:param name="start" value="R"/>
| </h:commandLink>
| <h:commandLink value="S" action="#{userFinder.findFirstPage}">
| <f:param name="start" value="S"/>
| </h:commandLink>
| ...
| ...
| ...
| </td>
| </tr>
| </table>
| </div>
| <table>
| <tr>
| <td colspan="5">
| <div>
| <div>
| <div>
| <div>
| <span>User:</span>
| <h:inputText value="#{userFinder.example.username}" size="15" required="true"/>
| <h:commandButton type="submit" value="Search" action="#{userFinder.findFirstPage}"/>
| </div>
| <br />
| <h:selectManyCheckbox
| value="#{userFinder.searchColumns}"
| layout="lineDirection"
| required="true">
| <f:selectItems value="#{userFinder.searchColumnItems}" />
| </h:selectManyCheckbox>
| <br />
| <span>(for wildcard search use %)</span>
| </div>
| </div>
| </div>
| </td>
| </tr>
| </table>
|
| <h:dataTable value="#{userList}" var="user" rendered="#{userList.rowCount > 0}">
| <h:column>
| <f:facet name="header">
| <h:commandLink value="Username" action="#{userFinder.reorder}">
| <f:param name="orderBy" value="username"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{user.username}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">
| <h:commandLink value="Company" action="#{userFinder.reorder}">
| <f:param name="orderBy" value="company"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{user.company}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">
| <h:outputText value="Name"/>
| </f:facet>
| <h:outputText value="#{user.firstName} #{user.lastName}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">
| <h:commandLink value="Email Address" action="#{userFinder.reorder}">
| <f:param name="orderBy" value="email"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{user.email}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">
| <h:commandLink value="Active" action="#{userFinder.reorder}">
| <f:param name="orderBy" value="active"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{user.active}"/>
| </h:column>
| </h:dataTable>
|
| <h:commandButton action="#{userFinder.findPreviousPage}" value="Previous Page" disabled="#{!userFinder.previousPage}" />
| <h:commandButton action="#{userFinder.findNextPage}" value="Next Page" disabled="#{!userFinder.nextPage}" />
| </h:form>
|
Here is my UserFinderBean with only the relevant information to this question. If you want to see the full code, see my previous post.
| @Name("userFinder")
| @Stateful
| @Scope(ScopeType.SESSION)
| public class UserFinderBean implements UserFinder {
|
| @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();
|
| 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() + "%");
| }
|
| 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() {
| executeQuery();
| return null;
| }
|
| @Destroy @Remove
| public void destroy() {}
|
|
| @RequestParameter
| private String start;
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963028#3963028
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963028
More information about the jboss-user
mailing list