Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

java - How to make Struts radio tag create a vertical list of radio buttons

I'm using a struts radio tag that is being populated with a list of objects that have two fields:

class MyAction {
     List<MyObject> myList;
     String selectedId
     public String execute() {
         ...
         myList = new ArrayList<MyObject>();
         myList.add(new MyObject("1","first object");
         myList.add(new MyObject("2","second object");
         myList.add(new MyObject("3","second object");
         ...
     }

     // Getters and Setters for myList & selectedId
     ...
}

class MyObject {
    String id;
    String name;

    MyObject(String id, String name) {
         this.id = id;
         this.name = name;
    }
    // Getters and Setters for id & name
    ...
}

Here's what I was using on my page to display the list of radio buttons

<s:radio key="selectedId" list="myList" listKey="id" listValue="name"/>

However, this yields a horizontal list of radio buttons. I tried adding a css style to them:

<style>
    .vertical input { display: block; }
</style>

But this causes the labels and the radio buttons to show up on separate lines as well, instead of the radio button and label on the same line:

first object second object third object

what I want is:

first object second object third object
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

its actually simple, i mean use theme simple :)

<s:iterator value="myList"> 
  <s:radio theme="simple" name="someNameToSubmit" list="#{id:name}"/><br>
</s:iterator> 

This will make name as a label and id as the property to submit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...