outject problem
laksu Feb 19, 2007 11:06 AMI already (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=101517) had asked this in this forum and I could not solve the problem yet. Here I have downsized my dummy app to even simpler and it still cannot outject. I must be missing or misunderstanding something fundamental.
I have the entity bean Organization:
@Entity @Name("organization") public class Organization implements Serializable { @TableGenerator(name="organizationGenerator") @Id @GeneratedValue(strategy=GenerationType.TABLE,generator="organizationGenerator") private Long id; private String name; private String description,address; private boolean deleted=false; @Temporal(TemporalType.DATE) private Date startUpDate; public Organization() { name="unnamed"; } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } @Override public int hashCode() { int hash = 0; hash += (this.id != null ? this.id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Organization)) { return false; } Organization other = (Organization)object; if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false; return true; } @Override public String toString() { return "[id=" + id + ":"+ name +"]"; } ... standart getters and setters follow ...
A stateful session bean
@Stateful @Name("testAction") public class TestActionBean implements TestActionLocal { @Out Organization organization; public TestActionBean() {} @Begin public String go(){ organization=new Organization(); organization.setName("Tester"); return "org"; } @End public String stop(){ return "test"; } @Remove @Destroy void destroy(){} }
one initial page, only for calling the action bean:
test.xhtml <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" template="listTemplate.xhtml"> <ui:define name="content"> <h:form> <h:commandButton value="Go" action="#{testAction.go}" /> </h:form> </ui:define> </ui:composition>
and another one that is navigated when "org" is returned:
org.xhtml <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" template="listTemplate.xhtml" > <ui:define name="content"> <h:form> <h:outputLabel value="Name:" /> <h:inputText value="#{organization.name}"/> </h:form> </ui:define> </ui:composition>
I construct a new "Organization" at the method "go" and set its "name" property to "tester". I expect it to show up in the "org.xhtml", but instead "unnamed" shows up, which is assigned in the default constructor of "Organization". The instance I assigned at the "go" method is ignored and another instance is outjected.
Where am I wrong?
Regards,
Levent