0

I have a list of, let's say, persons. Every person has a field that is "friend", that could be "yes" or "no". Their "friendship" status is presented in a column in the list:

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

As you can see, when the friend status is "no", two buttons are presented, one to say "that person is my friend" and another one to say "this person is not my friend". My question is:

When i click on the image that says "this person is my friend", I call the action "acceptFriend". But, how to access to the indivivual person instance, to change his status to "yes", and persist in the database? I think it may be with the "params" variable, but how to store it in the params to be accessed in the Controller?

Thank you!

4

4 回答 4

1

I believe, you cannot use the g:actionSubmitImage like this, because in the tag's documentation is written:

You cannot use multiple actionSubmitImage tags within the same form and have it work in Internet Explorer 6 or 7 unless you add some custom JavaScript. See this page for a bit more information and a workaround.

The correct solution would be to have a form per friend in list and then you can easily pass the ID of the domain class.

于 2012-10-08T09:01:45.690 回答
1

The actionSubmitImage creates a submit button in some form.

Create the form for each person in the list you're iterating.

In that form, add a hidden field named "id" with a value="${person.id}", and in acceptFriend action read it from params.id.

于 2012-10-08T11:51:52.363 回答
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>

This is not tested code, just to give you the idea.

于 2012-10-08T12:25:31.290 回答
0

By request of Tom Metz, i post the snippet with both g:actionSubmitImage tags working:

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

Sorry for the delay, mate, but I was away from work for three days.

于 2012-10-15T07:33:07.990 回答