Domanda

I'm able to use ManagedProperty when using the faces version of ManagedBean, but not when its a 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;

I'm using the javax.annotation.ManagedBean because that is the only way I was able to use @Produces and @Named with <h:dataTable var="_trip" value="#{trips}" in my facelet. I kind of like that better in the facelet as opposed to <h:dataTable var="_trip" value="#{tripListProducer.trip.trip_list}" if using the faces version of ManagedBean.

@Produces
@Named
public List<Trip> getTrips() {
   return trips_list;
}

And the reason I was trying to use @ManagedProperty because I want the user to be able to choose to display list of active only trips or all trips. I prefer to be using RESTful urls .com/SkiClub/trips/active or .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();
     }
  }

But active always stays to the default true. Not to tack on too much in my question, but I also feel that the if statement in my retrieveAllTripsOrderedByDate may not be the best approach.

È stato utile?

Soluzione

You need to decide between jsf managed beans and (cdi) javabeans. Can't mix both annotation types in one bean.

For your @ManagedProperty use there's omnifaces' @Param annotation, so you can go full CDI.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top