Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h:form>
- <p:panelGrid>
- <p:row>
- <p:column>
- <p:outputLabel for="departureRegion" value="Please select a departure region:"/>
- </p:column>
- <p:column>
- <p:selectOneMenu id="departureRegion" value="#{flightBean.departureRegion}">
- <f:selectItems value="#{flightBean.allRegions}" var="region" itemValue="#{region}"
- itemLabel="#{region.name}"/>
- <f:ajax render="departureLocation"/>
- </p:selectOneMenu>
- </p:column>
- </p:row>
- <p:row>
- <p:column>
- <p:outputLabel for="departureLocation" value="Please select a departure location: "/>
- </p:column>
- <p:column>
- <p:selectOneMenu id="departureLocation" value="#{flightBean.departureLocation}">
- <f:selectItems value="#{flightBean.allLocationsByRegion}" var="location" itemValue="#{location}"
- itemLabel="#{location.name}"/>
- </p:selectOneMenu>
- </p:column>
- </p:row>
- </p:panelGrid>
- </h:form>
- @ManagedBean
- @ViewScoped
- public class FlightBean implements Serializable{
- @EJB
- private LocationService locationService;
- @EJB
- private RegionService regionService;
- @NotNull
- private Location departureLocation;
- private Region departureRegion;
- private Logger logger = LoggerFactory.getLogger(FlightBean.class);
- public FlightBean() {
- }
- @PostConstruct
- public void init(){
- this.departureRegion = regionService.findRegionById(1);
- }
- public Location getDepartureLocation() {
- return departureLocation;
- }
- public void setDepartureLocation(Location departureLocation) {
- this.departureLocation = departureLocation;
- }
- public Region getDepartureRegion() {
- return departureRegion;
- }
- public void setDepartureRegion(Region departureRegion) {
- logger.info("region is " + departureRegion);
- this.departureRegion = departureRegion;
- }
- public List<Region> getAllRegions(){
- return regionService.findAllRegions();
- }
- public List<Location> getAllLocationsByRegion(){
- return locationService.findAllLocationsByRegion(departureRegion);
- }
- public void refreshLocations(AjaxBehaviorEvent event){
- logger.info("event " + event.toString());
- getAllLocationsByRegion();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement