在提交

时间:2015-05-13 14:42:02

标签: java javascript jquery jsp liferay-6

此代码在Liferay 6.1平台中完成。

描述:我有一个名为“商店名称”的下拉菜单。我将从下拉列表中选择任何一个值,并将该值传递给javascript函数“getStoreDetails”onchange。此函数的发送值将在javascript数组“lNames”中检查,如果此数组中存在值,则将获取索引并使用索引从“fNames”数组中获取值并添加到span类“FirstName”。我能够做到这一点,代码工作正常。

问题:我无法从jsp文件获取firstName值到submitIssue方法的Controller类。

这是我的Controller类

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>

我的javascript程序在单独的文件submitIssue.js

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

任何人都可以建议我获得这个价值。如果您不理解我的问题陈述,请发表评论。提前谢谢。

1 个答案:

答案 0 :(得分:0)

你能看到&#34; FirstName&#34;印在你的jsp?如果是,则需要在输入标记中传递此值,以便您可以期望此值出现在控制器中。希望这会有所帮助!!