2015-02-06 35 views
0

我正在編寫一個java spring mvc web應用程序,並且在客戶端,我使用bootstrap和星級評分插件來顯示我正在顯示的歌曲列表用戶。Spring MVC獲取onclick輸入星級評分值

我正在做的是傳遞我在會話中生成的播放列表,並在jsp中迭代此列表以創建適合正確的表。在歌曲名稱\標題的旁邊,我想顯示星級評分系統;我做到了,但它被設置爲輸入數字。我想要做的是,在星星點擊後,重定向到另一個頁面,在控制器中檢索速率,製作一些邏輯,然後返回沒有該歌曲的播放列表頁面。

我有一些困難,因爲在控制器上,爲了理解哪首歌得到了評價,我顯然必須將歌曲的id作爲輸入參數,所以輸入的名稱就像「input2838 「,但在控制器端,當我必須請求參數RequestParameter值時,我需要指定我想要的參數名稱,所以我認爲這不是正確的做法。

請問您對如何做這種東西的建議,而且,最重要的是,如何重定向到另一個頁面,傳遞參數的值,當我點擊輸入...

我向您展示jsp代碼片段,其中顯示了歌曲表。

<script>$("#input-id").rating();</script> <-- initialize the stars script 

<c:choose> <-- when the playlist is not empty show it 
    <c:when test="${not empty playlist}"> 
    <div class="container col-lg-10 col-lg-offset-1" > 
    <table class="table table-striped table-bordered table-hover"> 

     <thead> 
      <tr> 
       <th>#</th> 
       <th>Cover</th> 
       <th>Artista</th> 
       <th>Titolo</th> 
       <th>Rate</th> 
      </tr> 
     </thead> 

     <tbody> 

<c:forEach items="${playlist}" var="canzone" varStatus="count"> 
<tr style="font-weight: normal"> 
    <td style="font-weight: normal">${count.index +1}</td> 
    <td style="font-weight: normal"><img src="${canzone.albumImageUrl}" /></td> 
    <td style="font-weight: normal">${canzone.artistName}</td> 
    <td class="col-lg-4" style="font-weight: normal">${canzone.title}</td> 
<td class="col-lg-4" style="font-weight: normal"><div><input id="input-id" type="number" class="rating" min=0 max=5 step=1 data-size="xs" data-rtl="false"></div></td> 
     <tr> 
    </c:forEach> 
      </tbody> 

    </table> 
    </div> 
    </c:when> 
    <c:otherwise> 

現在我發佈你的完整性星級JS作爲引擎收錄鏈接的緣故:

Pastebin here

不要猶豫,問其他的相關信息。

回答

0

你的問題是,如果你得到所有的表指定爲id="sondId"name="sondId",並通過使用request.getParameter("songId")歌曲ID,它不會挑中的所有行的正確值堂妹將含有相同的ID和名稱。

所以你需要做的是裏面的<c:forEach>輸入,如下面

<c:forEach items="${playlist}" var="canzone" varStatus="count"> 
    <form action="yourActionPath" method="post"> 
     <tr style="font-weight: normal"> 
      <input type="hidden" id="songId" name="songId" value="${canzone.id}"/> 
      <td style="font-weight: normal">${count.index +1}</td> 
      <td style="font-weight: normal"><img src="${canzone.albumImageUrl}" /></td> 
      <td style="font-weight: normal">${canzone.artistName}</td> 
      <td class="col-lg-4" style="font-weight: normal">${canzone.title}</td> 
      <td class="col-lg-4" style="font-weight: normal"><div><input id="input-id" type="number" class="rating" min=0 max=5 step=1 data-size="xs" data-rtl="false"></div></td> 
     </tr> 
    </form> 
</c:forEach> 

你要如何到指定的星星之後提交表單,喜歡的onchange()或別的東西決定。這不是很好的選擇,但正是我所知道的..

+0

很遺憾一個表格不能插入tr標籤內... – lateralus 2015-02-06 10:30:00

+0

然後把表格放在標籤外面,更新我的答案,看看 – 2015-02-06 10:31:26

+0

它以某種方式告訴我它不能看到結束標記... http://pastebin.com/VF42RDbA – lateralus 2015-02-06 11:00:18