001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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.party.common.PartyUtil;
020import com.echothree.model.control.party.common.choice.LanguageChoicesBean;
021import java.util.List;
022import javax.naming.NamingException;
023import org.apache.struts.util.LabelValueBean;
024
025public class BaseLanguageActionForm
026        extends BaseActionForm {
027    
028    private LanguageChoicesBean languageChoices = null;
029    
030    private String languageChoice = null;
031    
032    private void setupLanguageChoices() {
033        if(languageChoices == null) {
034            try {
035                var commandForm = PartyUtil.getHome().getGetLanguageChoicesForm();
036                
037                commandForm.setDefaultLanguageChoice(languageChoice);
038                commandForm.setAllowNullChoice(String.valueOf(false));
039
040                var commandResult = PartyUtil.getHome().getLanguageChoices(userVisitPK, commandForm);
041                var executionResult = commandResult.getExecutionResult();
042                var getLanguageChoicesResult = executionResult.getResult();
043                languageChoices = getLanguageChoicesResult.getLanguageChoices();
044                
045                if(languageChoice == null) {
046                    languageChoice = languageChoices.getDefaultValue();
047                }
048            } catch (NamingException ne) {
049                // failed, languageChoices remains null, no default
050            }
051        }
052    }
053    
054    public List<LabelValueBean> getLanguageChoices() {
055        List<LabelValueBean> choices = null;
056        
057        setupLanguageChoices();
058        if(languageChoices != null) {
059            choices = convertChoices(languageChoices);
060        }
061        
062        return choices;
063    }
064    
065    public void setLanguageChoice(String languageChoice) {
066        this.languageChoice = languageChoice;
067    }
068    
069    public String getLanguageChoice() {
070        setupLanguageChoices();
071        
072        return languageChoice;
073    }
074    
075}