1 18 package org.apache.beehive.netui.tags.databinding.datagrid; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.jsp.JspException ; 22 23 import org.apache.beehive.netui.tags.AbstractSimpleTag; 24 import org.apache.beehive.netui.tags.TagConfig; 25 import org.apache.beehive.netui.tags.javascript.ScriptRequestState; 26 import org.apache.beehive.netui.tags.html.Form; 27 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 28 import org.apache.beehive.netui.tags.rendering.AbstractHtmlControlState; 29 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel; 30 31 48 public abstract class AbstractDataGridHtmlTag 49 extends AbstractSimpleTag { 50 51 55 protected final DataGridTagModel lookupDataGridTagModel() { 56 return DataGridUtil.getDataGridTagModel(getJspContext()); 57 } 58 59 67 protected final void applyIndexedTagId(AbstractHtmlState state, String tagId) 68 throws JspException { 69 state.id = indexTagId(generateTagId(tagId)); 70 } 71 72 78 protected final void applyTagId(AbstractHtmlState state, String tagId) 79 throws JspException { 80 state.id = generateTagId(tagId); 81 } 82 83 89 private final String generateTagId(String tagId) 90 throws JspException { 91 return setRequiredValueAttribute(tagId, "tagId"); 92 } 93 94 101 private final String indexTagId(String tagId) { 102 DataGridTagModel dataGridTagModel = lookupDataGridTagModel(); 103 assert dataGridTagModel != null; 104 105 int index = dataGridTagModel.getCurrentIndex(); 106 assert index >= 0; 107 108 return tagId + index; 109 } 110 111 129 protected final String renderNameAndId(HttpServletRequest request, AbstractHtmlState state, Form parentForm) { 130 if (state.id == null) 132 return null; 133 134 boolean ctrlState = (state instanceof AbstractHtmlControlState); 136 137 if (parentForm != null && ctrlState) { 139 AbstractHtmlControlState hcs = (AbstractHtmlControlState) state; 140 if (hcs.name == null && parentForm.isFocusSet()) 141 hcs.name = state.id; 142 parentForm.addTagID(state.id, ((AbstractHtmlControlState) state).name); 143 } 144 145 String id = state.id; 147 state.id = getIdForTagId(id); 148 149 String idScript = null; 152 if (TagConfig.isLegacyJavaScript()) { 153 ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request); 154 if (!ctrlState) { 155 idScript = srs.mapLegacyTagId(getScriptReporter(), id, state.id); 156 } 157 else { 158 AbstractHtmlControlState cState = (AbstractHtmlControlState) state; 159 if (cState.name != null) 160 idScript = srs.mapLegacyTagId(getScriptReporter(), id, cState.name); 161 else 162 idScript = srs.mapLegacyTagId(getScriptReporter(), id, state.id); 163 } 164 } 165 166 String name = null; 168 if (ctrlState) { 169 AbstractHtmlControlState cState = (AbstractHtmlControlState) state; 170 name = cState.name; 171 } 172 173 String script = renderDefaultNameAndId((HttpServletRequest )request, state, id, name); 174 if (script != null) { 175 if (idScript != null) 176 idScript = idScript + script; 177 else idScript = script; 178 } 179 return idScript; 180 } 181 182 183 protected String renderDefaultNameAndId(HttpServletRequest request, AbstractHtmlState state, String id, String name) { 184 String script = null; 186 if (TagConfig.isDefaultJavaScript()) { 187 ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request); 188 script = srs.mapTagId(getScriptReporter(), id, state.id, name); 189 } 190 return script; 191 } 192 } 193 | Popular Tags |