public void handleLivingDistrictChange(AjaxBehaviorEvent event) {
    try {
      if (selectedUserForEditing.getDistrictLivingId() == 0
          || selectedUserForEditing.getDistrictLivingId() == null) {
        enableLivingAssemblyConstituencyCombo = false;
        livingAssemblyConstituencyList = new ArrayList<>();
      } else {
        enableLivingAssemblyConstituencyCombo = true;
        livingAssemblyConstituencyList =
            aapService.getAllAssemblyConstituenciesOfDistrict(
                selectedUserForEditing.getDistrictLivingId());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void handleStateChange(AjaxBehaviorEvent event) {
   try {
     if (selectedUserForEditing.getStateVotingId() == 0
         || selectedUserForEditing.getStateVotingId() == null) {
       enableDistrictCombo = false;
       enableParliamentConstituencyCombo = false;
       districtList = new ArrayList<>();
       parliamentConstituencyList = new ArrayList<>();
     } else {
       districtList = aapService.getAllDistrictOfState(selectedUserForEditing.getStateVotingId());
       parliamentConstituencyList =
           aapService.getAllParliamentConstituenciesOfState(
               selectedUserForEditing.getStateVotingId());
       enableDistrictCombo = true;
       enableParliamentConstituencyCombo = true;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @URLAction(onPostback = false)
  public void init() throws Exception {
    showBanner = true;
    if (countries == null || countries.isEmpty()) {
      countries = aapService.getAllCountries();
    }
    if (stateList == null || stateList.isEmpty()) {
      livingStateList = stateList = aapService.getAllStates();
    }
    // Copy Logged In user to selectedUserForEditing
    selectedUserForEditing = new UserDto();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 1981);
    selectedUserForEditing.setDateOfBirth(cal.getTime());

    if (selectedUserForEditing.getStateVotingId() != null) {
      enableDistrictCombo = true;
      enableParliamentConstituencyCombo = true;
      parliamentConstituencyList =
          aapService.getAllParliamentConstituenciesOfState(
              selectedUserForEditing.getStateVotingId());
      districtList = aapService.getAllDistrictOfState(selectedUserForEditing.getStateVotingId());
      if (selectedUserForEditing.getDistrictVotingId() != null) {
        enableAssemblyConstituencyCombo = true;
        assemblyConstituencyList =
            aapService.getAllAssemblyConstituenciesOfDistrict(
                selectedUserForEditing.getDistrictVotingId());
      }
    }
    if (selectedUserForEditing.getStateLivingId() != null) {
      enableLivingDistrictCombo = true;
      enableLivingParliamentConstituencyCombo = true;
      livingParliamentConstituencyList =
          aapService.getAllParliamentConstituenciesOfState(
              selectedUserForEditing.getStateLivingId());
      livingDistrictList =
          aapService.getAllDistrictOfState(selectedUserForEditing.getStateLivingId());
      if (selectedUserForEditing.getDistrictLivingId() != null) {
        enableLivingAssemblyConstituencyCombo = true;
        livingAssemblyConstituencyList =
            aapService.getAllAssemblyConstituenciesOfDistrict(
                selectedUserForEditing.getDistrictLivingId());
      }
    }
  }
 public boolean isShowMemberPanel() {
   return StringUtil.isEmpty(selectedUserForEditing.getMembershipNumber());
 }
  public void saveProfile(ActionEvent event) {
    showBanner = false;
    if (sameAsLiving) {
      selectedUserForEditing.setStateVotingId(selectedUserForEditing.getStateLivingId());
      selectedUserForEditing.setDistrictVotingId(selectedUserForEditing.getDistrictLivingId());
      selectedUserForEditing.setAssemblyConstituencyVotingId(
          selectedUserForEditing.getAssemblyConstituencyLivingId());
      selectedUserForEditing.setParliamentConstituencyVotingId(
          selectedUserForEditing.getParliamentConstituencyLivingId());
    }

    if (selectedUserForEditing.getStateLivingId() == null
        || selectedUserForEditing.getStateLivingId() == 0) {
      sendErrorMessageToJsfScreen("Please select State where you are living currently");
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("livingState"))
          .setValid(false);
    }
    if (selectedUserForEditing.getDistrictLivingId() == null
        || selectedUserForEditing.getDistrictLivingId() == 0) {
      sendErrorMessageToJsfScreen("Please select District where you are living currently");
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("livingDistrict"))
          .setValid(false);
    }
    if (selectedUserForEditing.getAssemblyConstituencyLivingId() == null
        || selectedUserForEditing.getAssemblyConstituencyLivingId() == 0) {
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("livingAssemblyConstituency"))
          .setValid(false);
      sendErrorMessageToJsfScreen(
          "Please select Assembly Constituency where you are living currently");
    }
    if (selectedUserForEditing.getParliamentConstituencyLivingId() == null
        || selectedUserForEditing.getParliamentConstituencyLivingId() == 0) {
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("livingParliamentConstituency"))
          .setValid(false);
      sendErrorMessageToJsfScreen(
          "Please select Parliament Constituency where you are living currently");
    }
    if (selectedUserForEditing.getStateVotingId() == null
        || selectedUserForEditing.getStateVotingId() == 0) {
      sendErrorMessageToJsfScreen("Please select State where you are registered as Voter");
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("state"))
          .setValid(false);
    }
    if (selectedUserForEditing.getDistrictVotingId() == null
        || selectedUserForEditing.getDistrictVotingId() == 0) {
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("district"))
          .setValid(false);
      sendErrorMessageToJsfScreen("Please select District where you are registered as Voter");
    }
    if (selectedUserForEditing.getAssemblyConstituencyVotingId() == null
        || selectedUserForEditing.getAssemblyConstituencyVotingId() == 0) {
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("assemblyConstituency"))
          .setValid(false);
      sendErrorMessageToJsfScreen(
          "Please select Assembly Constituency where you registered as Voter");
    }
    if (selectedUserForEditing.getParliamentConstituencyVotingId() == null
        || selectedUserForEditing.getParliamentConstituencyVotingId() == 0) {
      ((UISelectOne)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("parliamentConstituency"))
          .setValid(false);
      sendErrorMessageToJsfScreen(
          "Please select Parliament Constituency where you registered as Voter");
    }
    if (selectedUserForEditing.isNri()) {
      if ((selectedUserForEditing.getNriCountryId() == null
          || selectedUserForEditing.getNriCountryId() == 0)) {
        sendErrorMessageToJsfScreen("Please select Country where you Live");
        ((UIInput)
                UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                    .findComponent("nriCountry"))
            .setValid(false);
      }
      if (selectedUserForEditing.isMember()
          && StringUtil.isEmpty(selectedUserForEditing.getPassportNumber())) {
        sendErrorMessageToJsfScreen(
            "Please enter passport number. Its Required for NRIs to become member/Volunteer.");
        ((UIInput)
                UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                    .findComponent("passportNumber"))
            .setValid(false);
      }
    }
    if (!selectedUserForEditing.isMember() && !selectedUserForEditing.isVolunteer()) {
      sendErrorMessageToJsfScreen("Please choose if you want to be Member or Volunteer or both");
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("member"))
          .setValid(false);
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("volunteer"))
          .setValid(false);
    }
    if (selectedUserForEditing.getDateOfBirth() == null) {
      sendErrorMessageToJsfScreen("Please enter your Date of Birth");
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("cal"))
          .setValid(false);
    }
    /*
     * else{ Calendar todayCalendar = Calendar.getInstance();
     * todayCalendar.add(Calendar.YEAR, -18);
     * if(dobCalendar.after(todayCalendar)){
     * sendErrorMessageToJsfScreen("You must be 18 to be eligible for vote"
     * ); } }
     */
    if (StringUtil.isEmptyOrWhitespace(selectedUserForEditing.getName())) {
      sendErrorMessageToJsfScreen("Please enter your full name");
      // sendErrorMessageToJsfScreen("name", "Please enter your full name");
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("name"))
          .setValid(false);
    }
    if (StringUtil.isEmptyOrWhitespace(selectedUserForEditing.getEmail())
        && StringUtil.isEmptyOrWhitespace(selectedUserForEditing.getMobileNumber())) {
      sendErrorMessageToJsfScreen("Please enter either email or Mobile number or both");
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("email"))
          .setValid(false);
      ((UIInput)
              UIViewRoot.getCurrentComponent(FacesContext.getCurrentInstance())
                  .findComponent("mobile"))
          .setValid(false);
    }
    if (isValidInput()) {
      try {
        selectedUserForEditing = aapService.saveUser(selectedUserForEditing);
        ssaveLoggedInUserInSession(selectedUserForEditing);
        sendInfoMessageToJsfScreen("Profile saved succesfully.");

      } catch (Exception ex) {
        sendErrorMessageToJsfScreen(ex.getMessage());
      }
    }
    /*
     * String url =
     * BaseController.getFinalRedirectUrlFromSesion(getHttpServletRequest
     * ()); if(!StringUtil.isEmpty(url)){
     * BaseController.clearFinalRedirectUrlInSesion
     * (getHttpServletRequest()); redirect(buildUrl(url)); }
     */
  }