如何使用spring处理动态表单输入

时间:2022-11-24 08:45:33

I have a dynamic form, which is used to save application settings for each company. As each company, has different settings, I have to generate the form dynamically.

我有一个动态表单,用于保存每个公司的应用程序设置。由于每个公司都有不同的设置,我必须动态生成表单。

<form:form id="update-user-form"
  action="${pageContext.request.contextPath}/add-app-settings"
  commandName="addApsTypeSetting" class="form-horizontal">
  <c:forEach var="key" items="${appTypeSettingsKey}">
      <%--                <a href="#panelDecription" style="cursor: pointer;">${key.setting_key}</a> --%>
      <div class="form-group">
          <label class="col-md-3 control-label"></label>

          <div class="col-md-9">
              <form:errors path="setting_key" cssClass="error" />
              <form:label path="setting_key" id="setting_key_error"
                  cssClass="error"></form:label>
          </div>
          <label class="col-md-3 control-label">${key.setting_key}</label>
          <div class="col-md-9">
              <form:input path="setting_key" cssClass="form-control" id=""
                  maxlength="50" />
          </div>
      </div>
  </c:forEach>
  <c:if test="${not empty appTypeSettingsKey}">
      <div class="form-group">
          <label class="col-md-3 control-label"></label>
          <div class="col-md-9">
              <div>
                  <!-- <a class="btn btn-primary m-r-5" style="float: right"
                      href="#modal-dialog" >Save</a> -->
                  <form:button>submit</form:button>
              </div>
          </div>
      </div>
  </c:if>
</form:form>

I have to deal with two database table, one is for generating the settings and otherone is for saving the settings values.

我必须处理两个数据库表,一个用于生成设置,另一个用于保存设置值。

Basically, I am trying to bing two objects to the form,One is to render the content and other object for saving the settings values. Can anybody help me to fix this issue? Do you need any information?

基本上,我试图将两个对象绑定到表单,一个是呈现内容和其他对象以保存设置值。有人可以帮我解决这个问题吗?你需要任何信息吗?

1 个解决方案

#1


0  

Why can't you use the same object for rendering create and retrieve the form information?

为什么不能使用相同的对象来渲染创建和检索表单信息?

I assume you have an object that store metadata that should be immutable in the form context, and another to store the form value. If that's true, you can load the metadata into an object, that is mutable and available for binding data from the form. Then you make it through.

我假设你有一个对象,它存储在表单上下文中应该是不可变的元数据,另一个存储表单值。如果这是真的,您可以将元数据加载到一个对象中,该对象是可变的,可用于绑定表单中的数据。然后你完成它。

#1


0  

Why can't you use the same object for rendering create and retrieve the form information?

为什么不能使用相同的对象来渲染创建和检索表单信息?

I assume you have an object that store metadata that should be immutable in the form context, and another to store the form value. If that's true, you can load the metadata into an object, that is mutable and available for binding data from the form. Then you make it through.

我假设你有一个对象,它存储在表单上下文中应该是不可变的元数据,另一个存储表单值。如果这是真的,您可以将元数据加载到一个对象中,该对象是可变的,可用于绑定表单中的数据。然后你完成它。