Package org.apache.struts.taglib.html

Examples of org.apache.struts.taglib.html.SelectTag


     *
     * @exception JspException if the scripting variable can not be found or if there is an error processing the tag
     */
    public final int doStartTag() throws JspException {
        try {
            SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);

            Object collection = RequestUtils.lookup(pageContext, name, property, null);
            Iterator it = getIterator(collection);

            JspWriter out = pageContext.getOut();
            StringBuffer sb = new StringBuffer();
            while (it.hasNext()) {
                Object next = it.next();
                String value = null;
                String key = null;
                if (next instanceof LabelValueBean) {
                    LabelValueBean bean = (LabelValueBean) next;
                    value = bean.getValue();
                    key = baseKey + '.' + bean.getLabel();
                } else {
                    value = String.valueOf(next);
                    key = baseKey + '.' + value;
                }

                String label = RequestUtils.message(pageContext, bundle, locale, key);
                addOption(sb, label, value, selectTag.isMatched(value));
            }

            out.write(sb.toString());

            return SKIP_BODY;
View Full Code Here


        support = new XPlannerTestSupport();
        support.setUpSubject(XPlannerTestSupport.DEFAULT_PERSON_USER_ID,new String[]{});
        authorizer = new MockAuthorizer();
        SystemAuthorizer.set(authorizer);
        ThreadSession.set(support.hibernateSession);
        SelectTag selectTag = new SelectTag();
        support.pageContext.setAttribute(Constants.SELECT_KEY, selectTag);
        tag.setPageContext(support.pageContext);
        tag.setAuthorizer(authorizer);
        tag.setSession(support.hibernateSession);
        tag.setLoggedInUserId(XPlannerTestSupport.DEFAULT_PERSON_ID);
View Full Code Here

    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    IDataComposer dataComposer = HDIVUtil.getDataComposer(request);

    // Acquire the select tag we are associated with
    SelectTag selectTag = (SelectTag) findAncestorWithClass(this, SelectTag.class);
    if (selectTag == null) {
      // This tag should only be nested in an select tag
      // If it's not, throw exception
      JspException e = new JspException(messages.getMessage("optionTag.select"));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    String cipheredValue = dataComposer.composeFormField(selectTag.getProperty(), value, false, null);

    // If there isn't any content in the body of the tag option, and there isn't
    // any value for the property key, the value of the property value is shown.
    // This is, the encoded value is shown. That is the reason why we store the
    // plain value, without encoding.
View Full Code Here

   *
   * @throws JspException
   */
  private SelectTag selectTag() throws JspException {

    SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);

    if (selectTag == null) {
      JspException e = new JspException(messages.getMessage("optionTag.select"));

      TagUtils.getInstance().saveException(pageContext, e);
View Full Code Here

     */
    protected void addOption(StringBuffer sb, String label, String value, boolean matched) {

        // Acquire the select tag we are associated with. If selectTag is null
    // super.doStartTag returns JspException before invoke this method.
        SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);           
     
        sb.append("<option value=\"");
       
        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    IDataComposer dataComposer = HDIVUtil.getDataComposer(request);
        String cipheredValue = dataComposer.composeFormField(selectTag.getProperty(), value, false, null);
       
        if (filter) {
            sb.append(TagUtils.getInstance().filter(cipheredValue));
        } else {
            sb.append(cipheredValue);
View Full Code Here

   * @param matched Should this value be marked as selected?
   * @see org.hdiv.dataComposer.IDataComposer#composeFormField(String, String, boolean, String)
   */
  protected void addOption(StringBuffer sb, String value, String label, boolean matched) {
   
    SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
   
    sb.append("<option value=\"");
    String cipheredValue = null;

    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    IDataComposer dataComposer = HDIVUtil.getDataComposer(request);
    cipheredValue = dataComposer.composeFormField(selectTag.getProperty(), value, false, null);

    if (filter) {
      sb.append(TagUtils.getInstance().filter(cipheredValue));
    } else {
      sb.append(cipheredValue);
View Full Code Here

     */
    @Override
    public int doEndTag() throws JspException {

        // Acquire the select tag we are associated with
        SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
        if (selectTag == null) {
            throw new JspException(messages.getMessage("optionsTag.select"));
        }
        StringBuilder sb = new StringBuilder();

        // If a collection was specified, use that mode to render options
        if (collection != null) {
            Iterator collIterator = getIterator(collection, null);
            while (collIterator.hasNext()) {

                Object bean = collIterator.next();
                Object value = null;
                Object label = null;

                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));
                }

                try {
                    if (labelProperty != null) {
                        label = PropertyUtils.getProperty(bean, labelProperty);
                    } else {
                        label = value;
                    }
                    if (label == null) {
                        label = "";
                    }
                } catch (IllegalAccessException e) {
                    throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
                } catch (InvocationTargetException e) {
                    Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
                } catch (NoSuchMethodException e) {
                    throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
                }

                String stringValue = value.toString();
                addOption(sb, stringValue, label.toString(), selectTag.isMatched(stringValue));

            }

        }

        // Otherwise, use the separate iterators mode to render options
        else {

            // Construct iterators for the values and labels collections
            Iterator valuesIterator = getIterator(name, property);
            Iterator labelsIterator = null;
            if ((labelName == null) && (labelProperty == null)) {
                labelsIterator = getIterator(name, property); // Same coll.
            } else {
                labelsIterator = getIterator(labelName, labelProperty);
            }

            // Render the options tags for each element of the values coll.
            while (valuesIterator.hasNext()) {
                String value = valuesIterator.next().toString();
                String label = value;
                if (labelsIterator.hasNext()) {
                    label = labelsIterator.next().toString();
                }
                addOption(sb, value, label, selectTag.isMatched(value));
            }
        }

        // Render this element to our writer
        ResponseUtils.write(pageContext, sb.toString());
View Full Code Here

TOP

Related Classes of org.apache.struts.taglib.html.SelectTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.