How to set value of one field as param while using remote link gsp

I am using gsp for the first time and i have a requirement to update a value when a button is clicked. For that I am using remote link.

I have the below textArea with id update_${test.id}

<g:textArea name="test" id="update_${test.id}" value="${test?.number}" disabled="${readonly ? true : false}" />

I need to be able to set the value of the param required to be the value inside the textArea.

<g:remoteLink action="updateTest" params="{required:\$('#update_${test.id}').val()}" update="updateOnClick" class="btn btn-default"><span class="icon-save"></span></g:remoteLink>

This is obviously a wrong approach. Could some one help me with this.

The following example uses ajax to pass all the form fields to the controller using serialize, you can pick out which ones you want in your action as we have done below by printing the value of the text area.

We then render some text which updates a div on screen.

Controller

class TestStuffController {

    def index(){}

    def myAction() {
        println params.myTextArea
        render 'Updated'
    }
}

index.gsp

<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main">
    <script type="text/javascript">
        $( document ).ready( function() {
            $( '#myButton' ).on( 'click' , function (event) {
                $.ajax({
                    url: "${g.createLink( controller: 'testStuff', action: 'myAction')}",
                    type: "POST",
                    data: $( "form" ).serialize(),
                    success: function ( data ) {
                        $( '#myDiv' ).html( data );
                    },
                    error: function( j, status, eThrown ) { console.log( 'Error ' + eThrown ) }
                });
            });
        });
    </script>
</head>
    <body>
        <div>
            <div id="myDiv"></div>

            <g:form id="myForm">
                <g:textArea name="myTextArea" id="myTextArea" />
                <button type="button" name="myButton" id="myButton">Update</button>
            </g:form>
        </div>
    </body>
</html>

The Definitive Guide to Grails, The changes in Listing 9-14 are in bold, where the code gets the <g: remoteLink> to update the surrounding bookmark div with the contents of the response. Now ifyou change the edit view (located at grails-app/views/bookmark/edit.gsp) to simply you can getyour inline editing fields to appear when the Edit link is clicked. If you have started using Invoke-Command, then you have ran into the issue of getting local variables into your remote commands. There is a lot of advice out there on how to do this and some approaches are more clunky than others.

Here is a g:link example passing a single name value pair. To add multiple just add a comma and the second name value pair inside the square brackets.

<g:link role="button" class="btn btn-success" action="details" params="${['folderNumber' : instance.fileFolderNumber]}" title="Details">Details</g:link>

Note that g:remoteLink is deprecated I have switched to using JQuery to do Ajax calls.

8 The Web Layer 2.4.2, defaultScope property set in grails-app/conf/Config.groovy with a value of "​singleton". def show() { def map = [book: Book.get(params.id)] render(view: "​display", be used to define a custom binding mechanism for a particular field in a class. GSP also features tags to help you manage linking to controllers and actions. Click the Select a Merge Code link below the Populate with the following field. Search for "URL variable" in the available search field The URL Variable merge code will return in the search results; click Insert ; the merge code will be inserted into the Populate with the following field:

Thank you for all the suggestions. This is what was required. I could reach my solution based on your suggestion.

    <g:javascript>
        function updateMethod(testId) {
            $.ajax({url: "${g.createLink( controller: 'testHandler', 
               action: 'testOnChange')}", 
               type: "POST",
               data: {'id': testId},
               success: function ( data ) {
                 $("#rowUpdated").show().delay(2500).fadeOut();
                 $("#updateFailed").hide();
              },
              error: function( j, status, eThrown ) {
                 $("#updateFailed").show().delay(2500).fadeOut();
                 $("#rowUpdated").hide();
                 console.log( 'Error ' + eThrown )
              }
           });
       }
    </g:javascript>
    <a href="javascript:void(0)" onclick="updateMethod('${test.id}');return false;" class="btn btn-default"><span class="icon-save"></span></a>

remoteFunction, Creates a remote JavaScript function that can be assigned to a DOM event to call Example as a method call in GSP only: Example changing the asynchronous option to false: <select from="[1,2,3,4,5]" onchange="${remoteFunction(action: action (optional) - the name of the action to use in the link; if not specified the  Whenever a parameter is modified using the ALTER SYSTEM statement, the Oracle Database records the statement that modifies the parameter in the alert log. The ALTER SESSION statement changes the value of the specified parameter for the duration of the session that invokes the statement.

submitToRemote, This tag creates a submit button that fires an AJAX request when it is pressed. either a map containing keys for the action, controller and id or a string value; value is automatically added so you don't have to provide one yourself in this string. after (optional) - The JavaScript function to call after the remote function call. set_param (Object,ParameterName,Value,ParameterNameN,ValueN) sets the parameter to the specified value on the specified model or block object. When you set multiple parameters on the same model or block, use a single set_param command with multiple pairs of ParameterName, Value arguments, rather than multiple set_param commands.

New Parameter, Hide/Show · Animation · Movement · Presentation · Sound · Link · Scroll This Number menu command creates a new parameter in your sketch. To change the value of a parameter, you can double-click it with the Arrow tool, use the Display Value: Set the initial value of the parameter by typing a value in this field. SET "Values with Spaces - using Double Quotes. There is no need to add quotation marks when assigning a value that includes spaces. SET _variable=one two three. For special characters like & you can surround the entire expression with quotation marks. The variable contents will not include the surrounding quotes: SET "_variable=one & two"

[PDF] GSP Virtual Server Handbook v4.1, Telnet in, either by clicking the Connect button or by entering the name of your remote host, which is your permanent domain name or temporary domain name. In the Mail Server (Incoming) field, enter the name of your ISP's POP mail If no argument Change the name of the Windows 98 default from New Value #1 to. Some of the parameters you’ve already seen in action, such as those related to running the workflow as a job. Remote access in workflows. One of the more interesting parameters is PSComputerName, which is used for connecting to a remote computer. You get a number of options. First option is to access the remote computer at the workflow level.

Comments
  • Are you just trying to send whatever is in the textArea to the updateTest action in your controller?
  • @MikeW Yes I am trying to do that. Please let me know how to do it :-)