@ModelAttribute public void addDataToModel(ModelMap model){
  SearchData advancedSearchData=new SearchData();
  advancedSearchData.setCurrentPage(1);
  advancedSearchData.setNumberResultsPerPage(DEFAULT_NUMBER_OF_RESULTS_PER_PAGE);
  advancedSearchData.setSearchMode("natural");
  advancedSearchData.setCurrentPage(1);
  advancedSearchData.setQueryText(null);
  model.put("advancedSearchData",advancedSearchData);
  model.put("randomPodcasts",startPageService.getRandomPodcasts(NUMBER_OF_PODCASTS_IN_CHART));
  model.addAttribute("mediaTypes",MediaType.values());
  model.addAttribute("languageCodes",LanguageCode.values());
  model.addAttribute("orderByOptions",OrderByOption.values());
  List<Category> categoriesByNoOfPodcasts=categoryService.getCategoriesOrderedByNoOfPodcasts();
  model.put("topCategories",categoriesByNoOfPodcasts.subList(0,NUMBER_OF_CATEGORIES_IN_CHART));
  model.put("allCategories",categoriesByNoOfPodcasts);
  List<Podcast> recommendedPodcasts=startPageService.getRecommendedPodcasts();
  model.put("recommendedPodcasts",recommendedPodcasts);
  Locale locale=LocaleContextHolder.getLocale();
  String language=locale.getLanguage();
  List<String> preferredLanguagesList=Arrays.asList(preferredLanguages);
  model.put("newEntries",startPageService.getNewEntries());
  if (preferredLanguagesList.contains(language)) {
    model.put("lastUpdatedPodcasts",startPageService.getLastUpdatedPodcasts(LanguageCode.get(language)));
  }
 else {
    model.put("lastUpdatedPodcasts",startPageService.getLastUpdatedPodcasts());
  }
}

@ ModelAttribute public void addDataToModel ( ModelMap model ) { SearchData advancedSearchData = new SearchData ( ) ; advancedSearchData . setCurrentPage ( 1 ) ; advancedSearchData . setNumberResultsPerPage ( DEFAULT_NUMBER_OF_RESULTS_PER_PAGE ) ; advancedSearchData . setSearchMode ( "natural" ) ; advancedSearchData . setCurrentPage ( 1 ) ; advancedSearchData . setQueryText ( null ) ; model . put ( "advancedSearchData" , advancedSearchData ) ; model . put ( "randomPodcasts" , startPageService . getRandomPodcasts ( NUMBER_OF_PODCASTS_IN_CHART ) ) ; model . addAttribute ( "mediaTypes" , MediaType . values ( ) ) ; model . addAttribute ( "languageCodes" , LanguageCode . values ( ) ) ; model . addAttribute ( "orderByOptions" , OrderByOption . values ( ) ) ; List < Category > categoriesByNoOfPodcasts = categoryService . getCategoriesOrderedByNoOfPodcasts ( ) ; model . put ( "topCategories" , categoriesByNoOfPodcasts . subList ( 0 , NUMBER_OF_CATEGORIES_IN_CHART ) ) ; model . put ( "allCategories" , categoriesByNoOfPodcasts ) ; List < Podcast > recommendedPodcasts = startPageService . getRecommendedPodcasts ( ) ; model . put ( "recommendedPodcasts" , recommendedPodcasts ) ; Locale locale = LocaleContextHolder . getLocale ( ) ; String language = locale . getLanguage ( ) ; List < String > preferredLanguagesList = Arrays . asList ( preferredLanguages ) ; model . put ( "newEntries" , startPageService . getNewEntries ( ) ) ; if ( preferredLanguagesList . contains ( language ) ) { model . put ( "lastUpdatedPodcasts" , startPageService . getLastUpdatedPodcasts ( LanguageCode . get ( language ) ) ) ; } else { model . put ( "lastUpdatedPodcasts" , startPageService . getLastUpdatedPodcasts ( ) ) ; } }
add an empty searchdata object to the model - this is needed just for the search bar . tbd - search a way to optimize this . . .
