STRUTS2 the use of radio button labels S:radio and their settings default values

Source: Internet
Author: User

Http://www.itzhai.com/struts2-radio-button-label-s-radio-use-and-set-the-default-value.html

First, the Struts tag library is introduced in the page:

<%@ taglib prefix= "s" uri= "/struts-tags"%>

To create a radio button radio in a JSP page:

<s:radio list= "#{' 1 ': ' Mr. ', ' 0 ': ' Lady '}" name= "Gender" value= "1"/>

Where the key-value pairs in list represent all options, value represents the default value of the setting, and if this default is passed from the background, you can set it up:

<s:radio list= "#{' 1 ': ' Mr. ', ' 0 ': ' Lady '}" name= "Gender" value= "#{buyer_gender}"/>

Note that this is using the # symbol instead of $.

FUNI16: I wrote <s:radio list= "#{1: ' Recommended to peripheral personal module ', 0: ' Not recommended '}" Name= "Recommendenable" value= "recommendenable" ></s: Radio> Because the property I need is an integer type, so it doesn't have to be written in the form of a string, and I'm getting it is also an integer type, and recommendenable is the data I've got in the background, so write the value directly.

If the value is not obtained from the background, written as <s:radio list= "#{1: ' Recommended to peripheral personal module ', 0: ' Not recommended '} ' Name=" recommendenable "value=" 1 "></s:radio> You can default to 1. method to get the value of S:radio

S:radio is also very easy to obtain, if the action in Struts2 is directly using the label's Name property to obtain:

First declare a property named Radio name, and then add getter and Setter methods:

String gender;
Public String Getgender () {
	return gender;
}
public void Setgender (String gender) {
	this.gender = gender;
}

This allows you to get the selected value directly. (Select a value for the label of the list property of the key value pair, as in the above 1 or 0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.