2015-08-03 37 views
0
//controller 
    @RequestMapping("/view") 
     public String viewEmpDetails(@RequestParam int emp_Id,@ModelAttribute Employee emp,Model model){ 
      emp=empService.getEmpDetails(emp_Id); 
      model.addAttribute("isView",true); 
      model.addAttribute("emp",emp); 
      model.addAttribute("readonly", true); 
      model.addAttribute("action","/getList"); 
       return "employee"; 
     } 
//jsp page 
    <td>First Name <span style="color:red;">*</span>:</td> 
     <td><form:input id="firstName" path="firstName" value="${emp.firstName}" readonly="true" /></td> 
     <td><input type="text" id="firstNameError" style="visibility:hidden;color:red"></td> 
    </tr> 
    <tr> 
     <td>Last Name :</td> 
     <td><form:input id="lastName" path="lastName" value="${emp.lastName}" readonly="true" /></td> 
     <td><input type="text" id="lastNameError" style="visibility:hidden;color:red"></td> 
    </tr> 

我只使用了1個jsp來執行視圖,如何在spring中只讀使用mvc

+1

請檢查下面的例子,讓我們知道你是否發現任何問題。 還有一點不要使用窗體:輸入標籤它很難使用。使用簡單的html 標籤。 –

回答

0

使用jQuery的:

$('#seclector_id').prop('disabled', true); 

$('#seclector_id').attr('disabled','disabled'); 

通過在JSP中檢查你的模型屬性:

model.addAttribute("readonly", true); 

只需添加下面一行在你的JSP網頁,並執行給定的檢查操作在jsFiddle示例中:

<input type="hidden" id="conditionCheck" value="${readonly}"/> 

jsFiddle

我希望這會工作。