如何使用带弹簧的taglib标签基于状态设置城市和邮政编码?

时间:2016-02-26 09:21:11

标签: javascript java jsp spring-mvc taglib

我正在使用spring mvc。还有田野,城市和乡村邮政编码分别。我的问题是当我在那个时候编辑州,城市& zipcode应显示其值。但是现在只显示状态。我想要所有三个字段值。请帮我。我在这里粘贴我的代码。提前谢谢。

This is my combineBean where Pojo is there with setter and getter.
package com.pharmacy.Bean;
import java.io.Serializable; 

@SuppressWarnings("serial")
public class CombineBean implements Serializable {
Pharmacy pharmacyPojo;
public Pharmacy getPharmacyPojo() {
    return pharmacyPojo;
}
public void setPharmacyPojo(Pharmacy pharmacyPojo) {
    this.pharmacyPojo = pharmacyPojo;
    }   
}

这是我的POJO课程。

package com.pharmacy.Bean;
@SuppressWarnings("serial")
@Entity
@Table(name = "pharmacy")
public class Pharmacy implements Serializable  {
@Column(name = "Pharmacy_City")
private String pharmacyCity;

@Column(name = "Pharmacy_State")
private String pharmacyState;


@Column(name = "Pharmacy_Zipcode")
private Integer pharmacyZipcode;


public Integer getPharmacyZipcode() {
    return pharmacyZipcode;
}

public void setPharmacyZipcode(Integer pharmacyZipcode) {
    this.pharmacyZipcode = pharmacyZipcode;
}

public String getPharmacyLicenseNo() {
    return pharmacyLicenseNo;
}

public String getPharmacyCity() {
    return pharmacyCity;
}

public void setPharmacyCity(String pharmacyCity) {
    this.pharmacyCity = pharmacyCity;
}

public String getPharmacyState() {
    return pharmacyState;
}

public void setPharmacyState(String pharmacyState) {
    this.pharmacyState = pharmacyState;
}

public String getPharmacyCountry() {
    return pharmacyCountry;
    }   
}

这是我的控制器。

public ModelAndView editPharmacyBo(@RequestParam("id") Long id, HttpServletRequest request) {
    ModelAndView mv = new ModelAndView("admin/addEditPharmacy");

    CombineBean comBean = new CombineBean();
    Pharmacy pharmacy = getPharmacyService().getPharmacyDetailsById(id);

    comBean.setPharmacyPojo(pharmacy);
    mv.addObject("combineBean", comBean);
return requiredHomeController(request, mv);
}

这是我的带有taglib标签的jsp页面。

<form:form  enctype="multipart/form-data" class="form-horizontal row-border"
                            commandName="combineBean"                        action="savePharmacy.htm" method="post">
<form:select path="pharmacyPojo.pharmacyState" name="state" id="state" class="form-control" onchange="changeCityByState(this.value)" style="margin-top: 0px;">
<option value="-1">Select State</option>
    <c:forEach items="${stateList}" var="data">
            <c:choose>
            <c:when test="${data == pharmacyPojo.pharmacyState}">
            <form:option value="${data}" selected="selected">${data}  </form:option>
                    </c:when>
                    <c:otherwise>
                    <form:option value="${data}">${data}
    </form:option>
    </c:otherwise> 
    </c:choose>
   </c:forEach>
  </form:select>
    <form:input type="text" path="pharmacyPojo.pharmacyCity" name="temp1" value="${pharmacyPojo.pharmacyCity}"/>
   <form:select path="pharmacyPojo.pharmacyCity" name="city" id="city" class="form-control" onchange="changeZipcodeByCity(this.value)" style="margin-top: 0px;">
<form:option value="-1" path="pharmacyPojo.pharmacyCity">Select City</form:option>
</form:select>                                  
<form:select path="pharmacyPojo.pharmacyZipcode" name="zipcode" id="zipcode" class="form-control" style="margin-top: 0px;">
    <form:option value="-1">Select Zipcode</form:option>
            </form:select>

这是我的javascript函数。

function changeCityByState(val)
{
$("#loading").fadeIn();
if(val != '-1')
    {
    dwrAdminCommand.getCityListByState(val,
            function(data1) {
                $("#loading").fadeOut();
                dwr.util.removeAllOptions('city');
                dwr.util.addOptions('city', [ {
                    id : '-1',
                    name : 'Select City'
                } ], "id", "name");
                dwr.util.addOptions('city', data1);
            });
    }
else
    {
    $("#loading").fadeOut();
    dwr.util.removeAllOptions('city');
    dwr.util.addOptions('city', [ {
        id : '-1',
        name : 'Select City'
    } ], "id", "name");

    dwr.util.removeAllOptions('zipcode');
    dwr.util.addOptions('zipcode', [ {
        id : '-1',
        name : 'Select Zipcode'
    } ], "id", "name");
    }
}

我必须做什么以及在哪里改变。我得到了状态完美,但没有城市和他们的邮政编码。请指导我。

0 个答案:

没有答案