Results 1 to 7 of 7
  1. #1
    pbale is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Spring Form Tag Library <form:select> behaviour

    Hi,

    I wrote a form using Spring form tag library. My form has two <form:selects> one being a single select (i.e., device in my form) and other is a multiple select (i.e., port in my form)fields.
    When the form is submitted, the binding object has a single select form value as "formInput,0".
    Can any one help me why the binding object has returned a list of strings instead of a string.

    Here is my form:

    <form:form role="form" class="form-horizontal" modelAttribute="portStatistics" method="get" action="${servletPath}/lensapp/portstatistics/traffic">

    <div id="ipmac-device-form" class="well app-form-well">
    <div class="form-group">
    <form:label class="col-sm-3 control-label" path="device" for="device">Device</form:label>
    <div class="col-sm-4">
    <form:select path="device" for="device" targetId="portsField" class="updatePorts form-control">
    <form:option value="0" label="Select Switch"/>
    <form:options items="${devices}"/>
    </form:select>
    </div>
    </div>
    <div class="form-group">
    <form:label class="col-sm-3 control-label" path="ports" id="port-label">Port</form:label>
    <div class="col-sm-4" id="ports">
    <form:select path="ports" id="portsField" class="form-control multiPorts" multiple="true" name="portsTraffic">
    <form:option value="0" label="Select Port"/>
    </form:select>
    </div>
    </div>
    </div>
    <div class="form-group">
    <div class="col-sm-offset-3 col-sm-4">
    <button id="submit-ipmac" name="submit" type="submit" value="submit" class="btn btn-primary btn-sm launch-wait">Submit</button>
    </div>
    </div>

    </form:form>

    and the Controller looks like:

    @RequestMapping(value = "/traffic", method = RequestMethod.GET)
    public String getPortsTraffic(@ModelAttribute("portStatistics") PortStatistics portStatistics,BindingResult result,
    RedirectAttributes redirectAttributes,
    Model model) {


    logger.info("PORTSTATISTICS TRAFFIC: ");
    logger.info("PORTSTATISTICS DEVICE: "+ portStatistics.getDevice()); // this prints deviceName, 0

    logger.info("PORTSTATISTICS PORTS: "+ portStatistics.getPorts().toString());


    String port = portStatistics.getPorts().get(0);

    String device = portStatistics.getDevice();

    device = device.substring(0, device.indexOf(","));


    psrObj = psrServiceObj.getPortStatisticsByifcPortStatistics (device, port, startTime, endTime);

    logger.info("PORTTRAFFIC: "+ psrObj);

    return "portstatistics/traffic";
    }
    Please, can any one help me?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: Spring Form Tag Library <form:select> behaviour

    What does your PortStatistics class look like?
    Specifically what does getDeivce() return?
    If it's an object, then what does that class look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    pbale is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Spring Form Tag Library <form:select> behaviour

    getDevice() returns a String.

    Here is my PortStatistics Class:

    public class PortStatistics {

    private List<String> devices;
    private List<String> ports;
    private String device;
    private String port;

    public String getDevice() {
    return device;
    }

    public void setDevice(String device) {
    this.device = device;
    }
    public String getPort() {
    return port;
    }

    public void setPort(String port) {
    this.port = port;
    }

    public List<String> getDevices() {
    return devices;
    }

    public void setDevices(List<String> devices) {
    this.devices = devices;
    }

    public List<String> getPorts() {
    return ports;
    }

    public void setPorts(List<String> ports) {
    this.ports = ports;
    }
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: Spring Form Tag Library <form:select> behaviour

    OK.
    Nothing odd there.
    So what does the html produced by those Spring tags look like?

    Also, which value are you selecting?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: Spring Form Tag Library <form:select> behaviour

    Oh yes, and what version of Spring?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    pbale is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Spring Form Tag Library <form:select> behaviour

    I am selecting the device "sw-120emr" will make an ajax to get the ports for that device and display those ports in the form.
    BTW, I am using Spring mvc 3.2

    THe HTML looks like:

    <form id="portStatistics" class="form-horizontal" method="get" action="/lensapp/portstatistics/traffic" role="form">
    <div id="ipmac-device-form" class="well app-form-well">
    <div class="form-group">
    <label class="col-sm-3 control-label" for="device">Device</label>
    <div class="col-sm-4">
    <select id="device" class="updatePorts form-control" targetid="portsField" for="device" name="device">
    <option value="0">Select Switch</option>
    <option value="bc-cad">bc-cad</option>
    <option value="sw-120emr">sw-120emr</option>
    </select>
    </div>
    </div>
    <div class="form-group">
    <label id="port-label" class="col-sm-3 control-label" for="ports">Port</label>
    <div id="ports" class="col-sm-4">
    <select id="portsField" class="form-control multiPorts" multiple="multiple" name="ports">
    <option value="0">Select Port</option>
    <option value="1">1</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="bc-ad">bc-ad</option>
    <option value="sw-cad">swcad</option>
    <option value="lmp-40w">lmp-40w</option>
    </div>
    </div>
    //submit button
    </form>

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: Spring Form Tag Library <form:select> behaviour

    You'll have to debug the creation of that PortStatistics object.
    Those mappings, and the data, look OK to me, offhand.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. spring mvc form handing
    By BALUBALU in forum Spring
    Replies: 3
    Last Post: 08-08-2012, 06:01 PM
  2. how to retrieve data when i select the input from the form
    By sharanya in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-08-2011, 10:39 AM
  3. Replies: 10
    Last Post: 08-12-2009, 04:02 PM
  4. how select date form calendar to textFeild
    By the swan in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 12:16 PM
  5. how select date form calendar to textFeild
    By the swan in forum AWT / Swing
    Replies: 1
    Last Post: 03-31-2009, 06:59 PM

Posting Permissions

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