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.client.helper.NameSuffixesHelper;
020import com.echothree.control.user.party.client.helper.PersonalTitlesHelper;
021import com.echothree.model.control.party.common.choice.NameSuffixChoicesBean;
022import com.echothree.model.control.party.common.choice.PersonalTitleChoicesBean;
023import java.util.List;
024import javax.naming.NamingException;
025import org.apache.struts.util.LabelValueBean;
026
027public class BasePersonActionForm
028        extends BasePartyActionForm {
029    
030    private PersonalTitleChoicesBean personalTitleChoices = null;
031    private NameSuffixChoicesBean nameSuffixChoices = null;
032    
033    private String personalTitleChoice = null;
034    private String firstName = null;
035    private String middleName = null;
036    private String lastName = null;
037    private String nameSuffixChoice = null;
038    
039    /** Creates a new instance of BasePersonActionForm */
040    public BasePersonActionForm() {
041        super();
042    }
043    
044    private void setupPersonalTitleChoices() {
045        if(personalTitleChoices == null) {
046            try {
047                personalTitleChoices = PersonalTitlesHelper.getInstance().getPersonalTitleChoices(userVisitPK, Boolean.TRUE);
048
049                if(personalTitleChoice == null) {
050                    personalTitleChoice = personalTitleChoices == null ? null : personalTitleChoices.getDefaultValue();
051                }
052            } catch (NamingException ne) {
053                ne.printStackTrace();
054                // failed, personalTitleChoices remains null, no default
055            }
056        }
057    }
058    
059    private void setupNameSuffixChoices() {
060        if(nameSuffixChoices == null) {
061            try {
062                nameSuffixChoices = NameSuffixesHelper.getInstance().getNameSuffixChoices(userVisitPK, Boolean.TRUE);
063                
064                if(nameSuffixChoice == null) {
065                    nameSuffixChoice = nameSuffixChoices == null ? null : nameSuffixChoices.getDefaultValue();
066                }
067            } catch (NamingException ne) {
068                ne.printStackTrace();
069                // failed, nameSuffixChoices remains null, no default
070            }
071        }
072    }
073    
074    public List<LabelValueBean> getPersonalTitleChoices() {
075        List<LabelValueBean> choices = null;
076        
077        setupPersonalTitleChoices();
078        if(personalTitleChoices != null) {
079            choices = convertChoices(personalTitleChoices);
080        }
081        
082        return choices;
083    }
084    
085    public void setPersonalTitleChoice(String personalTitleChoice) {
086        this.personalTitleChoice = personalTitleChoice;
087    }
088    
089    public String getPersonalTitleChoice() {
090        setupPersonalTitleChoices();
091        
092        return personalTitleChoice;
093    }
094    
095    public void setFirstName(String firstName) {
096        this.firstName = firstName;
097    }
098    
099    public String getFirstName() {
100        return firstName;
101    }
102    
103    public void setMiddleName(String middleName) {
104        this.middleName = middleName;
105    }
106    
107    public String getMiddleName() {
108        return middleName;
109    }
110    
111    public void setLastName(String lastName) {
112        this.lastName = lastName;
113    }
114    
115    public String getLastName() {
116        return lastName;
117    }
118    
119    public List<LabelValueBean> getNameSuffixChoices() {
120        List<LabelValueBean> choices = null;
121        
122        setupNameSuffixChoices();
123        if(nameSuffixChoices != null) {
124            choices = convertChoices(nameSuffixChoices);
125        }
126        
127        return choices;
128    }
129    
130    public void setNameSuffixChoice(String nameSuffixChoice) {
131        this.nameSuffixChoice = nameSuffixChoice;
132    }
133    
134    public String getNameSuffixChoice() {
135        setupNameSuffixChoices();
136        
137        return nameSuffixChoice;
138    }
139    
140}