4 Replies Latest reply on Dec 18, 2009 5:05 PM by Jeff Palmer

    Page Parameters Question

    Jeff Palmer Newbie

      I have a search form that allows the user to filter the search results. One of the parameters that they can filter by is bureau, which is defined as an entity in my application. The code for the search looks like such:




      <s:decorate template="layout/display.xhtml">
          <ui:define name="label">Bureau</ui:define>
              <h:selectOneMenu id="bureau" value="#{employeeCriteria.bureau}">
               <s:selectItems var="_bureau" value="#{bureaus}"
                   label="#{_bureau.name}" noSelectionLabel="-- Select --" />
               <s:convertEntity />
               <a:support event="onchange" />
           </h:selectOneMenu>
      </s:decorate>



      The searching and sorting is working fine without a page parameter defined for bureau. When I add a page parameter for bureau (so that I can track what bureau was selected when a column is sorted) and perform a sort on any of the columns, however, I get the following exception: java.lang.IllegalArgumentException: argument type mismatch


      My page parameter for bureau is defined as:


      <param name="bureau" value="#{employeeCriteria.bureau}"/>



      Anyone know how I can fix this?



        • 1. Re: Page Parameters Question
          Aravind Ksr Newbie

          Jeff,


          Make sure that your Bureau Entity has overwritten hashCode and equals methods. Basically when you submit the request bureau page parameter will be created as an entity but you might be expecting it as a String or numeric based on design.


          Since your h:selectOneMenu component id and page parameter name are both same and it might be causing problem. Try to change page parameter name and see how it works.


          Aravind

          • 2. Re: Page Parameters Question
            Jeff Palmer Newbie

            Thanks for the suggestions. Unfortunately I tried both though and am still getting the exception. Am I missing something?

            • 3. Re: Page Parameters Question
              Aravind Ksr Newbie

              Can you post your action class code here? Also, post xhtml or pages.xml code where you are passing page paramter?

              • 4. Re: Page Parameters Question
                Jeff Palmer Newbie

                My action class:



                package org.cityofchicago.water.dma.session;
                
                import java.util.Arrays;
                import java.util.List;
                
                import org.cityofchicago.water.dma.entity.Employee;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.framework.EntityQuery;
                
                @Name("employeeList")
                public class EmployeeList extends EntityQuery<Employee> {
                
                     private static final long serialVersionUID = -6941614394831512670L;
                     
                     private static final String EJBQL = "select e from Employee e join fetch e.bureau b";
                     
                     private static final String[] RESTRICTIONS = {
                          "lower(e.firstName) like concat(lower(#{employeeExample.firstName}),'%')",
                          "lower(e.lastName) like concat(lower(#{employeeExample.lastName}),'%')",
                          "lower(e.positionTitle) like concat(lower(#{employeeExample.positionTitle}),'%')",
                          "b = #{employeeCriteria.bureau}"};
                     
                     private Employee employee = new Employee();
                     
                     public EmployeeList() {
                          setEjbql(EJBQL);
                          setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                          setMaxResults(25);
                          setOrder("e.lastName");
                     }
                     
                     public Employee getEmployee() {
                          return employee;
                     }
                     
                     public List<Employee> autoComplete(Object o) {
                          String sql = EmployeeList.EJBQL + " where lower(e.lastName) like concat(lower('"+o.toString()+"'),'%')";
                          return this.getEntityManager().createQuery(sql).getResultList();   
                     }
                }
                     
                



                My xhtml page:



                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:rich="http://richfaces.org/rich" 
                     xmlns:p="http://primefaces.prime.com.tr/ui"
                    xmlns:a="http://richfaces.org/a4j"
                     template="layout/template.xhtml">
                
                     <ui:define name="tabs">
                          <ul class="tab-list">
                               <li><h:outputLink value="home.seam">Dashboard</h:outputLink></li>
                               <li><h:outputLink value="DmaCaseList.seam">Cases</h:outputLink></li>
                               <li><h:outputLink value="ResolutionList.seam">Resolutions</h:outputLink></li>
                               <li><a href="#content">Employees</a></li>
                               <li><h:outputLink value="ReportList.seam">Reports</h:outputLink></li>
                          </ul>
                
                          <script type="text/javascript">
                        jQuery(document).ready(function(){jQuery('#tabs').tabs({ selected: 3 });});
                        </script>
                     </ui:define>
                
                     <ui:define name="body">
                
                          <div id="content">
                               <h:form id="employeeSearch" styleClass="edit">
                
                                    <rich:simpleTogglePanel label="Employee Search Filter"
                                         switchType="ajax">
                     
                                         <s:decorate template="layout/display.xhtml">
                                              <ui:define name="label">Bureau</ui:define>
                                              <h:selectOneMenu id="bureau" value="#{employeeCriteria.bureau}">
                                                   <s:selectItems var="_bureau" value="#{bureaus}"
                                                        label="#{_bureau.name}" noSelectionLabel="-- Select --" />
                                                   <s:convertEntity />
                                                   <a:support event="onchange" />
                                              </h:selectOneMenu>
                                         </s:decorate>
                     
                                         <s:decorate template="layout/display.xhtml">
                                              <ui:define name="label">First name</ui:define>
                                              <h:inputText id="firstName" value="#{employeeExample.firstName}">
                                                   <a:support event="onkeyup" />
                                              </h:inputText>
                                         </s:decorate>
                     
                                         <s:decorate template="layout/display.xhtml">
                                              <ui:define name="label">Last name</ui:define>
                                              <h:inputText id="lastName" value="#{employeeExample.lastName}">
                                                   <a:support event="onkeyup" />
                                              </h:inputText>
                                         </s:decorate>
                     
                                         <s:decorate template="layout/display.xhtml">
                                              <ui:define name="label">Position title</ui:define>
                                              <h:inputText id="positionTitle"
                                                   value="#{employeeExample.positionTitle}">
                                                   <a:support event="onkeyup" />     
                                              </h:inputText>
                                         </s:decorate>
                     
                                    </rich:simpleTogglePanel>
                     
                                    <div class="actionButtons">
                                         <s:button id="reset" value="Reset" includePageParams="false" />
                                    </div>
                                    
                                    <a:outputPanel ajaxRendered="true" layout="none">
                                         <rich:panel id="searchResultsPanel">
                                              <f:facet name="header">Employee Search Results (#{empty employeeList.resultList ? 0 : (employeeList.paginated ? employeeList.resultCount : employeeList.resultList.size)})</f:facet>
                                              <div class="results" id="employeeList">
                                                   <h:outputText value="The employee search returned no results."
                                                        rendered="#{empty employeeList.resultList}" /> 
                                                        
                                                   <rich:dataTable id="employeeList" var="_employee"
                                                        value="#{employeeList.resultList}"
                                                        rendered="#{not empty employeeList.resultList}">
                                                        <h:column>
                                                             <f:facet name="header">
                                                                  <ui:include src="layout/sort.xhtml">
                                                                       <ui:param name="entityList" value="#{employeeList}" />
                                                                       <ui:param name="propertyLabel" value="Bureau" />
                                                                       <ui:param name="propertyPath" value="b" />
                                                                  </ui:include>
                                                             </f:facet>
                                                             <h:outputText value="#{_employee.bureau.name}" />
                                                        </h:column>
                                                        <h:column>
                                                             <f:facet name="header">
                                                                  <ui:include src="layout/sort.xhtml">
                                                                       <ui:param name="entityList" value="#{employeeList}" />
                                                                       <ui:param name="propertyLabel" value="First name" />
                                                                       <ui:param name="propertyPath" value="e.firstName" />
                                                                  </ui:include>
                                                             </f:facet>
                                                             <h:outputText value="#{_employee.firstName}" />
                                                        </h:column>
                                                        <h:column>
                                                             <f:facet name="header">
                                                                  <ui:include src="layout/sort.xhtml">
                                                                       <ui:param name="entityList" value="#{employeeList}" />
                                                                       <ui:param name="propertyLabel" value="Last name" />
                                                                       <ui:param name="propertyPath" value="e.lastName" />
                                                                  </ui:include>
                                                             </f:facet>
                                                             <h:outputText value="#{_employee.lastName}" />
                                                        </h:column>
                                                        <h:column>
                                                             <f:facet name="header">
                                                                  <ui:include src="layout/sort.xhtml">
                                                                       <ui:param name="entityList" value="#{employeeList}" />
                                                                       <ui:param name="propertyLabel" value="Position title" />
                                                                       <ui:param name="propertyPath" value="e.positionTitle" />
                                                                  </ui:include>
                                                             </f:facet>
                                                             <h:outputText value="#{_employee.positionTitle}" />
                                                        </h:column>
                                                        <rich:column styleClass="action">
                                                             <f:facet name="header">Action</f:facet>
                                                             <s:link view="/#{empty from ? 'Employee' : from}.xhtml"
                                                                  value="#{empty from ? 'View' : 'Select'}"
                                                                  propagation="#{empty from ? 'none' : 'default'}"
                                                                  id="employeeViewId">
                                                                  <f:param name="employeeId" value="#{_employee.id}" />
                                                             </s:link>
                                                          #{' '}
                                                          <s:link view="/EmployeeEdit.xhtml" value="Edit"
                                                                  propagation="none" id="employeeEdit" rendered="#{empty from}">
                                                                  <f:param name="employeeId" value="#{_employee.id}" />
                                                             </s:link>
                                                        </rich:column>
                                                   </rich:dataTable>
                                              </div>
                                         </rich:panel>
                                    
                                         <div class="tableControl">
                                              <s:link view="/EmployeeList.xhtml" rendered="#{employeeList.previousExists}"
                                                   value="#{messages.left}#{messages.left} First Page" id="firstPage">
                                                   <f:param name="firstResult" value="0" />
                                              </s:link> 
                                              <s:link view="/EmployeeList.xhtml" rendered="#{employeeList.previousExists}"
                                                   value="#{messages.left} Previous Page" id="previousPage">
                                                   <f:param name="firstResult" value="#{employeeList.previousFirstResult}" />
                                              </s:link> 
                                              <s:link view="/EmployeeList.xhtml" rendered="#{employeeList.nextExists}"
                                                   value="Next Page #{messages.right}" id="nextPage">
                                                   <f:param name="firstResult" value="#{employeeList.nextFirstResult}" />
                                              </s:link> 
                                              <s:link view="/EmployeeList.xhtml" rendered="#{employeeList.nextExists}"
                                                   value="Last Page #{messages.right}#{messages.right}" id="lastPage">
                                                   <f:param name="firstResult" value="#{employeeList.lastFirstResult}" />
                                              </s:link>
                                         </div>
                                         
                                    </a:outputPanel>
                     
                                    <s:div styleClass="actionButtons" rendered="#{empty from}">
                                         <s:button view="/EmployeeEdit.xhtml" id="create" propagation="none"
                                              value="Create employee">
                                              <f:param name="employeeId" />
                                         </s:button>
                                         <h:commandButton value="PDF Export">
                                              <p:dataExporter type="pdf" target="employeeList" fileName="employees"
                                                   excludeColumns="4"
                                                   preProcessor="#{dataTableExportFormatter.preProcessPDF}"
                                                   postProcessor="#{dataTableExportFormatter.postProcessPDF}" />
                                         </h:commandButton>
                                    </s:div>
                                    
                               </h:form>
                          </div>
                
                     </ui:define>
                
                </ui:composition>



                My pages.xml code:



                <?xml version="1.0" encoding="UTF-8"?>
                <page xmlns="http://jboss.com/products/seam/pages"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"
                      login-required="true">
                
                   <param name="firstResult" value="#{employeeList.firstResult}"/>
                   <param name="sort" value="#{employeeList.orderColumn}"/>
                   <param name="dir" value="#{employeeList.orderDirection}"/>
                   <param name="logic" value="#{employeeList.restrictionLogicOperator}"/>
                
                   <param name="from"/>
                   <param name="bur" value="#{employeeExample.bureau}"/>
                   <param name="firstName" value="#{employeeExample.firstName}"/>
                   <param name="lastName" value="#{employeeExample.lastName}"/>
                   <param name="positionTitle" value="#{employeeExample.positionTitle}"/>
                
                </page>