Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <h:form>
  2. <p:panelGrid>
  3. <p:row>
  4. <p:column>
  5. <p:outputLabel for="departureRegion" value="Please select a departure region:"/>
  6. </p:column>
  7. <p:column>
  8. <p:selectOneMenu id="departureRegion" value="#{flightBean.departureRegion}">
  9. <f:selectItems value="#{flightBean.allRegions}" var="region" itemValue="#{region}"
  10. itemLabel="#{region.name}"/>
  11. <f:ajax render="departureLocation"/>
  12. </p:selectOneMenu>
  13. </p:column>
  14. </p:row>
  15. <p:row>
  16. <p:column>
  17. <p:outputLabel for="departureLocation" value="Please select a departure location: "/>
  18. </p:column>
  19. <p:column>
  20. <p:selectOneMenu id="departureLocation" value="#{flightBean.departureLocation}">
  21. <f:selectItems value="#{flightBean.allLocationsByRegion}" var="location" itemValue="#{location}"
  22. itemLabel="#{location.name}"/>
  23. </p:selectOneMenu>
  24. </p:column>
  25. </p:row>
  26. </p:panelGrid>
  27. </h:form>
  28.  
  29. @ManagedBean
  30. @ViewScoped
  31. public class FlightBean implements Serializable{
  32. @EJB
  33. private LocationService locationService;
  34.  
  35. @EJB
  36. private RegionService regionService;
  37.  
  38. @NotNull
  39. private Location departureLocation;
  40.  
  41. private Region departureRegion;
  42.  
  43. private Logger logger = LoggerFactory.getLogger(FlightBean.class);
  44.  
  45. public FlightBean() {
  46.  
  47. }
  48.  
  49. @PostConstruct
  50. public void init(){
  51. this.departureRegion = regionService.findRegionById(1);
  52. }
  53.  
  54. public Location getDepartureLocation() {
  55. return departureLocation;
  56. }
  57.  
  58. public void setDepartureLocation(Location departureLocation) {
  59. this.departureLocation = departureLocation;
  60. }
  61.  
  62. public Region getDepartureRegion() {
  63. return departureRegion;
  64. }
  65.  
  66. public void setDepartureRegion(Region departureRegion) {
  67. logger.info("region is " + departureRegion);
  68. this.departureRegion = departureRegion;
  69. }
  70.  
  71. public List<Region> getAllRegions(){
  72. return regionService.findAllRegions();
  73. }
  74.  
  75. public List<Location> getAllLocationsByRegion(){
  76. return locationService.findAllLocationsByRegion(departureRegion);
  77. }
  78.  
  79. public void refreshLocations(AjaxBehaviorEvent event){
  80. logger.info("event " + event.toString());
  81. getAllLocationsByRegion();
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement