grails - 在从不同的方法调用和验证表单后如何呈现文件(以一种方法调用)?

标签 grails groovy gsp

我们正在显示 gsp 中的文件。通过以下方式从后端提取文件:

看法

<table>
 <tr>
  <th>Attachment:
   <td>
    <g:each in="${lstAttachment}" var="nonOracleAttachmentItem">
     <g:link id="${nonOracleAttachmentItem.Id}" action="nonOracleAttachment" params="[nonOracleAttachmentItemId: nonOracleAttachmentItem.Id,nonOracleAttachmentItemName: nonOracleAttachmentItem.Name]">${nonOracleAttachmentItem.Name}</g:link><br/>
    </g:each>
  </td>
 </tr>
</table>

Controller
def show(){ 
     def strAttachmentsName = null;
    def boolAttachment = objChangeControl.Attachment__c
    def strOrcAttachmentName = objChangeControl.Attachment_Name__c

    if(strOrcAttachmentName !=null){
        def lstOracleAttachment = salesforceService.getSObjectList(SFDC_ORG, "SELECT Id,Name from Attachment where ParentId='${idG}' AND Name='$strOrcAttachmentName'")
        def lstAttachment = salesforceService.getSObjectList(SFDC_ORG, "SELECT Id,Name from Attachment where ParentId='${idG}' AND Name != '$strOrcAttachmentName'")
        def oracleAttachmentId = lstOracleAttachment[0].Id
        def oracleAttachmentName = lstOracleAttachment[0].Name
        [oracleAttachmentId:oracleAttachmentId, oracleAttachmentName: oracleAttachmentName,lstAttachment:lstAttachment,grcInstance: objGRCChangeControl,updatedRAIInstance: objUpdatedRAI, strConfigurationOwner:strConfigurationOwner,strGRCStatusCustomSetting:strGRCStatusCustomSetting,sfUserName: session["${SFDC_ORG}UserName"],sfUserId:sfUserId]
    }else{
        def lstAttachment = salesforceService.getSObjectList(SFDC_ORG, "SELECT Id,Name from Attachment where ParentId='${idG}'")
        [lstAttachment:lstAttachment,grcInstance: objGRCChangeControl,updatedRAIInstance: objUpdatedRAI, strConfigurationOwner:strConfigurationOwner,strGRCStatusCustomSetting:strGRCStatusCustomSetting,sfUserName: session["${SFDC_ORG}UserName"],sfUserId:sfUserId]
    }
}

这一切都很好,除非表单中的字段验证失败并且我们需要保留所有字段值以及最初显示的文件。这是显示错误并呈现用户在验证错误之前输入的值的 catch block (在按下“提交”按钮后调用的方法内)。我怎样才能渲染文件呢?
 def submitGRCRecord(){
   try{

......
}

         catch (Exception e){
            render(action:"show",model:[sfUserName: session["${SFDC_ORG}UserName"], sfUserId: session["${SFDC_ORG}UserId"],encodedId:encodedIdParam,grcInstance: getGRCRecord(),inputITGNumber:inputITGNumber,inputJustification:inputJustification,attmtChecked: 'true',lstAttachment:params['lstAttachment']])
    }

最佳答案

抱歉,如果这是非常基本的信息,但以下是此用例和解决方案的摘要,以供将来引用:

用户收到一封电子邮件,其中包含他们需要提供某些信息的表单的链接/URL。 URL 将始终采用以下格式:
例如。:
https://testchain.tstrandomurl.com/Folder1/show?encodedId=qwerty12345
该表单将显示数据库中记录中的一些现有信息。记录 id(唯一标识符)是从 URL 中的 encodedId 中提取的。现有的“信息”包括但不限于需要显示为可下载链接的一堆文件。

此外,该表单还有几个字段需要用户输入更改说明:- 长文本字段和其他相关附件:- 文件上传占位符。

变更说明有 256 个字符限制。可以多次访问同一记录,并且每次用户需要输入新的更改说明时,它都会计入包含先前输入的总字符限制。因此,当达到总字符数限制时,会使用 flash.message 将标准错误消息发送回 View 。此外,我们还进行了另一项检查,以对照数据库中预先存在的文件交叉检查附加相关附件的文件名。

在表单输入验证后发送错误消息时,需要在表单中保留所有原始值(上传的文件除外)。

这是通过使用带有 Action 、参数和模型的链方法来实现的,如下所示:chain(action:'show',params:[encodedId:encodedIdParam],model: [UserName: session["${ORG}UserName"], UserId: session["${ORG}UserId"] ,inputExplainChanges:inputExplainChanges])
使用链方法调用“显示”方法,该方法最初在表单中显示文件并通过模型保留用户输入:[..] 问题已解决。

关于grails - 在从不同的方法调用和验证表单后如何呈现文件(以一种方法调用)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28599336/

相关文章:

grails - 更改Grails的默认index.gsp页?

unit-testing - Grails test-app未执行语句

grails - 解析相关域对象的外键失败(obj.relatedId)

grails - 手动安装插件?

testing - Groovy 脚本错误 : No such property while parsing the json

grails - Json字符串超过524288异常

sorting - 如何对grails对象的persistentSet进行排序?

groovy - 如何在groovy中编写条件收集?

Grails:使用index.gsp中的 Controller

grails - Grails-Gsp如何使复选框组仅选择三个复选框中的一个