Outject EJB
gmichalk Jun 6, 2006 4:06 AMHi,
I am working on a risk managing app based on the DVD store demo in order to evaluate seam for further developments. In the searchAction.java, I have the following construct:
@EJB @Out(scope=ScopeType.SESSION,required=false)
AccesTicketTypeLocal accesTicketType;
Here is its code of the bean.
@Stateful
@Name("accestickettypebean")
@Scope(ScopeType.EVENT)
public class AccesTicketTypeBean implements AccesTicketTypeLocal, Serializable {
/** Creates a new instance of AccesTypeTickeBean */
public AccesTicketTypeBean() {
}
private List ticketType;
Map<String,TicketType> ticketTypesMap;
@PersistenceContext
EntityManager em;
public void loadData(TypeFormulaire tf) {
System.out.println("============appel de loadData ticketType avec tf="+tf.getReference());
ticketType = em.createQuery("from TicketType c where c.typeFormulaire=:tf")
.setHint("org.hibernate.cacheable", true)
.setParameter("tf",tf)
.getResultList();
Map<String,TicketType> results = new TreeMap<String,TicketType>();
for (TicketType tt: ticketType) {
System.out.println("======== TicketType="+tt.getId()+","+tt.getDescription());
results.put(tt.getDescription(),tt);
}
ticketTypesMap = results;
}
public Converter getConverter() {
return new TicketTypeConverter(ticketType);
}
public Map<String, TicketType> getTicketTypes() {
System.out.println("=======appel getTicketTypes");
Collection tt = ticketTypesMap.keySet();
for (String t:tt)
{
System.out.println(t);
}
System.out.println("=========fin");
return ticketTypesMap;
}
public TicketType getNullTicketType() {
return new TicketType();
}
static public class TicketTypeConverter
implements Converter,
Serializable
{
List tfs;
public TicketTypeConverter(List tf) {
this.tfs = tf;
}
public String getAsString(FacesContext facesContext,
UIComponent component,
Object obj)
{
if (obj == null) return null;
String val = String.valueOf( ((TicketType)obj).getId());
return val;
}
public Object getAsObject(FacesContext facesContext,
UIComponent component,
String str)
throws ConverterException
{
if (str == null || str.length()==0) {
return null;
}
String id = str;
for (TicketType tf : tfs) {
//System.out.println("on teste "+tf.getReference());
if (tf.getId().equals(id)) {
//System.out.println("on trouve "+tf.getDescription());
return tf;
}
}
return null;
}
}
}
Then I inject it via seam in a jsf page:
<h:selectOneMenu value="#{search.ticketType}"
converter="#{accesTicketType.converter}">
<f:selectItems value="#{accesTicketType.ticketTypes}" />
</h:selectOneMenu>
<h:commandButton action="#{search.attribueTicket}"
value="#{msgs.searchButton}"
class="formButton" style="width: 166px;"/>
This works great when it shows the data in the HTML list; but when I click on the button, the value search.ticketType remains at value null.
Some help available ?
Kind regards,
Gerd