我在servlet中遇到了一些麻烦,每当我在下拉菜单中更改选项时,不同的值将传递给servlet,然后导致无限循环.当我没有在下拉列表中更改选项(值没有变化)时,没有错误.
这是我的代码:
我的Javascript:
<script>
function loadStaff(){
//dropdown
var positionDropDown = document.getElementById("positionsDropdown");
//value of the drop down
var positionID = positionDropDown.options[positionDropDown.selectedIndex].value;
$.getJSON('loadStaff?positionID=' + positionID, function(data) {
-- no populate code yet
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的AjaxServlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userPath = request.getServletPath();
if (userPath.equals("/loadStaff")) {
String positionID = request.getParameter("positionID");
Position position = positionFacade.find(Integer.parseInt(positionID));
Collection staffCollection = position.getStaffCollection();
List<Staff> staffList = new ArrayList(staffCollection);
String staffListJson = new Gson().toJson(staffList);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(staffListJson);
}
}
Run Code Online (Sandbox Code Playgroud)
在debuggig.错误出现在:
String …Run Code Online (Sandbox Code Playgroud) 我有覆盖primefaces lazydatamodel加载的问题.加载方法的错误点.我正在使用primefaces 5.0.在Jboss Developer Studio 7.1中工作
private LazyDataModel<City> mdlCityList;
@PostConstruct
public void init() {
try {
this.mdlCityList = new LazyDataModel<City>() {
private static final long serialVersionUID = 1L;
@Override
public List<City> load(int first, int pageSize,
String sortField, SortOrder sortOrder,
Map<String, String> filters) {
mdlCityList.setRowCount(cityFacade.count(filters));
return cityFacade.getResultList(first, pageSize, sortField,
sortOrder, filters);
}
};
mdlCityList.setRowCount(cityFacade
.count(new HashMap<String, String>()));
} catch (Exception e) {
System.out.println("Exception in CityListProducer " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我正在实现@Override,但它仍然指出:
new LazyDataModel(){}类型的方法load(int,int,String,SortOrder,Map)必须覆盖或实现超类型方法