Results 1 to 3 of 3

Thread: Using <spring:bind> with radio buttons

  1. #1
    Join Date
    Apr 2006
    Posts
    6

    Default Using <spring:bind> with radio buttons

    Hi , I'm fairly new to Spring MVC .I'd like to bind 3 radio buttons in my jsp to some boolean values .Here's what I have and tried :

    My Command class
    ==============
    Code:
    public class MyCommand extends BaseCommand {
    
    
    	private MyVO filter;
    
    
    	public MyVO getFilter() {
    		return filter;
    	}
    
    	public void setFilter(MyVO filter) {
    		this.filter = filter;
    	}
    
    }

    My VO class
    =========

    Code:
    public class MyVO implements ValueObject {
    
    	private boolean createdBy = false;
    	
    	private boolean createdFor = false;
    	
    	private boolean participantOn = true;
    
    
    	public boolean getCreatedBy() {
    		return createdBy;
    	}
    
    	public void setCreatedBy(boolean createdBy) {
    		this.createdBy = createdBy;
    	}
    
    	public boolean getCreatedFor() {
    		return createdFor;
    	}
    
    	public void setCreatedFor(boolean createdFor) {
    		this.createdFor = createdFor;
    	}
    
    	public boolean getParticipantOn() {
    		return participantOn;
    	}
    
    	public void setParticipantOn(boolean participantOn) {
    		this.participantOn = participantOn;
    	}
    
    }

    and then in jsp i have the following :
    ============================

    Code:
    <spring:bind path="myCommand.filter">
    		       <input type="radio" name="radios"  value="${status.value}" />
    		       Created by
    		       <br>
    		       <input type="radio" name="radios" value="${status.value}"/>
    		       Created for
    		      <br>
    		      <input type="radio" name="radios" value="${status.value}"/>
    		      Participant on
    </spring:bind>


    How do I correctly wire the radio buttons to map to the boolean variables in my VO class , MyVO , i.e

    Code:
    private boolean createdBy = false;
    	
    private boolean createdFor = false;
    	
    private boolean participantOn = true;
    Thank you
    Last edited by ejbengine; Jul 9th, 2008 at 04:20 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    I think you shoud use checkbox instead of radio button. because you have 3 boolean values and if you use radio button you can only bind one field..

    also why dont you use the MyVO class as your command class?

  3. #3
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    lets say you used your MyCommand as the command object. then if you want to get values for your 3 boolean variables you might have to do like following.

    Code:
    <spring:nestedPath path="myCommand">
    
    <spring:nestedPath path="filter">
    <spring:bind path="createdBy"> <input type="checkbox" name="${status.expression}" <c:if test="${status.value}" > checked</c:if> /> Created by </spring:bind> <br> <spring:bind path="createdFor"> <input type="checkbox" name="${status.expression}" <c:if test="${status.value}" > checked</c:if> /> Created for </spring:bind> <br> <spring:bind path="participantOn"> <input type="checkbox" name="${status.expression}" <c:if test="${status.value}" > checked</c:if> /> Participant on </spring:bind>
    </spring:nestedPath>
    </spring:nestedPath>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •