1 19 20 21 package com.sslexplorer.core.forms; 22 23 import java.util.Collection ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.apache.struts.action.ActionErrors; 29 import org.apache.struts.action.ActionMapping; 30 31 import com.sslexplorer.core.DefaultPanel; 32 import com.sslexplorer.core.Panel; 33 import com.sslexplorer.core.PanelManager; 34 import com.sslexplorer.core.actions.AbstractMultiFormDispatchAction.SubActionWrapper; 35 import com.sslexplorer.tabs.TabModel; 36 37 public abstract class AbstractMultiFormDispatchForm extends CoreForm implements TabModel { 38 private Collection <SubActionWrapper> subActionWrappers_; 39 private List <Panel> panels_; 40 private String selectedTab_; 41 private String subForm_; 42 private final int placement_; 43 44 public AbstractMultiFormDispatchForm(int placement) { 45 placement_ = placement; 46 } 47 48 public void init(Collection <SubActionWrapper> subActionWrappers, ActionMapping mapping, HttpServletRequest request) { 49 subActionWrappers_ = subActionWrappers; 50 } 51 52 public void setSubForm(String subForm) { 53 subForm_ = subForm; 54 } 55 56 public String getSubForm() { 57 return subForm_; 58 } 59 60 public boolean isSubFormEmpty () { 61 return subForm_ == null || subForm_.length() == 0; 62 } 63 64 void resetForms(HttpServletRequest request) { 65 if (subActionWrappers_ != null) { 66 for (SubActionWrapper wrapper : subActionWrappers_) 67 wrapper.getForm().reset(wrapper.getMapping(), request); 68 } 69 } 70 71 public String getSelectedTab() { 72 return selectedTab_; 73 } 74 75 public int getTabCount() { 76 return panels_.size(); 77 } 78 79 public String getTabBundle(int idx) { 80 return ((Panel) panels_.get(idx)).getBundle(); 81 } 82 83 public String getTabName(int idx) { 84 return ((Panel) panels_.get(idx)).getId(); 85 } 86 87 public String getTabTitle(int idx) { 88 return null; 89 } 90 91 public void setSelectedTab(String selectedTab) { 92 selectedTab_ = selectedTab; 93 } 94 95 public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { 96 panels_ = getPannels(request); 97 resetForms(request); 98 } 99 100 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 101 ActionErrors allActionErrors = new ActionErrors(); 102 if (subActionWrappers_ != null) { 103 for (SubActionWrapper wrapper : subActionWrappers_) { 104 ActionErrors actionErrors = wrapper.getForm().validate(mapping, request); 105 if (null != actionErrors) 106 allActionErrors.add(actionErrors); 107 } 108 } 109 return allActionErrors; 110 } 111 112 public List <Panel> getPannels(HttpServletRequest request){ 113 return PanelManager.getInstance().getPanels(placement_, request, null, DefaultPanel.MAIN_LAYOUT); 114 } 115 } | Popular Tags |