8 Replies Latest reply on Jul 1, 2014 5:51 PM by aristide

    Target Unreachable, '...' returned null on '...'

    gnufolandia

      Dear experts,
      my environment is: JBOSS 4.2, seam 2.1, eclipse europa 3.3.2 with jboss tools 2.1.2.


      I created 2 classes Bank and User. By reverse engineering, eclipse automatically created BankHome, BankList, UserHome and UserList classes plus the following xhtml files: Bank.xhtml,
      BankHome.xhtml, BankList.xhtml etc...


      After eclipse reverse engineering, I joined Bank and User classes in a OneToOne relationship:



      imports...
      /**
       * Bank generated by hbm2java
       */
      @Entity
      @Table(name = "bank", catalog = "df", uniqueConstraints = @UniqueConstraint(columnNames = "billacc"))
      public class Bank implements java.io.Serializable {
      
           private int id;
           private String billacc;
           private User user;
      
      [...]
          @OneToOne
           @JoinTable(name = "bank_user", 
                     joinColumns = @JoinColumn(name = "idbank"), 
                     inverseJoinColumns = @JoinColumn(name = "iduser"))
          public User getUser() {
              return user;
          }
          public void setUser(User user) {
              this.user = user;
          }
      }
      



      and...





      imports...
      /**
       * User generated by hbm2java
       */
      @Entity
      @SuppressWarnings("serial")
      @Table(name = "user", catalog = "df")
      public class User implements java.io.Serializable {
      
           private Integer id;
           private String firstName;
           private String surname;
           private String account;
           private String password;
           private String email;
           private boolean isMarried;
           private int children;
           private Date fromDate;
           private Date endDate;
           private Float credit;
           private Float debt;
           private Set<Dutyfreerole> dutyfreeroles;
           private Bank bankaccount;
           private Set<Invoices> invoices;
           private Set<Orders> orders;
      [...]
           @OneToOne
           @JoinTable(name = "bank_user", 
                     joinColumns = @JoinColumn(name = "iduser"), 
                     inverseJoinColumns = @JoinColumn(name = "idbank"))
                    public Bank getBankaccount() {
                        return bankaccount;
                    }
                    public void setBankaccount(Bank bankaccount) {
                        this.bankaccount = bankaccount;
                    }
      [...]
       }
      



      Then, I want to modify BankList.xhtml adding a search parameter related to user:




      [...]
      <ui:define name="body">
          
          <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
          
          <h:form id="bankSearch" styleClass="edit">
          
              <rich:simpleTogglePanel label="Bank Account search parameters" switchType="ajax">
              
                  <s:decorate template="../layout/display.xhtml">
                      <ui:define name="label">Bank Account</ui:define>
                      <h:inputText id="billacc" value="#{bankList.bank.billacc}"/>
                  </s:decorate>
      
      <--! BEGIN CODE ADDED BY ME -->
      *          <s:decorate template="../layout/display.xhtml">
                      <ui:define name="label">user</ui:define>
                      <h:inputText id="user" value="#{bankList.bank.user.account}"/>
                  </s:decorate>
       *           
      <--! END CODE ADDED -->        
              <div class="actionButtons">
                  <h:commandButton id="search" value="Search" action="BankList.xhtml"/>
              </div>
              
          </h:form>
          
          <rich:panel>
              <f:facet name="header">Bank Account search results</f:facet>
          <div class="results" id="bankList">
      
          <h:outputText value="No bank account exists" 
                     rendered="#{empty bankList.resultList}"/>
                     
          <rich:dataTable id="bankList" 
                      var="bank"
                    value="#{bankList.resultList}" 
                 rendered="#{not empty bankList.resultList}">
                 
                         <h:column>
                  <f:facet name="header">
                      <s:link styleClass="columnHeader"
                                   value="account #{bankList.order=='account asc' ? messages.down : ( bankList.order=='account desc' ? messages.up : '' )}">
                          <f:param name="order" value="#{bankList.order=='user.account asc' ? 'user.account desc' : 'user.account asc'}"/>
                      </s:link>
                  </f:facet>
                  #{bank.user.account}
              </h:column>
              <h:column>
                  <f:facet name="header">
                      <s:link styleClass="columnHeader"
                                   value="billacc #{bankList.order=='billacc asc' ? messages.down : ( bankList.order=='billacc desc' ? messages.up : '' )}">
                          <f:param name="order" value="#{bankList.order=='billacc asc' ? 'billacc desc' : 'billacc asc'}"/>
                      </s:link>
                  </f:facet>
                  #{bank.billacc}
              </h:column>
              <h:column>
                  <f:facet name="header">action</f:facet>
                  <s:link view="/admin/#{empty from ? 'Bank' : from}.xhtml" 
                         value="Select" 
                            id="bank">
                      <f:param name="bankId" 
                              value="#{bank.id}"/>
                  </s:link>
              </h:column>
          </rich:dataTable>
      
          </div>
          </rich:panel>
          
          <div class="tableControl">
            
              <s:link view="/admin/BankList.xhtml" 
                  rendered="#{bankList.previousExists}" 
                     value="#{messages.left}#{messages.left} First Page"
                        id="firstPage">
                <f:param name="firstResult" value="0"/>
              </s:link>
              
              <s:link view="/admin/BankList.xhtml" 
                  rendered="#{bankList.previousExists}" 
                     value="#{messages.left} Previous Page"
                        id="previousPage">
                  <f:param name="firstResult" 
                          value="#{bankList.previousFirstResult}"/>
              </s:link>
              
              <s:link view="/admin/BankList.xhtml" 
                  rendered="#{bankList.nextExists}" 
                     value="Next Page #{messages.right}"
                        id="nextPage">
                  <f:param name="firstResult" 
                          value="#{bankList.nextFirstResult}"/>
              </s:link>
              
              <s:link view="/admin/BankList.xhtml" 
                  rendered="#{bankList.nextExists}" 
                     value="Last Page #{messages.right}#{messages.right}"
                        id="lastPage">
                  <f:param name="firstResult" 
                          value="#{bankList.lastFirstResult}"/>
              </s:link>
              
          </div>
          
      [...]
          
      </ui:define>
      
      </ui:composition>




      But if add that code the result is:




      Exception during request processing:
      Caused by javax.servlet.ServletException with message: /admin/BankList.xhtml @26,79 value=#{bankList.bank.user.account}: Target Unreachable, 'user' returned null on 'org.bsc.DutyFree.entity.Bank'


      What am I doing wrong?

        • 1. Re: Target Unreachable, '...' returned null on '...'
          gnufolandia

          To summarize,


          this works:



                      <s:decorate template="../layout/display.xhtml">
                          <ui:define name="label">Bank Account</ui:define>
                          <h:inputText id="billacc" value="#{bankList.bank.billacc}"/>
                      </s:decorate>
          




          and this doesn't?



                    <s:decorate template="../layout/display.xhtml">
                          <ui:define name="label">user</ui:define>
                          <h:inputText id="user" value="#{bankList.bank.user.account}"/>
                      </s:decorate>
          




          • 2. Re: Target Unreachable, '...' returned null on '...'
            tmalatinszki

            Hi,


            The target which is unreachable is the account property of the User class, because user variable of bankList.bank is null.
            So the problem should be there is no User entity fetched in Your actual Bank entity.


            Regards,


            Tamas

            • 3. Re: Target Unreachable, '...' returned null on '...'
              gnufolandia

              Hi Tamas,


              if I comment out:



                        <s:decorate template="../layout/display.xhtml">
                              <ui:define name="label">user</ui:define>
                              <h:inputText id="user" value="#{bankList.bank.user.account}"/>
                          </s:decorate>
              



              then everything works and the list shows correctly the column with bank.user.account:


              <rich:dataTable id="bankList" 
                              var="bank"
                            value="#{bankList.resultList}" 
                         rendered="#{not empty bankList.resultList}">
                         
                                 <h:column>
                          <f:facet name="header">
                              <s:link styleClass="columnHeader"
                                           value="account #{bankList.order=='account asc' ? messages.down : ( bankList.order=='account desc' ? messages.up : '' )}">
                                  <f:param name="order" value="#{bankList.order=='user.account asc' ? 'user.account desc' : 'user.account asc'}"/>
                              </s:link>
                          </f:facet>
                          #{bank.user.account}
                      </h:column>
              



              So it seems that User entity is fetched but it has some problems when it is used to filter BankList.resultList.
              Is that correct?
              Maybe it has something to do with cascade or fetch type?


              • 4. Re: Target Unreachable, '...' returned null on '...'
                minimum

                Dear, everyone.
                I have same problem, too.
                Please give me some solutions.
                Thanks all.

                • 5. Re: Target Unreachable, '...' returned null on '...'
                  minimum

                  Please help ???

                  • 6. Re: Target Unreachable, '...' returned null on '...'
                    mackhitler

                    I have the same problem, please help???????????????''

                    • 7. Re: Target Unreachable, '...' returned null on '...'
                      vata2999

                      AFAIK, you can solve this problem as below


                      1.Create another seam component from your bank entity in your components.xml



                      <component class="Bank" name="bank">
                      <property name="user">#{userHome.instance}</property>
                      </component>
                      
                      



                      in view




                      <s:decorate template="../layout/display.xhtml">
                                      <ui:define name="label">user</ui:define>
                                      <h:inputText id="user" value="#{bank.user.account}"/>
                                  </s:decorate>



                      in your entityQuery




                      Restriction = "{b.user.account = #{bank.user.account}}"



                      problem solved ;)






                      • 8. Re: Target Unreachable, '...' returned null on '...'
                        aristide

                        I tried this solution but it did not work.

                         

                        I ended up solving a simpler way.

                         

                        Keep the original amendments and in BankList class and method BankList () enter the following commands:

                         

                        User user = new User ();

                        user.setAccount ("");

                        bankList.setUser (user);

                         

                        Thus no longer will give error.