i'm having 1 Entity
with 1 Named
Bean with ConversationScope
, I created a jsf form
with save button, and my problem is, why when my form are posted my entity with @injected, the properties of the entity bean(ArticuloController property) has not been injected. Exists with cdi something similar to @in
annotation of seam2 to populate @inject
Entity entity
.
this is my source code:
@Entity
@Named("articulo")
public class Articulo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "articulo_seq")
@SequenceGenerator(name = "articulo_seq", sequenceName = "articulo_seq")
private Integer articulo;
private String descripcion="";
//my action class
@Named("articuloController")
@ConversationScoped
public class ArticuloController implements Serializable {
@Inject
private Articulo articulo;
@Inject
private Messages messages;
@Begin
public String init() {
messages.info("init conversation");
//this values is not show in the jsf form
articulo.setDescripcion("complete descripcion");
articulo.setPrecio(new BigDecimal(0));
return null;
}
public String save() {
//the values of the properties is not the values filled by user,
//but is the values filled by init method
System.out.println("save!" + articulo.getDescripcion()
+ articulo.getPrecio() + " " + id);
return null;
}
my jsf page is
<f:metadata>
<f:viewParam name="id" value="#{articuloController.id}" />
<s:viewAction action="#{articuloController.init}" />
</f:metadata>
<h:form>
<h:panelGrid columns="3" id="panel">
<h:outputLabel value="Descripcion" />
<h:inputText value="#{articulo.descripcion}" id="descripcion"
required="true" label="Descripción" />
<rich:message for="descripcion" />
<h:outputLabel value="Precio" />
<h:inputText value="#{articulo.precio}" id="precio" required="true"
label="Precio" />
<rich:message for="precio" />
<h:commandButton value="Guardar" action="#{articuloController.save}" />
</h:panelGrid>
</h:form>
Updated: i'm using seam3 3.1.0.Final
Mixing JPA and CDI this way is a very bad idea. Things will not save correctly if you do it this way and you'll have exceptions all over the place. What you need to do is remove the @Name from entity and create a producer for it. You'll also need to add a scope annotation to the producer, probably request or conversation will work fine.