4 Replies Latest reply on Dec 23, 2009 5:08 PM by jpalmer1026.jpalmer1026.mchsi.com

    Page Parameters Question Take 2

    jpalmer1026.jpalmer1026.mchsi.com

      Sorry to repost a question but I still haven't gotten this resolved. I feel like this is a fairly common use case so I'm hoping someone might be able to assist. To repeat, I have a search form that allows the user to filter search results. One of the parameters that they can filter by is bureau, which is an entity in the 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="#{employeeExample.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="#{employeeExample.bureau}"/>



      Lastly, I have the employeeExample object defined in components.xml like so:


      <component name="employeeExample" class="org.cityofchicago.water.dma.entity.Employee" />





      Anyone know how I can fix this?

        • 1. Re: Page Parameters Question Take 2
          yahawari

          basically page parameters should contain basic types (or their wrappers). for anything other than the basic types u will need to write a converter. for example Date is an object,  seam has a date JSF converter that will allow u to pass it as a page param.


          however for ur scenario, it is easier to just pass the id of the object then fetch it on form submit.

          • 2. Re: Page Parameters Question Take 2
            jpalmer1026.jpalmer1026.mchsi.com

            Thanks for the explanation. Maybe I misunderstood your explanation but I ended up changing my code like so:


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



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



            These changes are resulting in the following error message:


            08:51:36,009 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
            sourceId=employeeSearch:j_id39:bureau[severity=(ERROR 2), summary=(/EmployeeList.xhtml @37,73 value="#{employeeExample.bureau.id}": Target Unreachable, 'bureau' returned null on 'org.cityofchicago.water.dma.entity.Employee'), detail=(/EmployeeList.xhtml @37,73 value="#{employeeExample.bureau.id}": Target Unreachable, 'bureau' returned null on 'org.cityofchicago.water.dma.entity.Employee')]
            



            Am I doing something blatantly wrong?



            • 3. Re: Page Parameters Question Take 2
              mikkus70

              Your form is using <s:convertEntity>, but your backing property seems to be an ID (possibly a Long). The purpose of <s:convertEntity> is that of passing an entity directly, so that your backing property should be an instance of the entity class (so, instead of #{employeeExample.bureau.id}, you would probably want to use #{employeeEXample.bureau}).


              The other thing is that page parameters use converters much like form fields do...


              I've personally grown to dislike entity conversion, at least for simple use cases like these. I find using the entity id as key for the combo is not complicated and makes the code more understandable, so I would just add an itemValue property to the <s:selectItems> tag and remove the <s:convertEntity>. This of course means that you need to load the entity when submitting back the form, but for search screens it is usually sufficient to just filter by the id.


              Finally, as said by Yasser, your scenario is probably simple enough to just leave the combo within the same form as the order by action and its contents will be automatically submitted back to the server when ordering the results.

              • 4. Re: Page Parameters Question Take 2
                jpalmer1026.jpalmer1026.mchsi.com

                Thanks for the prompt response, Emir. If you look at my first post in this thread, you'll notice that I am in fact using


                #{employee.bureau}



                as my backing property. The question then becomes how can I use employee.bureau in my page.xml class without it breaking the code? I'm presuming I need a converter for this, so if someone could let me know what that should look like, that would be very helpful.