我试着去了解一个JSF示例出书的Java EE7发展与Wildfly的,但这里是我不明白 - 即使它的工作原理:@Produces在成员变量
豆:
@Named
@RequestScoped
public class TheatreSetupService {
...
@Produces
@Named
private SeatType newSeatType;
@PostConstruct
public void initNewSeatType() {
newSeatType = new SeatType();
}
....
}
XHTML:
<h:form id="reg" role="form">
<div class="form-group has-feedback #{!desc.valid? 'has-error' : ''}">
<h:outputLabel for="desc" value="Description"
styleClass="control-label"/>
<h:inputText id="desc" value="#{newSeatType.description}"
p:placeholder="Enter a description here" class="form-control"
binding="#{desc}"/>
<span class="#{!desc.valid ? 'glyphicon glyphicon-remove form-control-feedback' : ''}"/>
<h:message for="desc" errorClass="control-label has-error"/>
</div>
</h:form>
实体:
@Entity
@Table(name = "seat_type")
public class SeatType implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Size(min = 1, max = 25, message = "Enter a Seat Description (max 25 char)")
@Pattern(regexp = "[A-Za-z ]*", message = "Description must contain only letters and spaces")
private String description;
private SeatPosition position;
@NotNull
private Integer price;
@NotNull
private Integer quantity;
@OneToMany(mappedBy = "seatType", fetch = FetchType.EAGER)
private List<Seat> seats;
public SeatType() {
// empty for jpa
}
...
}
我不明白@Produces对成员变量newSeatType的影响。创建由TheatreSetupService类明确管理。对我来说,它看起来就像是一个导出,该成员可用于jsf,但@Named注释不足以使此示例正常工作。任何人都可以解释我在这个小例子中发生了什么?据我看,这不是很常用 - 这是真的吗?
谢谢你的提示!
Dominic