0

I'm trying to create a webflow with a dynamic table on one page. Which looks like this

 def startFlow = {

    contact {
        on('next') {
            flow.developer = params.developer
            flow.project = params.project
            flow.division = params.division
            flow.projectResponsible = params.projectResponsible
            flow.email = params.email

            [flow : flow]
        }.to('ipcount')
        on('cancel').to('finish')
    }
    ipcount{
        on('next'){
            flow.ipcount = params.int('ipcount')

            [flow: flow]
        }.to('systems')
        on('cancel').to('finish')
    }
    systems{
        on('next') {
            flow.hoster= params.hoster
            flow.ip = params.ip
            flow.os = params.os
            flow.dns = params.dns
            flow.systemDate = params.systemDate

            [flow : flow]
        }.to('url')
        on('cancel').to('finish')
    } ....

The problem is I that the number of systems could be different every time (1...n). One idea was to ask the page before how many entries should be created (ipcount).

My view looks like this

  <g:set var="count" value="${flow.ipcount}" />
                 <g:each in="${(1..'${count}')}">
                  <tr class="prop">
                    <td valign="top" class="name">
                        <label for="ip">IP Adresse:</label>
                    </td>
                   <td valign="top">
                    <td valign="top" class="value ${hasErrors(bean:hosterInstance,field:'ip','errors')}">
                        <input type="text" id="ip" name="ip" value="${params.ip}" />
                    </td>
                    <td valign="top" class="name">
                        <label for="dns">DNS:</label>
                    </td>
                    <td valign="top">
                        <input type="text" id="dns" name="dns" value="${params.dns}" />
                    </td>
                    <td valign="top" class="name">
                        <label for="os">Operating System:</label>
                    </td>
                    <td valign="top">
                        <input type="text" id="dns" name="dns" value="${params.os}" />
                    </td>
                </tr>
               </g:each>

Beside that this is not working as I get an Internal server error: (java.lang.String cannot be cast to java.lang.Integer) it would be nicer if I could at the table row dynamically on the page. Here is the question: Is this possible with webflow and how? Especially I don't know how to handle the flow parameter and how to save the collected entries at the end of the webflow to the database.

4

1 回答 1

2

如果您需要使用对象列表,那么命令对象是您的最佳选择。它支持来自传入请求的数据绑定并将处理列表。

你可以检查一个相关的问题,告诉你如何去做。

在您看来,您将需要处理输入名称中的索引。例子:

考虑

class System {
  String ip
  String dns
  ...
}

commandInstance.systems一个List<System>

<g:each in="${commandInstance.systems}" var="command" status="i">

  <input type="text" id="ip$i" name="systems[$i].ip" value="${command.ip}" />

</g:each>
于 2013-10-09T13:28:42.423 回答