2011-06-29 13 views
0

私は以下のようなGSPページを持っています。要件は、レポートのリストが表示されるようなものです。ユーザーは1つのレポートを選択するオプションがあり、レポートをExcelにエクスポートすることができます。Grailsで選択したラジオボタンの値を読み取る方法は?

選択したラジオボタンを読み取って、選択した値を「params」として渡す方法はありますか? displayUploadedReportsTemplateがある

<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> 

<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

を使用していることを前提とPS! – 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> 

私はあなたが ` Excelへのエクスポート は`私のsubmitボタンとして機能することになるjQueryの

関連する問題