2011-06-29 41 views
0

我有一个像下面这样的GSP页面。这个要求就像一个报表列表 - 用户可以选择一个报表,并可以将报表导出为ex​​cel。如何阅读Grails中选定的单选按钮值?

如何读取所选的单选按钮并将所选值传递为“params”?

<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="excelExport" params="['id':{ radId.value}]">Export To Excel</g:link> 
     </span> 
    </div> 
    <div class="body"> 
     <div class="message">Select the report and click 'Excel Export'</div> 
    </div> 
    <g:form method="post"> 
     <g:render template="displayUploadedReportsTemplate" 
      model="['uploadedReports':uploadedReports]" /> 
    </g:form> 

</body> 
</html> 

其中displayUploadedReportsTemplate是:

<tbody> 
      <g:each in="${uploadedReports}" var="bbkRat"> 
       <tr> 
        <td valign="top"><g:radio name="radId" 
          value="${fieldValue(bean:bbkRat,field:'id')}" /></td> 
        <td valign="top"><label> ${fieldValue(bean:bbkRat,field:'cmpName')} 
        </label></td> 
        <td valign="top"><label> ${fieldValue(bean:bbkRat,field:'reportCreationDate')} 
        </label></td> 

        <%--<td valign="top"> 
        <label> ${fieldValue(bean:bbkRat,field:'cmpName')} 
       </label> 
       </td> 

       --%> 
       <tr> 
      </g:each> 

     </tbody> 

的PARAMS值如何应低于??

<g:link class="create" 
       action="excelExport" params="['id':{ radId.value}]"> 

回答

2

我会建议使用单选按钮组。而不是使用g:readio标签,您可以用每个标签内的纯html输入标签替换它。

<input type="radio" name="myGroup" value="1" checked="checked" /> 
<input type="radio" name="myGroup" value="2" /> 
<input type="radio" name="myGroup" value="3" /> 

您已经在displayUploadedReportsTemplate周围定义了一个表单。所以你需要在这个表单上添加一个提交按钮,并且在这个操作中应该传输参数,例如

<g:form method="post" action="test"> 

在测试行动中,您可以打印您的params.myGroup,您将收到选定的报告。

+0

的'导出到Excel'将充当我的提交按钮! – HanuAthena

+1

在你的情况下,我会更容易使用表单提交按钮。否则,像splix所说的,你必须使用java脚本。 – hitty5

0

<g:link在服务器端处理,所以你不能在客户端使用它,你必须使用JavaScript代替。

这将是这样的:

<a href="#" class="excelExport" onclick="doExport(); return false"> 
<script type="text/javascript"> 
function doExport() { 
    var id= $('input:radio[name=radId]:checked').val(); 
    window.location = '${g.createLink(action:'excelReport')}?id=' + id; 
} 
</script> 

PS我假设你正在使用jQuery