Target Unreachable, '...' returned null on '...'
gnufolandia Jan 12, 2010 2:14 PMDear 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?