我有 1 Entity
with 1 Named
Bean with ConversationScope
,我创建了一个jsf form
带保存按钮,我的问题是,为什么当我的表单使用@injected 发布我的实体时,实体 bean 的属性(ArticuloController 属性)没有被注入。与 cdi 一起存在类似于@in
seam2 的注释 to populate @inject
Entity entity
。
这是我的源代码:
@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>
更新:我正在使用 seam3 3.1.0.Final