【发布时间】:2014-01-08 17:08:00
【问题描述】:
我可以在使用 ManagedBean 的 faces 版本时使用 ManagedProperty,但在 javax.annotation.ManagedBean 时不能使用
@ManagedBean
@RequestScoped
public class TripListProducer {
@Inject
private TripDao tripDao;
private List<Trip> trips_list;
@ManagedProperty(value = "#{param.active}")
private Boolean active = true;
我正在使用javax.annotation.ManagedBean,因为这是我能够在我的facelet 中使用@Produces 和@Named 和<h:dataTable var="_trip" value="#{trips}" 的唯一方法。如果使用 ManagedBean 的 faces 版本,我更喜欢 facelet,而不是 <h:dataTable var="_trip" value="#{tripListProducer.trip.trip_list}"。
@Produces
@Named
public List<Trip> getTrips() {
return trips_list;
}
我尝试使用@ManagedProperty 的原因是我希望用户能够选择显示仅活动行程或所有行程的列表。我更喜欢使用 RESTful url .com/SkiClub/trips/active 或 .com/SkiClub/index.xhtml?active=false
@PostConstruct
public void retrieveAllTripsOrderedByDate() {
System.out.println("Active Only? " + active);
if (active) {
trips_list = tripDao.findAllActiveOrderedByStartDate();
} else {
trips_list = tripDao.findAllOrderedByStartDate();
}
}
但 active 始终保持默认值 true。不要在我的问题中添加太多内容,但我也觉得我的 retrieveAllTripsOrderedByDate 中的 if 语句可能不是最好的方法。
【问题讨论】:
标签: jsf jakarta-ee javabeans facelets