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