2017-05-24 70 views
0

在這個jsp中,我使用了2個表單動作,一個保存角色(表:定義角色)和其他調用drop來自其他表格的列表(表格:solutionList)。我可以在單個jsp中使用休眠方式有多個表單動作(表單內部表單)

點擊提交後,它沒有做任何事情。

如果刪除此形式(solutionMaster.html)

即時得到bean類的這個錯誤「無效的屬性 'sMName'[com.mode; .definingrole]:Bean屬性 'sMName' 不是可讀或具有一個無效的getter方法:getter的返回類型是否與setter的參數類型相匹配?

是的,我知道原因,因爲列'sMName'不是定義角色表的一部分。與此

事情我想知道的是,

  1. 我們可以在窗體內創建窗體嗎?

2.沒有創建另一個表單,如何獲取其他表的列值來定義角色表?

請幫忙。

在此先感謝。

<div class="modal inmodal" id="myModalForRole" tabindex="-1" 
        role="dialog" aria-hidden="true"> 
        <div class="modal-dialog"> 
         <div class="modal-content animated bounceInRight"> 
          <div class="modal-header"> 
           <button type="button" class="close" data-dismiss="modal"> 
            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span> 
           </button> 
           <i class="fa fa-laptop modal-icon"></i> 
           <h4 class="modal-title">Define Role</h4> 

          </div> 
          <div class="modal-body"> 
           <form:form action="newRoleDetails.html" method="post" 
            commandName="deftemp" id="deftemp"> 
            <div class="row"> 
             <div class="form-group"> 
             <form:form action="solutionName.html" method="post" 
               commandName="soltemp" id="soltemp"> 
              <div class="col-sm-6"> 
               <label>Solutions*</label><br> 


               <form:select path="sMName" class="form-control" 
                id="sMName"> 
                <form:option value="" label="--select--"></form:option> 
                <c:forEach var="solutionList" items="${solutionList}" 
                 varStatus="loop"> 
                 <form:option value="${solutionList}" 
                  label="${solutionList}"> 
                 </form:option> 
                </c:forEach> 
               </form:select> 
              </div> 
              </form:form> 
             </div> 
            </div> 
            <div class="row"> 
             <div class="form-group"> 
              <div class="col-sm-6"> 
               <label>Parent Role*</label><br> 
               <form:textarea path="ParentRole" id="ParentRole" 
                class="form-control" placeholder="Enter the Parent Role" /> 
              </div> 
             </div> 
            </div> 
            <div class="row"> 
             <div class="form-group"> 
              <div class="col-sm-6"> 
               <label>Sub Role*</label><br> 
               <form:textarea path="SubRole" id="SubRole" 
                class="form-control" placeholder="Enter the Child role" /> 
              </div> 
             </div> 
            </div> 
            <br> 
            <br> 
            <div class="modal-footer"> 
             <button type="button" class="btn btn-white" 
              data-dismiss="modal">Close</button> 
             <button type="submit" class="btn btn-primary">Submit 
             </button> 
            </div> 
           </form:form> 
          </div> 

型號:(solutionlist.java)

package com.model; 

import java.io.Serializable; 
import java.text.SimpleDateFormat; 
import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 


@Entity 
@Table (name="solutionlist") 
public class solutionlist implements Serializable{ 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="solutionId",nullable = false,columnDefinition = "UNSIGNED INT(4)") 
    Integer solutionId; 

    @Column(name="solutionName") 
    String solutionName; 

    @Column(name="solutionOwner") 
    String solutionOwner; 

    @Column(name="ownerMailId") 
    String ownerMailId; 

    @Column(name="additionDate") 
    String additionDate; 

    public Integer getSolutionId() { 
     return solutionId; 
    } 

    public void setSolutionId(Integer solutionId) { 
     this.solutionId = solutionId; 
    } 

    public String getSolutionName() { 
     return solutionName; 
    } 

    public void setSolutionName(String solutionName) { 
     this.solutionName = solutionName; 
    } 

    public String getSolutionOwner() { 
     return solutionOwner; 
    } 

    public void setSolutionOwner(String solutionOwner) { 
     this.solutionOwner = solutionOwner; 
    } 

    public String getOwnerMailId() { 
     return ownerMailId; 
    } 

    public void setOwnerMailId(String ownerMailId) { 
     this.ownerMailId = ownerMailId; 
    } 

    public String getAdditionDate() { 
     return new SimpleDateFormat("yyyy-MM-dd HH-mm-ss.SSS") 
     .format(new Date()); 
    } 

    public void setAdditionDate(String additionDate) { 
     this.additionDate = additionDate; 
    } 
} 

definingrole.java

package com.model; 

import java.io.Serializable; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 


@Entity 
@Table(name="definingrole") 
public class definingrole implements Serializable{ 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="SNo") 
    Integer SNo; 

    @Column(name="Solutions") 
    String Solutions; 

    @Column(name="ParentRole") 
    String ParentRole; 

    @Column(name="SubRole") 
    String SubRole; 

    public Integer getSNo() { 
     return SNo; 
    } 

    public void setSNo(Integer sNo) { 
     SNo = sNo; 
    } 

    public String getSolutions() { 
     return Solutions; 
    } 

    public void setSolutions(String solutions) { 
     Solutions = solutions; 
    } 

    public String getParentRole() { 
     return ParentRole; 
    } 

    public void setParentRole(String parentRole) { 
     ParentRole = parentRole; 
    } 

    public String getSubRole() { 
     return SubRole; 
    } 

    public void setSubRole(String subRole) { 
     SubRole = subRole; 
    } 
} 

控制器:newRoleDetails.html

@RequestMapping(value=NEWROLEDETAILS_PATH) 
    public String newRoleDetails(Map<String, Object> model, definingrole value,solutionlist sol) throws Exception { 
     Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
     String name = auth.getName(); 
     String nameOfUser=TemplateService.getEmpNameOfUser(name); 
     model.put("nameOfUser",nameOfUser); 
     String userid=loginService.getUserId(); 
     String role=loginService.getRole(); 

     TemplateService.newRoleDetails(value); 
     definingrole deftemp=new definingrole(); 
     model.put("deftemp", deftemp); 
     solutionlist s = new solutionlist(); 

     ArrayList<templateDetails> listOfTemplate=TemplateService.listTemplateDetails(role,userid); 
     model.put("listOfTemplate",listOfTemplate); 
      return TEMPLATESUMMARY; 
    } 

控制器:solutionName.html

@RequestMapping("/solutionlist.html") 
    public String solutionName(Map<String, Object> model,solutionlist sol) throws Exception { 
     Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
     String name = auth.getName(); 
     String nameOfUser=TemplateService.getEmpNameOfUser(name); 
     model.put("nameOfUser",nameOfUser); 
     solutionlist soltemp = new solutionlist(); 
     model.put("soltemp", soltemp); 
     ArrayList<String> solutionList=TemplateService.getSolutionListForTemplate(); 
     model.put("solutionList", solutionList); 
     return REDIRECT_TEMPLATESUMMARY_URL; 
    } 
+0

請幫助......這個代碼每天滯留..... :( –

+0

請解釋一下你是什麼需要做什麼?給你的控制器和模型的細節。在內部形成形式沒有任何意義。看起來像你的情況是不是直線前進。你必須使周圍的一種方式。 – Zico

+0

我不明白爲什麼點你需要爲'select'名單 – Zico

回答

2

您正在嘗試在form的標記下填充表單內的列表。哪種方法是錯誤的。您的form將不會從/solutionlist.html獲得價值。如果您想使用/solutionlist.html控制器,則必須至少撥打GET

如果我想是這樣,那麼你必須做到以下幾點

  1. 你不需要「/solutionlist.html」控制器。
  2. 只需將ArrayList solutionList綁定到提供表單頁的控制器方法中的模型中即可。我的意思是給定表格的Controller的GET方法。

    ArrayList<String> solutionList=TemplateService.getSolutionListForTemplate(); model.put("solutionList", solutionList);

  3. 你會得到solutionList直接向您的形式價值。因此,修改形式的select部分如下

    <select name="solutions"path="Solutions"> <c:forEach items="${solutionList}" var="solution"> <option value="${solution}">${solution}</option> </c:forEach> </select>

+0

嗨@Zico,我一直在爲此掙扎2天。現在它的工作......謝謝。除了solutionList之外,值都存儲在定義角色表中。因此,我已將所選解決方案列表設置爲DefinitionRole模型的對象,如「value.setSolutions(sol.getSolutionName())」(SolutionList sol)。我在許多jsp中使用了兩種形式從其他表中獲取droplist。這對於減少我的代碼非常有用。非常感謝你。 –

+0

如何將其標記爲正確或投票? – Zico

+0

已接受爲答覆。謝謝@Zico –