2012-10-08 111 views
0

我有一个列表,比方说,人员。每个人都有一个“朋友”的领域,可以是“是”或“否”。他们的“友谊”的状态呈现在一列在列表中:访问列表中的单个元素

<g:if test="${person.friend.status=='no' }"> 
<td><g:textField name="status" value="${person.friend.status}" readonly="readonly" style="width:60px;border:0px; background:transparent;color:black"/></td> 

     <td style="width:20px"> 
<g:actionSubmitImage action="acceptFriend" value="aceptar" src="${resource(dir: 'images', file: '/skin/tick_16.png')}" style="width:5px;height:8px;"/> 
     </td> 
     <td> 
     <g:actionSubmitImage action="refuseFriend" value="aceptar" src="${resource(dir: 'images', file: '/skin/wrong_16.png')}" style="width:5px;height:8px;"/>  
     </td>  
     </g:if> 

正如你可以看到,当朋友的状态是“不”,两个按钮呈现,一个说:“这个人是我的朋友”另一个说“这个人不是我的朋友”。我的问题是:

当我点击“这个人是我的朋友”的图片时,我称之为“接受朋友”的行为。但是,如何访问个人实例,将其状态更改为“是”,并坚持在数据库中?我认为它可能是“params”变量,但是如何将它存储在参数中以便在Controller中访问?

谢谢!

回答

1

我相信,你不能使用G:actionSubmitImage这样的,因为标签的文档中写到:

你不能在同一个表单中使用多个actionSubmitImage标签和有它在Internet Explorer 6或7的工作除非你添加一些自定义的JavaScript。请参阅此页获取更多信息和解决方法

正确的解决方案是在列表中每个朋友都有一个表单,然后您可以轻松传递域类的ID。

+0

我可以住在我们的页面不工作在IE 6或7 – Fustigador

+0

注意,它不仅是关于IE 6和7,但重要的是,你不能有超过1 g:actionSubmitImage 1格式。所以不幸的是它对你的用例没用。 –

+0

你是第一个,你接受了。但是,我必须说,我可以使用两个在相同的形式,他们的工作。我的错误是,参数领域以我认为不同的方式命名。但这两个actionSubmitImage工作完美... – Fustigador

1

actionSubmitImage以某种形式创建提交按钮。

在您正在迭代的列表中为每个person创建一个表单。

在该表单中,添加一个名为“id”的值为=“$ {person.id}”的隐藏字段,并在acceptFriend动作中从params.id中读取它。

0
<a href="${createLink(action: 'refuseFriend', id: person.id)}"><img src="${resource(dir: 'images', file: '/skin/wrong_16.png')}" style="width:5px;height:8px;" /></a> 

这是没有测试的代码,只是为了给你的想法。

0

汤姆·梅斯的要求,我张贴既克片段:actionSubmitImage标签工作:

<form> 
     <g:hiddenField name="contrato" value="${factura.id}"/> 
<td> <g:link title="${message(code :'contratosVer.tooltip')}" controller="campaign" action="show" id="${factura.id}" style="width:160px"> <g:img dir="images" file="/skin/eye_16.png"/></g:link> </td> 

     <td><g:textField name="campaign" value="${factura.nombre}" readonly="readonly" style="width:120px;border:0px; background:transparent;color:black"/></td> 

     <td><g:textField name="total" value="${factura.presupuestosPendientes.total}" readonly="readonly" style="width:40px;border:0px; background:transparent;color:black"/></td> 
      <g:if test="${factura.estado=='Espera'}"> 

         <td><g:textField name="estado" value="${factura.estado}" readonly="readonly" style="width:60px;border:0px; background:transparent;color:black"/></td> 


     <td style="width:20px"> 
     <g:actionSubmitImage action="aceptarCamp" value="aceptar" src="${resource(dir: 'images', file: '/skin/tick_16.png')}" style="width:5px;height:8px;"/> 
     </td> 
     <td> 
     <g:actionSubmitImage action="rechazarCamp" value="aceptar" src="${resource(dir: 'images', file: '/skin/wrong_16.png')}" style="width:5px;height:8px;"/>  
     </td>  
     </g:if> 
      <g:else> 

         <td><g:textField name="estado" value="${factura.estado}" readonly="readonly" style="width:65px;border:0px; background:transparent;color:black"/></td> 

         <td></td><td></td> 
      </g:else> 
     <g:set var="desc" value="${result.toString()}" /> 
     <g:if test="${desc.size() > 120}"><g:set var="desc" value="${desc[0..120] + '...'}" /></g:if> 
         </form> 

抱歉耽搁,队友,但我离开工作了三天。