开发者

how to pass model from view to controller in grails

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />         

    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><g:link class="create" action="index">Save</g:link></span>
            <span class="menuButton"><g:link class="create" action="index">Ca开发者_StackOverflowncel</g:link></span>
            <span class="menuButton"><g:link class="create" action="excelExport">Export To Excel</g:link></span>
        </div>
        <div class="body">
            <div class="message">Parsed Data:</div>
            <g:hasErrors bean="${savedCrInstance}">
            <div class="errors">
                <g:renderErrors bean="${savedCrInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <input type="hidden" name="id" value="${savedCrInstance?.id}" />
                <input type="hidden" name="version" value="${savedCrInstance?.version}" />
                <g:render template="company" model="['savedCrInstance':savedCrInstance,'customerInquiriesVal':customerInquiriesVal,'balanceStmtInfo':balanceStmtInfo,'incomeStmtInfo':incomeStmtInfo,'listofMeasures':listofMeasures]"/>
            </g:form>
        </div>
    </body>
</html>

The above GSP displays parsed data(from PDFs) to users. The user has options to save, cancel and export the parsed data to Excel.

On click of Excel Export, I want the savedCrInstance model(which I got from controller) to be passed to another controller, where I'll be exporting the data to excel as shown here.


First of all you need not use the export Functionality using workbooks and file etc.. as specified in the link Grails: How do I export a grails list to Microsoft Excel?.

Grails provide an export plugin which is very easy to use. Refer: http://www.grails.org/plugin/export

This case would involve an addition of an action class to the existing controller that will export the data to the excel


You could POST the data as JSON, or provide the controller with enough information to re-generate the model data on the server-side.

For example, if it's a domain class that you're exporting, you could just pass the id to the controller and have the controller fetch it from the database.

Another option would be to use WebFlow to implement this workflow, and flow-scope the model data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