Метод контроллера не соединяется с моей страницей textit. jsp, на которой я использую jqgrid, вместо этого он вызывает диалог сохранения файла json окна? - PullRequest
0 голосов
/ 01 мая 2020

У меня есть этот метод контроллера:

 @RequestMapping("/singers")
@Controller
public class SingerController {
    @Autowired
    private SingerService singerService;

    @Autowired
    private MessageSource messageSource;

    @RequestMapping(value="/listgrid", method= RequestMethod.GET, produces="application/json")
    @ResponseBody
    public SingerGrid listGrid(@RequestParam(value = "page", required=false ) Integer page,
            @RequestParam(value = "rows", required=false) Integer rows,
            @RequestParam(value = "sidx", required=false) String sortBy,
            @RequestParam(value = "sord", required=false) String order){
        Sort sort = null;
        String orderBy = sortBy;
        if(orderBy != null && orderBy.equals("dateBirthString"))
            orderBy="birthDate";
        if(orderBy != null && order != null) {
            if(order.equals("desc")) {
                sort = Sort.by(Sort.Direction.DESC, orderBy);
            }else {
                sort = Sort.by(Sort.Direction.ASC, orderBy);
            }
        }
        PageRequest pageRequest = null;
        if(sort != null){
            pageRequest = PageRequest.of(page-1, rows, sort);
        }else {
            pageRequest = PageRequest.of(page-1, rows);
        }
        Page<Singer> singerPage = singerService.findAllByPage(pageRequest);
        SingerGrid singerGrid = new SingerGrid();
        singerGrid.setCurrentPage(singerPage.getNumber() + 1);

        singerGrid.setTotalPages(singerPage.getTotalPages());
        singerGrid.setTotalRecords(singerPage.getTotalElements());

        singerGrid.setSingerData(Lists.newArrayList(singerPage.iterator()));

        return singerGrid;}}

И я должен связать его с этим textit. jsp страница:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<%-- <head>
<title>List</title>
<spring:theme code = "styleSheet" var="app_css"/>
<spring:url value="/${app_css}" var="app_css_url"/>
<link rel="stylesheet" type="text/css" media="screen" href="${app_css_url}">
</head> --%>

<div>
    <spring:message code="label_singer_list" var="labelSingerList" />
    <spring:message code="label_singer_first_name"
        var="labelSingerFirstName" />
    <spring:message code="label_singer_last_name" var="labelSingerLastName" />
    <spring:message code="label_singer_birth_date"
        var="labelSingerBirthDate" />
     <spring:url value="/singers" var="showSingerUrl"/>

    <script type="text/javascript">
        $(function(){
            $("#list").jqGrid({
                url:'${showSingerUrl}/listgrid',
                datatype: 'json',
                mtype: 'GET',
                colNames:['${labelSingerFirstName}', '${labelSingerLastName}',
                    '${labelSingerBirthDate}'],
                colModel :[
                    {name:'firstName', index:'firstName', width:150},
                    {name:'lastName', index:'lastName', width:100},
                    {name:'birthDateString', index:'birthDate', width:100}
                ],
                jsonReader : {
                    root:"singerData",
                    page: "currentPage",
                    total: "totalPages",
                    records: "totalRecords",
                    repeatitems: false,
                    id: "id"
                },
                pager: '#pager',
                rowNum:10,
                rowList:[10,20,30],
                sortname: 'firstName',
                sortorder: 'asc',
                viewrecords: true,
                gridview: true,
                height: 250,
                width: 500,
                caption: '${labelSingerList}',
                onSelectRow: function(id){
                    document.location.href ="${showSingerUrl}/" + id;
                }
            });
        });
    </script>

    <c:if test="${not empty message}">
        <div id="message" class="${message.type}">${message.message}</div>
    </c:if>

    <h2>${labelSingerList}</h2>

    <div>
        <table id="list"><tr><td/></tr></table>
    </div>
    <div id="pager"></div>

</div>

Я использую плитки apache для подключите его по умолчанию. jsp, textit. jsp - это тело по умолчанию. jsp, которое выглядит следующим образом:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html SYSTEM "about:legacy-compat">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=8" />

    <spring:theme code="styleSheet" var="app_css" />
    <spring:url value="/${app_css}" var="app_css_url" />
    <link rel="stylesheet" type="text/css" media="screen" href="${app_css_url}" />

    <spring:url value="/resources/scripts/jquery-1.12.4.js" var="jquery_url" />
    <spring:url value="/resources/scripts/jquery-ui.min.js"
                var="jquery_ui_url" />
    <spring:url value="/resources/styles/custom-theme/jquery-ui.theme.min.css"
                var="jquery_ui_theme_css" />
    <link rel="stylesheet" type="text/css" media="screen" href="${jquery_ui_theme_css}" />
    <script src="${jquery_url}" type="text/javascript"><jsp:text/></script>
    <script src="${jquery_ui_url}" type="text/javascript"><jsp:text/></script>

    <!-- CKEditor -->
    <spring:url value="/resources/ckeditor/ckeditor.js" var="ckeditor_url" />
    <spring:url value="/resources/ckeditor/adapters/jquery.js" var="ckeditor_jquery_url" />
    <script type="text/javascript" src="${ckeditor_url}"><jsp:text/></script>
    <script type="text/javascript" src="${ckeditor_jquery_url}"><jsp:text/></script>

    <!--jqGrid-->
    <spring:url value="/resources/jqgrid/css/ui.jqgrid.css" var="jqgrid_css"/>
    <spring:url value="/resources/jqgrid/js/jquery-1.11.0.min.js" var="jqgrid_min_url"/>
    <spring:url value="/resources/jqgrid/js/i18n/grid.locale-en.js" var="jqgrid_locale_url"/>
    <spring:url value="/resources/jqgrid/js/jquery.jqGrid.min.js" var="jqgrid_url"/>
    <link rel="stylesheet" type="text/css" media="screen" href="${jqgrid_css}"/>
    <script type="text/javascript" src="${jqgrid_min_url}">
    <jsp:text/>
    </script>
    <script type="text/javascript" src="${jqgrid_locale_url}">
    <jsp:text/>
    </script>
    <script type="text/javascript">
        jQuery.jgrid.no_legacy_api = true;
    </script>
    <script type="text/javascript" src="${jqgrid_url}"><jsp:text/></script>

<!-- Get the user locale from the page context
    (it was set by Spring MVC's locale resolver) -->
<c:set var="userLocale">
    <c:set var="plocale">${pageContext.response.locale}</c:set>
    <c:out value="${fn:replace(plocale, '_', '-')}" default="en" />
</c:set>

<spring:message code="application_name" var="app_name"
    htmlEscape="false" />

<title><spring:message code="welcome_h3" arguments="${app_name}" />
</title>
</head>
<body class="tundra spring">
    <div id="headerWrapper">
        <tiles:insertAttribute name="header" ignore="true" />
    </div>
    <div id="wrapper">
        <tiles:insertAttribute name="menu" ignore="true" />
        <div id="main">
            <tiles:insertAttribute name="body" />
            <tiles:insertAttribute name="footer" ignore="true" />
        </div>
    </div>

</body>
</html>

textit. jsp должно быть включено http://localhost: 8081 / jelenaproject5 / singers / listgrid? Page = 1 & rows = 5 , но вот что я получаю: Сохранить json файл диалога

Как я могу это исправить

...