001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.view.client.web.struts; 018 019import com.echothree.control.user.accounting.common.AccountingUtil; 020import com.echothree.control.user.accounting.common.result.GetCurrencyChoicesResult; 021import com.echothree.control.user.party.common.PartyUtil; 022import com.echothree.control.user.party.common.result.GetDateTimeFormatChoicesResult; 023import com.echothree.control.user.party.common.result.GetLanguageChoicesResult; 024import com.echothree.control.user.party.common.result.GetTimeZoneChoicesResult; 025import com.echothree.model.control.accounting.common.choice.CurrencyChoicesBean; 026import com.echothree.model.control.party.common.choice.DateTimeFormatChoicesBean; 027import com.echothree.model.control.party.common.choice.LanguageChoicesBean; 028import com.echothree.model.control.party.common.choice.TimeZoneChoicesBean; 029import java.util.List; 030import javax.naming.NamingException; 031import org.apache.struts.util.LabelValueBean; 032 033public class BasePartyActionForm 034 extends BaseActionForm { 035 036 private CurrencyChoicesBean currencyChoices = null; 037 private DateTimeFormatChoicesBean dateTimeFormatChoices = null; 038 private LanguageChoicesBean languageChoices = null; 039 private TimeZoneChoicesBean timeZoneChoices = null; 040 041 private String currencyChoice = null; 042 private String dateTimeFormatChoice = null; 043 private String languageChoice = null; 044 private String timeZoneChoice = null; 045 046 /** Creates a new instance of BasePartyActionForm */ 047 public BasePartyActionForm() { 048 super(); 049 } 050 051 private void setupCurrencyChoices() { 052 if(currencyChoices == null) { 053 try { 054 var commandForm = AccountingUtil.getHome().getGetCurrencyChoicesForm(); 055 056 commandForm.setDefaultCurrencyChoice(currencyChoice); 057 commandForm.setAllowNullChoice(String.valueOf(true)); 058 059 var commandResult = AccountingUtil.getHome().getCurrencyChoices(userVisitPK, commandForm); 060 var executionResult = commandResult.getExecutionResult(); 061 var getCurrencyChoicesResult = (GetCurrencyChoicesResult)executionResult.getResult(); 062 currencyChoices = getCurrencyChoicesResult.getCurrencyChoices(); 063 064 if(currencyChoice == null) { 065 currencyChoice = currencyChoices.getDefaultValue(); 066 } 067 } catch (NamingException ne) { 068 // failed, currencyChoices remains null, no default 069 } 070 } 071 } 072 073 public List<LabelValueBean> getCurrencyChoices() { 074 List<LabelValueBean> choices = null; 075 076 setupCurrencyChoices(); 077 if(currencyChoices != null) { 078 choices = convertChoices(currencyChoices); 079 } 080 081 return choices; 082 } 083 084 public void setCurrencyChoice(String currencyChoice) { 085 this.currencyChoice = currencyChoice; 086 } 087 088 public String getCurrencyChoice() { 089 setupCurrencyChoices(); 090 091 return currencyChoice; 092 } 093 094 private void setupDateTimeFormatChoices() { 095 if(dateTimeFormatChoices == null) { 096 try { 097 var commandForm = PartyUtil.getHome().getGetDateTimeFormatChoicesForm(); 098 099 commandForm.setDefaultDateTimeFormatChoice(dateTimeFormatChoice); 100 commandForm.setAllowNullChoice(String.valueOf(true)); 101 102 var commandResult = PartyUtil.getHome().getDateTimeFormatChoices(userVisitPK, commandForm); 103 var executionResult = commandResult.getExecutionResult(); 104 var getDateTimeFormatChoicesResult = (GetDateTimeFormatChoicesResult)executionResult.getResult(); 105 dateTimeFormatChoices = getDateTimeFormatChoicesResult.getDateTimeFormatChoices(); 106 107 if(dateTimeFormatChoice == null) { 108 dateTimeFormatChoice = dateTimeFormatChoices.getDefaultValue(); 109 } 110 } catch (NamingException ne) { 111 // failed, dateTimeFormatChoices remains null, no default 112 } 113 } 114 } 115 116 public List<LabelValueBean> getDateTimeFormatChoices() { 117 List<LabelValueBean> choices = null; 118 119 setupDateTimeFormatChoices(); 120 if(dateTimeFormatChoices != null) { 121 choices = convertChoices(dateTimeFormatChoices); 122 } 123 124 return choices; 125 } 126 127 public void setDateTimeFormatChoice(String dateTimeFormatChoice) { 128 this.dateTimeFormatChoice = dateTimeFormatChoice; 129 } 130 131 public String getDateTimeFormatChoice() { 132 setupDateTimeFormatChoices(); 133 134 return dateTimeFormatChoice; 135 } 136 137 private void setupLanguageChoices() { 138 if(languageChoices == null) { 139 try { 140 var commandForm = PartyUtil.getHome().getGetLanguageChoicesForm(); 141 142 commandForm.setDefaultLanguageChoice(languageChoice); 143 commandForm.setAllowNullChoice(String.valueOf(true)); 144 145 var commandResult = PartyUtil.getHome().getLanguageChoices(userVisitPK, commandForm); 146 var executionResult = commandResult.getExecutionResult(); 147 var getLanguageChoicesResult = (GetLanguageChoicesResult)executionResult.getResult(); 148 languageChoices = getLanguageChoicesResult.getLanguageChoices(); 149 150 if(languageChoice == null) { 151 languageChoice = languageChoices.getDefaultValue(); 152 } 153 } catch (NamingException ne) { 154 // failed, languageChoices remains null, no default 155 } 156 } 157 } 158 159 public List<LabelValueBean> getLanguageChoices() { 160 List<LabelValueBean> choices = null; 161 162 setupLanguageChoices(); 163 if(languageChoices != null) { 164 choices = convertChoices(languageChoices); 165 } 166 167 return choices; 168 } 169 170 public void setLanguageChoice(String languageChoice) { 171 this.languageChoice = languageChoice; 172 } 173 174 public String getLanguageChoice() { 175 setupLanguageChoices(); 176 177 return languageChoice; 178 } 179 180 private void setupTimeZoneChoices() { 181 if(timeZoneChoices == null) { 182 try { 183 var commandForm = PartyUtil.getHome().getGetTimeZoneChoicesForm(); 184 185 commandForm.setDefaultTimeZoneChoice(timeZoneChoice); 186 commandForm.setAllowNullChoice(String.valueOf(true)); 187 188 var commandResult = PartyUtil.getHome().getTimeZoneChoices(userVisitPK, commandForm); 189 var executionResult = commandResult.getExecutionResult(); 190 var getTimeZoneChoicesResult = (GetTimeZoneChoicesResult)executionResult.getResult(); 191 timeZoneChoices = getTimeZoneChoicesResult.getTimeZoneChoices(); 192 193 if(timeZoneChoice == null) { 194 timeZoneChoice = timeZoneChoices.getDefaultValue(); 195 } 196 } catch (NamingException ne) { 197 // failed, timeZoneChoices remains null, no default 198 } 199 } 200 } 201 202 public List<LabelValueBean> getTimeZoneChoices() { 203 List<LabelValueBean> choices = null; 204 205 setupTimeZoneChoices(); 206 if(timeZoneChoices != null) { 207 choices = convertChoices(timeZoneChoices); 208 } 209 210 return choices; 211 } 212 213 public void setTimeZoneChoice(String timeZoneChoice) { 214 this.timeZoneChoice = timeZoneChoice; 215 } 216 217 public String getTimeZoneChoice() { 218 setupTimeZoneChoices(); 219 220 return timeZoneChoice; 221 } 222 223}