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