简体   繁体   中英

struts2 displays Radio button in a text view

Am retrieving the gender from the list and displaying in a jsp page.It is displaying the values I stored in the list but not the Radio button. any help will be appreciated

<s:radio list="genderList" value="Gender" label="Gender"
                                  name="accountBean.gender"></s:radio>

DAO:

public ArrayList<String> getGender() {

    ArrayList<String> list=new ArrayList<String>();    
    list.add("Male");
    list.add("Female");
    return list;            
}

The output which am getting is:

Gender

Male Female

Expected output:

预期结果

嘿,您的代码是正确的,但是在Action类中创建一个名为“ genderList”的数组列表及其获取器/设置器,它将可以正常工作。

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
 <body>
<s:radio list="genderList" value="Gender" label="Gender"
                              name="accountBean.gender"></s:radio>

Action class :

package mypack;

import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;

public class FormAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    private List<String> genderList;

    @Override
    public String execute() throws Exception {
        genderList = new ArrayList<String>();
        genderList.add("Male");
        genderList.add("Female");
        return SUCCESS;
    }

    public List<String> getGenderList() {
        return genderList;
    }

    public void setGenderList(List<String> genderList) {
        this.genderList = genderList;
    }
}

This I have done I will be glad if it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM