Skip to content

fix(sample): 목록 화면이 현재 페이지 번호를 상세·수정 경로로 넘기지 않는 문제 수정 - #73

Merged
jei007 merged 2 commits into
eGovFramework:mainfrom
wantaekchoi:fix/list-page-index-hidden
Sep 9, 2026
Merged

fix(sample): 목록 화면이 현재 페이지 번호를 상세·수정 경로로 넘기지 않는 문제 수정#73
jei007 merged 2 commits into
eGovFramework:mainfrom
wantaekchoi:fix/list-page-index-hidden

Conversation

@wantaekchoi

Copy link
Copy Markdown
Contributor

수정 사유 Reason for modification

소스를 수정한 사유가 무엇인지 체크해 주세요. Please check the reason you modified the source. ([X] X는 대문자여야 합니다.)

  • 버그수정 Bug fixes
  • 기능개선 Enhancements
  • 기능추가 Adding features
  • 기타 Others

수정된 소스 내용 Modified source

문제

egovSampleList.html 의 페이지 번호 히든 필드가 th:value="1" 로 고정돼 있습니다.

<input type="hidden" th:id="pageIndex" th:name="pageIndex" th:value="1" />

이 필드는 #listForm 안에 있고, 이 폼을 제출하는 함수는 sampleSearch·samplePagination·sampleCreate·sampleDetail 넷입니다. 이 중 값을 덮어쓰는 것은 samplePagination 뿐이라, 나머지 셋은 사용자가 몇 페이지를 보고 있든 pageIndex=1 을 보냅니다. 2페이지에서 ID 를 눌러 상세로 들어가면 상세 화면은 1페이지를 기억하고, 수정·삭제 완료 후 리다이렉트도 1페이지로 돌아갑니다.

받는 쪽은 반대로 페이지 번호를 지키도록 짜여 있습니다. EgovSampleController.updateSampleView 는 조회 결과에 요청값을 다시 심고(155행 detail.setPageIndex(sampleVO.getPageIndex())), updateSample(182행)·deleteSample(201행)은 redirectAttributespageIndex 를 실어 목록으로 돌려보냅니다. 같은 목적의 형제 템플릿 egovSampleRegister.html 82행의 히든 필드도 th:value="${sampleVO.pageIndex}" 입니다. 목록 폼 하나가 값을 버리는 바람에 그 세 곳이 전부 1만 왕복시키고 있었습니다.

같은 파일의 목록 순번 계산이 이미 sampleVO.pageIndex 를 현재 페이지로 쓰고 있어, 모델에는 값이 들어 있습니다.

<td class="text-center" th:text="${paginationInfo.totalRecordCount + 1 - ((sampleVO.pageIndex - 1) * sampleVO.pageSize + iterStat.count)}"></td>

변경

히든 필드를 모델 값에 연결했습니다.

-<input type="hidden" th:id="pageIndex" th:name="pageIndex" th:value="1" />
+<input type="hidden" th:id="pageIndex" th:name="pageIndex" th:value="${sampleVO.pageIndex}" />

