How to make a custom search using seam components?
oussama Aug 18, 2009 11:29 AMI’m developing an application using as framework JBoss Seam and I encountered a problem that I couldn’t solve since a week. I hope I can find a solution in this group.
First, I was using the totoList.xhtml, totoList.java session and the toto entity as it is generated by Seam-Gen. But, this could work only for a classic list search that means when the attributes are those present in the entity. This allows me to search for any attribute using toto.attribute in the inputText normally when the type is a string or to be modified for other types like int.
But, my situation is more complicated:
This is the first entity: Demande
|@Entity @Table(name = "DEMANDE", schema = "SIMM_SYS") @javax.persistence.SequenceGenerator(name = "SEQ_DEMANDE", sequenceName = "SEQ_DEMANDE", allocationSize = 1) public class Demande implements java.io.Serializable { private int id; private Navire navire; private String nomdemandeur; private String prenomdemandeur; … @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "REFNAVIRE") public Navire getNavire() { return this.navire; } public void setNavire(Navire navire) { this.navire = navire; } … }|
This is the second entity: Navire
@Entity @Table(name = "NAVIRE", schema = "SIMM_SYS") @javax.persistence.SequenceGenerator(name = "SEQ_NAVIRE", sequenceName = "SEQ_NAVIRE", allocationSize = 1) public class Navire implements java.io.Serializable { private int id; private String matricule; … @OneToMany(fetch = FetchType.LAZY, mappedBy = "navire") public List<Demande> getDemandes() { return demandes; } … }
In the demandeList.xhtml page it works only when I use it for the classic one (same thing for the navireList.xhtml).
The problem start when I wanted to make a search for an attribute from the navire entity in the demandeList.xhtml (or from the demande entity in the navireList.xhyml) in order to get a search for attributes that exit in the two entities.
Example: when I made a search for the attribute navire.matricule in the demandeList.xhtml like this:
<s:decorate template="layout/display.xhtml"> <ui:define name="label">N° Enregistrement</ui:define> <h:inputText id="idSearch" value="#{demandeList.demande.navire.matricule}"> </h:inputText> </s:decorate>
And I added the parameter in the page demandeList.page.xml:
<param name="demande.navire.id" value="#{demandeList.demande.navire.id}"/>
And I added this line in the demandeList.java session as a restriction:
"demande.navire.id = #{demandeList.demande.navire.id}",
I received this error:
Exception during request processing:
Caused by javax.servlet.ServletException with message: "/DemandeList.xhtml @43,73 value="#{demandeList.demande.navire.id}": Target Unreachable, 'navire' returned null on
…entities.demande
…
Caused by javax.el.PropertyNotFoundException with message: "/DemandeList.xhtml @43,73 value="#{demandeList.demande.navire.id}": Target Unreachable, 'navire' returned null on the …entities.demande
I hope I can find a solution. Thanks a lot.