0,0 → 1,71 |
// based on jakarta struts taglib |
package ak.hostadmiral.core.taglib; |
|
import java.lang.reflect.InvocationTargetException; |
import java.util.Iterator; |
|
import javax.servlet.jsp.JspException; |
|
import org.apache.commons.beanutils.PropertyUtils; |
import org.apache.struts.taglib.html.Constants; |
import org.apache.struts.taglib.html.SelectTag; |
import org.apache.struts.taglib.html.OptionsTag; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.ResponseUtils; |
|
import ak.hostadmiral.core.model.ModelObject; |
|
public class ModelObjectOptionsTag extends OptionsTag |
{ |
protected static MessageResources coreMessages = |
MessageResources.getMessageResources("ak.hostadmiral.core.CoreResources"); |
|
public int doEndTag() throws JspException |
{ |
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY); |
if (selectTag == null) { |
throw new JspException(messages.getMessage("optionsTag.select")); |
} |
StringBuffer sb = new StringBuffer(); |
|
if (collection != null) { |
Iterator collIterator = getIterator(collection, null); |
while (collIterator.hasNext()) { |
Object bean = collIterator.next(); |
Object value = null; |
|
if(!(bean instanceof ModelObject)) |
throw new JspException("Not a ModelObject"); |
|
ModelObject model = (ModelObject)bean; |
|
try { |
value = PropertyUtils.getProperty(bean, property); |
if (value == null) { |
value = ""; |
} |
} catch (IllegalAccessException e) { |
throw new JspException( |
messages.getMessage("getter.access", property, collection)); |
} catch (InvocationTargetException e) { |
Throwable t = e.getTargetException(); |
throw new JspException( |
messages.getMessage("getter.result", property, t.toString())); |
} catch (NoSuchMethodException e) { |
throw new JspException( |
messages.getMessage("getter.method", property, collection)); |
} |
|
String identKey = model.getIdentKey(); |
Object[] identParams = model.getIdentParams(); |
String label = coreMessages.getMessage(identKey, identParams); |
String stringValue = value.toString(); |
|
addOption(sb, stringValue, label, selectTag.isMatched(stringValue)); |
} |
} |
|
ResponseUtils.write(pageContext, sb.toString()); |
return EVAL_PAGE; |
} |
} |