2015-05-13 101 views
0

此代碼在Liferay 6.1平臺上運行。我無法將JSP頁面的值頁面提交給控制器類提交

描述:我有一個名稱爲「Store Name」的下拉菜單。我將從下拉列表中選擇任意一個值並將該值傳遞給JavaScript函數「getStoreDetails」onchange。這個函數發送的值將在javascript數組「lNames」中檢查,如果該數組中存在值,則將獲得索引,並使用索引從「fNames」數組中獲取值並添加到span類「FirstName」。我能夠做到這一點,代碼工作正常。

問題:我無法從jsp文件獲取FirstName值給Controller類的submitIssue方法。

這是我的控制器類

public class IssueController{ 

public String handleRenderRequest(RenderRequest request, RenderResponse response, Model model) throws Exception { 
HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); 

User user = PortalUtil.getUser(httpRequest); 

model.addAttribute("my_user", user); 

/*Some code goes here to set user attributes like department and organization using model object */ 

return "issue"; /*This is my jsp file mentioned below*/ 

} 

@ActionMapping 
public void submitIssue(@ModelAttribute IssueForm submitIssueForm, ActionRequest request, ActionResponse response) throws PortalException, SystemException, IOException, PortletException { 

     String First_Name=request.getParameter("FirstName"); 
     System.out.println("First Name while submitting is :\t"+First_Name); 

     /* here i am not able to obtain value of First_Name */ 
    } 

} 

下面的代碼是我issue.jsp文件

<div class="large-4 medium-8 small-12 columns"> 
       Store Name <select 
        class="no-highlight" id="StoreName_dropdown" 
        name="storeName" 
        onchange="getStoreDetails(this.value);" 

        <% 

        String stores[] = new String[] {"1021","1022","1023","1024","1025","1026","1027","1028","1029","1030"}; 

        for(int i=0;i<stores.length;i++){%> 

        <option value="<%=stores[i]%>"><%=stores[i]%></option> 

        <%}%> 

       </select> 
    </div> 
    <% 
    String fNames[] = new String[] {"John1021","wilson1022","test1023","test1024","test1025","test1026","test1027","test1028","test1029","test1030"}; 
     StringBuffer bufferfNames = new StringBuffer(); 
     bufferfNames.append("["); 
     for(int i=0; i<fNames.length; i++){ 

      bufferfNames.append("\"").append(fNames[i]).append("\""); 
       if(i+1 < fNames.length){ 
        bufferfNames.append(","); 
       } 
     } 
     bufferfNames.append("]"); 
     String First_Name=bufferfNames.toString(); 

     String lNames[] = new String[] {"1021","1022","1023","1024","1025","1026","1027","1028","1029","1030"}; 

     StringBuffer bufferlNames = new StringBuffer(); 
     bufferlNames.append("["); 
     for(int i=0; i<lNames.length; i++){ 

      bufferlNames.append("\"").append(lNames[i]).append("\""); 
       if(i+1 < lNames.length){ 
        bufferlNames.append(","); 
       } 
     } 
     bufferlNames.append("]"); 
     String Last_Name=bufferlNames.toString(); 
    %> 
    <div class="row "> 
      <div class="large-3 medium-4 columns"> 
       <span class="firstName">First Name : &nbsp;&nbsp; <span 
        class="hide-for-medium-up"><b>"dynamically name added"</b></span></span> 
       <div class="hide-for-small" id="FirstName" > 
        <b>"dynamically name added"</b> 
       </div> 
</div> 
</div> 

<div class="row "> 
     <div class="large-2 medium-3 columns"> 
       <button class="submitIssue submit_button" 
        id="submitIssue" tabIndex=9> 
        Submit 
       </button> 
     </div> 
</div> 

<script> 
function getStoreDetails(store) { 

    var fNames=<%=First_Name%>; 
    var lNames=<%=Last_Name%>; 
    var index; 

    index=lNames.indexOf(store); 

    if (index > -1) { 
     document.getElementById("FirstName").innerHTML = fNames[index]; 
    } 
    else{ 
     alert("Store is not present in lNames !!"); 
    } 
} 
</script> 

我在單獨的文件submitIssue.js JavaScript程序

$(document).ready(function() { 
     $('button.submitIssue').click(function(){ 
     $('#submitIssueForm').submit(); 
    }); 
}); 

任何人都可以建議我獲得這個價值。如果您還沒有理解我的問題陳述,請注意事項。提前致謝。

+0

我無法找到你把名字作爲請求參數的位置既沒有提交代碼(或按鈕) – jMounir

回答

0

你能看到「FirstName」打印在你的jsp中嗎?如果是的話,你需要在輸入標籤中傳遞這個值,以便你可以期待這個值進入你的控制器。希望這可以幫助!!

+0

每次我在下拉菜單中更改選項時,名字值都會改變。所以當我嘗試打印它時,它會在您的javascript變量上使用toString方法打印「null」 – user3534759

+0

。對於ex - lNames.toString()。indexOf(store.toString) – Ravi

+0

是的,我能夠看到我的JSP中的值。如果我按照你所說的那樣做,它將從具有多個名稱的數組lname中形成字符串。像String lNames [] = {「Name1」,「Name2」,「Name3」,「Name4」,「Name5」........「NameN」};我將在JSP中使用「index」顯示一個名稱,因此無論它打印什麼,我都必須將其讀取到Controller類。 – user3534759