Home > Web Front-end > HTML Tutorial > Detailed explanation of the selected attribute when converting into in html

Detailed explanation of the selected attribute when converting into in html

黄舟
Release: 2017-07-03 10:08:49
Original
2047 people have browsed it

1. Concept introduction

The use of html tags in stust1, including html:select, html:option, details are as follows

<html:select property="test
String
" size="1">
    <html:option value="value1">Show Value1</html:option>
    <html:option value="value2">Show Value2</html:option>
    <html:option value="value3">Show Value3</html:option>
    <:html:submit property="submit" value="提交"/> </html:select>
Copy after login


Among them, property represents the corresponding property name in the selection list and ActionForm. When the user clicks submit, the value of the option selected by the user will be seen on the test page. The following is the running effect of the code:

Show Value1 Show Value2 Show Value3

has a size attribute, which means The number of options displayed at the same time. For example, if size is 1 in the above example, only one option will be displayed at the same time. There is also a multiple attribute. When it is true, the selection list allows multiple selections. Users can drag the mouse or hold down the Ctrl key to perform multiple selections.

The following is an example of multiple="true" and size="8"

value1 value2 value3 value4 value5 value6 value7 value8 value9 value10

When the multiple attribute is true, in The corresponding property in ActionForm should be an arraytype so that multiple values ​​selected by the user can be assigned to it at the same time.

tag is the option of the tag, each will be represented in the select box an option. The following code is shown:

<html:select property="testString" size="1">
    <html:option value="value1">Show Value1</html:option>
    <html:option value="value2">Show Value2</html:option>
    <html:option value="value3">Show Value3</html:option>
</html:select>
Copy after login


An option has two important parts. The first is the content it displays to the user, which can be specified in the following way:

    <html:option value="value1">Show Value1</html:option>
Copy after login

As can be seen, the part between two is used to represent the content the user sees. . Of course, you can also use the key and bundle attributes of to specify the content in the resource file to represent the content seen by the user. For the usage of bundle and key attributes, please refer to the relevant chapters of "Configuration File".

Another important content is the value it passes to ActionForm. This is specified by the tag's value attribute. As in the above example, the values ​​of value are value1, value2 and value3 respectively. When the user selects a certain tag, the JSP page will pass the value corresponding to the tag to the corresponding attribute in the ActionForm.

The following is the running effect:

Show Value1 Show Value2 Show Value3
Copy after login

2. Secrets that cannot be told

<html:option></html:option>转化成<option></option>时加了selected属性,RTFSC,看源码

if(selectTag().isMatched(value))
    results.append(" selected=\"selected\"");



public boolean isMatched(String value)
            {
/* <-MISALIGNED-> */ /* 126*/        if(match == null || value == null)
/* <-MISALIGNED-> */ /* 127*/            return false;
/* <-MISALIGNED-> */ /* 130*/        for(int i = 0; i < match.length; i++)
/* <-MISALIGNED-> */ /* 131*/            if(value.equals(match[i]))
/* <-MISALIGNED-> */ /* 132*/                return true;
/* <-MISALIGNED-> */ /* 135*/        return false;
            }



if(value != null)
                {/* 234*/            match = new String[1];
/* 235*/            match[0] = value;
                } else
                {
/* 238*/            Object bean = TagUtils.getInstance().lookup(super.pageContext, name, null);
/* 239*/            if(bean == null)
                    {/* 240*/                JspException e = new JspException(messages.getMessage("getter.bean", name));


/* 243*/                TagUtils.getInstance().saveException(super.pageContext, e);
/* 244*/                throw e;
                    }


/* 248*/            try
                    {
/* <-MISALIGNED-> */ /* 248*/                match = BeanUtils.getArrayProperty(bean, property);    //获取form中的select的value值
/* <-MISALIGNED-> */ /* 249*/                if(match == null)
/* <-MISALIGNED-> */ /* 250*/                    match = new String[0];
                    }
/* 254*/            catch(IllegalAccessException e)
                    {
/* <-MISALIGNED-> */ /* 254*/                TagUtils.getInstance().saveException(super.pageContext, e);
/* <-MISALIGNED-> */ /* 255*/                throw new JspException(messages.getMessage("getter.access", property, name));
                    }
Copy after login

3. Unsolved problems, how to set the default selection using html:option, there is no selected attributeDetailed explanation of the selected attribute when converting <html:option></html:option> into <option></option> in html



The above is the detailed content of Detailed explanation of the selected attribute when converting into in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template