검색은 결과 집합이 바뀌어 1페이지부터 봐야 하므로 sampleSearch 에서만 값을 1로 되돌립니다. samplePagination$('#pageIndex').val(pageIndex) 로 페이지 번호를 넣는 방식과 같습니다.

 		function sampleSearch() {
             if (notNullCheck($('#searchKeyword').val())) {
+				$('#pageIndex').val(1);
 				$('#listForm').attr('method', 'get').attr('action', contextPath + '/egovSampleList.do').submit();

영향 범위

목록에서 상세로 들어가는 경로, 그리고 수정·삭제 완료 후 목록으로 돌아오는 리다이렉트입니다. 2페이지에서 글을 고치면 이제 2페이지로 돌아옵니다. 페이징 이동과 검색은 지금과 같이 동작합니다.

검증

EgovSampleControllerTestSelectListTestpageIndex=2 로 목록을 조회해 렌더된 히든 필드가 2를 내보내는지 확인하는 테스트를 추가했습니다. 히든 필드 한 줄만 되돌려 가며 전체 스위트를 돌린 결과입니다.

상태 mvn test
수정 전 (테스트 추가 이전) Tests run: 54, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS
테스트 추가 + 수정 되돌림 Tests run: 55, Failures: 1, Errors: 0, Skipped: 0 — BUILD FAILURE
테스트 추가 + 수정 적용 Tests run: 55, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS

수정을 되돌렸을 때 실패하는 것은 추가한 테스트 하나뿐입니다.

[ERROR] egovframework.example.sample.web.EgovSampleControllerTestSelectListTest.test_목록조회_현재페이지_히든필드_유지 -- Time elapsed: 0.018 s <<< FAILURE!
java.lang.AssertionError: 
Expected: a string containing "name=\"pageIndex\" value=\"2\""
     but: was "<!DOCTYPE html>
[...]

JUnit 테스트 JUnit tests

테스트를 완료하셨으면 다음 항목에 [대문자X]로 표시해 주세요. When you're done testing, check the following items.

  • JUnit 테스트 JUnit tests
  • 수동 테스트 Manual testing

테스트 브라우저 Test Browser

테스트를 진행한 브라우저를 선택해 주세요. Please select the browser(s) you ran the test on. (다중 선택 가능 you can select multiple) [X] X는 대문자여야 합니다.

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera
  • Internet Explorer
  • 기타 Others

브라우저 대신 앱을 띄워 curl 로 응답 HTML 과 리다이렉트 헤더를 확인했습니다.

테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video

폼이 보내는 값이 상세 화면과 수정 완료 리다이렉트까지 그대로 이어지는 것을, 값만 바꿔 확인했습니다.

$ # 2페이지에서 ID 링크 클릭 — 수정 전 폼이 보내는 값(pageIndex=1)
$ curl -s -X POST http://localhost:18711/updateSampleView.do -d "id=SAMPLE-00104&pageIndex=1" | grep -n "name=\"pageIndex\""
82:	<input type="hidden" id="pageIndex" name="pageIndex" value="1" />

$ # 그 상세화면에서 수정 완료 시 리다이렉트 Location
$ curl -s -o /dev/null -D - -X POST http://localhost:18711/updateSample.do -d "id=SAMPLE-00104&name=n&description=d&useYn=Y&regUser=eGov&pageIndex=1" | grep -i "^location"
Location: http://localhost:18711/egovSampleList.do?searchCondition=&searchKeyword=&pageIndex=1

$ # 수정 후 폼이 보내는 값(pageIndex=2)
$ curl -s -X POST http://localhost:18711/updateSampleView.do -d "id=SAMPLE-00104&pageIndex=2" | grep -n "name=\"pageIndex\""
82:	<input type="hidden" id="pageIndex" name="pageIndex" value="2" />

$ curl -s -o /dev/null -D - -X POST http://localhost:18711/updateSample.do -d "id=SAMPLE-00104&name=n&description=d&useYn=Y&regUser=eGov&pageIndex=2" | grep -i "^location"
Location: http://localhost:18711/egovSampleList.do?searchCondition=&searchKeyword=&pageIndex=2

wantaekchoi and others added 2 commits September 9, 2026 14:53
egovSampleList.html 의 히든 필드가 th:value="1" 로 고정돼 있어 #listForm
을 제출하는 sampleSearch·sampleCreate·sampleDetail 세 함수가 언제나
pageIndex=1 을 보낸다. 2페이지에서 ID 링크를 눌러도 상세 화면은 1페이지를
기억하고, 수정·삭제 완료 리다이렉트도 1페이지로 돌아간다.

컨트롤러는 반대로 pageIndex 를 보존하도록 짜여 있다.
updateSampleView 는 조회 결과에 setPageIndex 로 요청값을 다시 심고,
updateSample·deleteSample 은 redirectAttributes 에 pageIndex 를 실어
보낸다. 형제 템플릿 egovSampleRegister.html 의 같은 히든 필드도
th:value="${sampleVO.pageIndex}" 다. 목록 폼만 값을 버리고 있었다.

히든 필드를 sampleVO.pageIndex 에 연결한다. 같은 파일 98행이 이미
sampleVO.pageIndex 를 현재 페이지로 보고 순번을 계산하므로 모델에는
값이 들어 있다. 검색은 결과가 바뀌어 1페이지부터 봐야 하므로
sampleSearch 에서 값을 1로 되돌리며, samplePagination 이 페이지 번호를
넣는 방식과 같다.

EgovSampleControllerTestSelectListTest 에 pageIndex=2 로 목록을 조회해
렌더된 히든 필드가 2를 내보내는지 확인하는 테스트를 추가했다.

@jei007 jei007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

표준프레임워크에 대한 지속적인 참여에
대단히 감사드립니다.

@jei007
jei007 merged commit 0ddced8 into eGovFramework:main Sep 9, 2026
1 check passed
@wantaekchoi
wantaekchoi deleted the fix/list-page-index-hidden branch September 9, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants