【问题标题】:Can I have more than 1 form action(form inside form) in single jsp using hibernate我可以使用hibernate在单个jsp中拥有超过1个表单操作(表单内的表单)吗
【发布时间】:2017-05-24 10:00:38
【问题描述】:

在这个jsp中,我使用了2个表单动作,一个用来保存角色(表:定义角色),另一个从其他表(表:solutionList)调用下拉列表。

点击提交后,它什么也没做。

如果我删除此表单(solutionMaster.html)

我收到此错误“ bean 类 [com.mode;.definingrole] 的无效属性 'sMName':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;
    }
}

定义角色.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;
    }

【问题讨论】:

  • 请帮助......这个代码卡了一天...... :(
  • 请说明您需要做什么?并提供您的控制器和模型的详细信息。形式中的形式没有任何意义。好像你的情况不是直截了当的。你必须绕道而行。
  • 我不明白为什么您需要select 列表的表单
  • 我在这里添加了控制器和模型。我将角色详细信息存储到数据库。我正在从其他表(解决方案列表)中获取下拉列表,基于下拉列表,我输入父角色和子角色,它将存储在定义角色(表)中 - @Zico
  • 根据w3.org/TR/xhtml1/#prohibitions 嵌套表单不是有效的 HTML

标签: spring forms hibernate jsp action


【解决方案1】:

您正在尝试在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>

【讨论】:

  • 嗨@Zico,我已经为此苦苦挣扎了2天。现在它的工作......谢谢。值被存储在定义角色表中,除了解决方案列表。因此,我已将选定的解决方案列表设置为定义角色模型的对象,如“value.setSolutions(sol.getSolutionName())”(SolutionList sol)。我在许多 jsp 中使用了两种形式来从其他表中获取下拉列表。这对于减少我的代码非常有用。非常感谢。
  • 接受为答案。谢谢@Zico
猜你喜欢
  • 2011-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-17
  • 1970-01-01
  • 2023-03-05
相关资源
最近更新 更多