12 Replies Latest reply on Jul 17, 2007 4:54 PM by Grant Rettke

    Action argument is null when it shouldn't be null

    Grant Rettke Novice

      Hi folks,

      I'm running into something here where an argument to an action method is null, when I know that the value is actually not null. Here is the course of events:

      A link gets displayed. The name of the link is the account number. When the link is clicked a call is made to a session scoped seam component. The argument is the account number.

      <s:link id="viewDetail"
      value="#{dto.accountNumber}" action="#{accountMaintenanceAction.selectAccount(dto.accountNumber)}"/>
      


      That link gets rendered as
      1024768
      

      And when I click it the action gets run. After that the page is redirected to another page where we get the details for that account.

      <page view-id="/inspectionSearch.xhtml">
       <navigation from-action="#{accountMaintenanceAction.selectAccount(dto.accountNumber)}">
       <redirect view-id="/accountMaintenance.xhtml"/>
       </navigation>
       </page>
      


      The problem is that the argument that gets passed in to that method is null!

      What am I doing wrong here?



        • 1. Re: Action argument is null when it shouldn't be null
          Adrian Mitev Master

          Are you sure that when the action method is invoked the dto bean exists?

          • 2. Re: Action argument is null when it shouldn't be null
            Grant Rettke Novice

             

            "amitev" wrote:
            Are you sure that when the action method is invoked the dto bean exists?


            That is a good question. The search results that carry the DTOs are inside of a session scoped component.

            • 3. Re: Action argument is null when it shouldn't be null
              ilhami visne Newbie

              i have the same problem in a different way. The parameter passed to method is null.

              i have a <s:link> in a dataTable :

              <rich:dataTable value="#{genes}" var="gene" ....> ....
              <s:link action="#{tableviewer.displayTargetSequences(gene)}"> ...</s:link>
              .....</rich:dataTable>


              tableviewer is stateless session bean for outjection the parameter and redirection.

              @Stateless
              @Name("tableviewer")
              public class TableViewerAction implements ITableViewer{
              @Out private Gene selectedGene;
              
              public TableViewerAction() {}
              
              public String displayTargetSequences(Gene gene) {
               selectedGene = gene;
               return "/targetSequenceViewer.xhtml";
               }
              }


              This bean is used only here and constructed probably right after the user clicked on it. Is this the problem?

              • 4. Re: Action argument is null when it shouldn't be null
                Grant Rettke Novice

                 

                "fmars" wrote:
                i have the same problem in a different way. The parameter passed to method is null.
                ...
                This bean is used only here and constructed probably right after the user clicked on it. Is this the problem?


                I get the same problem if I just try passing in the dto itself, it evaluates to null.

                I don't think it is a conversational problem because the dto is used to create the link tag itself (the account number), so I know exists somewhere.

                Is this a lifecycle issue?

                This is how the demo apps are written, but obviously I'm doing something wrong here ;)

                • 5. Re: Action argument is null when it shouldn't be null
                  Adrian Mitev Master

                  I had that problem before and i solved it with long running conversation.

                  • 6. Re: Action argument is null when it shouldn't be null
                    Adrian Mitev Master

                    could you paste your source code?

                    • 7. Re: Action argument is null when it shouldn't be null
                      Gayatri Ramamurthi Newbie

                      1) something that skips the attention is the configuration settings which requires that the below code be added to the application config

                      <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>

                      2) Secondly what i noticed while running a similar app is,

                      " #{accountMaintenanceAction.selectAccount(dto.accountNumber) } " this code generates a URL, with query string "actionMethod=example.xhtml:ccountMaintenanceAction.selectAccount(dto.accountNumber)"

                      whereas using #{accountMaintenanceAction.selectAccount('12345') } would generate the query string as "actionMethod=example.xhtml:ccountMaintenanceAction.selectAccount('12345')"

                      I think this proves that there is a problem either with the handler or any related config issue.

                      • 8. Re: Action argument is null when it shouldn't be null
                        ilhami visne Newbie

                         

                        <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>

                        I use Seam 2 and there is no more "SeamFaceletViewHandler".

                        methsearch.xhtml displays my table. The generated URL looks like this:

                        http://localhost:8080/methcancerdb2/methsearch.seam?
                        dataModelSelection=gene:genes[1]&cid=18&actionMethod=methsearch.xhtml:tableviewer.displayTargetSequences(gene)


                        dataModelSelection=gene:genes[1] : i've clicked link on the second row. so it is the second object in the list "genes". With gene:genes[1] is "gene" is set to genes[1]. what the rest of the url means, i don't know.

                        More Details:

                        I have this methsearch.xhtml for searching my database. there is a button "Show All", which displays all entries on the table with a <s:link> for more infos.

                        there is a statefull sb for this site, MethSearch.java. here is the relevant part of it:


                        @Stateful
                        @Name("methsearch")
                        public class MethSearch implements IMethSearch{
                        ....
                        @Out(required=false)
                        private List<Gene> genes;
                        
                        public void showAll(){
                         genes = ((org.hibernate.Session)this.entityManager.getDelegate()).createCriteria(Gene.class).list();
                         }
                        }


                        "genes" outjected as expected. the table displayed. only the var "gene" is not sent to method successfully. Any Idea?

                        • 9. Re: Action argument is null when it shouldn't be null
                          Grant Rettke Novice

                          This type of construct (passing in a dto via el) works fine in the Seam 1.2.1GA demo app: "booking".

                          That said, what does this article imply?

                          http://www.jboss.com/index.html?module=bb&op=viewtopic&t=104204

                          • 10. Re: Action argument is null when it shouldn't be null
                            Grant Rettke Novice

                            This code from the sample works just fine though:

                            <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>

                            • 11. Re: Action argument is null when it shouldn't be null
                              Michael Courcy Newbie

                               

                              "grettke_spdr" wrote:
                              This code from the sample works just fine though:

                              <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>


                              Yes I ran into this problem until I unserstand that a link is a link and a post is a post ;)

                              Wich means that using such expression

                              <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
                              


                              make sens only if the #{hotelBookings} collection exist in one the available scope.

                              in you watch carefully the Scope of #{hotelBookings} in the seam-books example, it's a session scope.

                              It's really consistent, as you can engage many convesations inside a session. Session is the container of many conversations. Engaging many conversations without a session that reference them don't make sens.

                              When you use s:link with a one argument method you're passing a reference to an obect but you don't post this object.

                              But I agree on the fact that it would be more helpful if we could have an error message like : this object could not be found in any scopes (similar to struts) than having the method executed with a null argument.

                              I can't figure out in wich situation a developper would write

                              <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
                              


                              and expecting "hot" to be null !




                              • 12. Re: Action argument is null when it shouldn't be null
                                Grant Rettke Novice

                                Comparing my code with the example code I found one very important difference, the collection that populates the sample is annotated with @DataModel. This is my error!

                                I had used a plain property of my component, that was the wrong way to do it.