Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:12:51+00:00 2026-06-05T09:12:51+00:00

My form has a list of items, and each item has a delete button.

  • 0

My form has a list of items, and each item has a delete button. I need to submit the index of the item to be deleted, along with the other values of the form (for further editing).

With JavaScript, it looks like this:

<g:form method="post" mapping="defaultAction" id="${paymentInstance?.id}">
    <g:hiddenField name="id" value="${paymentInstance?.id}"/>
    <g:hiddenField name="version" value="${paymentInstance?.version}"/>
    <g:hiddenField name="deleteAdjIdx"/>
    <g:each in="${paymentInstance?.adjustments}" var="adj" status="idx">
        <g:set var="adjName" value="adjustments[${idx}]"/>
        <g:textField name="${adjName}.dollars" value="${adj.dollars}"/>
        <g:actionSubmit action="deleteAdj" value="delete" onclick="jQuery('#deleteAdjIdx').val(${idx})"/>
    </g:each>
</g:form>

How can I do this without JavaScript? (Can I add a param to the URL, in addition to the posted params? Or, some kind of multiplex in the mapping?)

The defaultAction mapping is:

    name defaultAction: "/$controller/$id"{     // stable URL for payments regardless of current status (editable or not)
        constraints {
            id(matches: /\d+/)      // since our action names don't start with a digit but many domain ids do
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:12:53+00:00Added an answer on June 5, 2026 at 9:12 am

    I’m going to try adding params to the action name in an actionSubmit:

    <my:actionSubmit action="deleteAdj" value="delete" params="${[deleteAdjIdx: idx]})"/>
    

    I didn’t find a nice way to do this, so I came up with the following hack. If anyone knows of any improvements, I’d appreciate it.

    Added to MyTagLib:

    import org.codehaus.groovy.grails.web.util.WebUtils
    
    def actionSubmit = { attrs ->
        String action = attrs.action ?: attrs.value
        Map params = attrs.remove('params')
        if (params) {
            attrs.action = (action + WebUtils.toQueryString(params)).encodeAsURL()
        }
        out << g.actionSubmit(attrs)
    }
    

    I unpack the params and restore the original action name in a filter:

    package com.example;
    
    import javax.servlet.FilterChain;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    
    import org.springframework.web.filter.GenericFilterBean
    import org.codehaus.groovy.grails.web.util.WebUtils
    import com.example.util.MyWebUtils
    import javax.servlet.http.HttpServletRequest;
    
    /**
     * Handles params packed into the MyTagLib.actionSubmit param name.
     * This Filter needs to come before GrailsWebRequestFilter.
     * <p/>
     * Updating the GrailsParameterMap after the GrailsWebRequestFilter doesn't work,
     * because the request given to DefaultUrlMappingInfo.checkDispatchAction()
     * is the immutable request saved in the GrailsWebRequest, not the wrapped request
     * that this filter passes on down the chain.
     */
    public class ActionSubmitParamFilter extends GenericFilterBean {
    
        final static QUERY_SEPARATOR = '?'
        final static QUERY_SEPARATOR_REGEX = '[?]'
        final static PARAM_SEPARATOR_REGEX = '[&]'
    
        @Override
        void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
            def dispatchAction = request.parameterNames.find {it.startsWith(WebUtils.DISPATCH_ACTION_PARAMETER)}
            def decoded = dispatchAction?.decodeURL()
            if (decoded?.contains(QUERY_SEPARATOR)) {
                def overrides = unpackParams(decoded)
                overrides[dispatchAction] = null   // deletes from the overridden request params
                request = MyWebUtils.overrideParams((HttpServletRequest) request, overrides)
            }
            chain.doFilter(request, response);
        }
    
        private Map unpackParams(String decoded) {
            String action, paramsPart
            (action, paramsPart) = decoded.split(QUERY_SEPARATOR_REGEX)
            assert action.startsWith(WebUtils.DISPATCH_ACTION_PARAMETER)
            def packedParams = [:].withDefault {[]}
            packedParams[action] << ''
    
            for (param in paramsPart.split(PARAM_SEPARATOR_REGEX)) {
                if (param.contains('=')) {
                    def (name, value) = param.split('=')
                    packedParams[name.decodeURL()] << value.decodeURL()
                } else {
                    packedParams[param.decodeURL()] << ''
                }
            }
            packedParams
        }
    }
    

    I made utility methods to override the request params and configure the filter:

    package com.example.util
    
    import org.springframework.web.multipart.MultipartHttpServletRequest
    import javax.servlet.http.HttpServletRequest
    import javax.servlet.http.HttpServletRequestWrapper
    import groovy.util.slurpersupport.GPathResult
    import com.example.ActionSubmitParamFilter
    
    class MyWebUtils {
    
        static HttpServletRequest overrideParams(HttpServletRequest original, Map<String, List<String>> overrides) {
            assert !(original instanceof MultipartHttpServletRequest)   // if we get one of these, we'll need to use a special wrapper
    
            def params = (Map<String, String[]>) new HashMap(original.getParameterMap())
            overrides.each {k, v ->
                if (v == null) {
                    params.remove(k)    // significant for parameterNames enumeration and parameterMap
                } else {
                    params[k] = v as String[]
                }
            }
            params = Collections.unmodifiableMap(params)
            new HttpServletRequestWrapper(original) {
    
                @Override
                String[] getParameterValues(String name) {
                    params[name]
                }
    
                @Override
                String getParameter(String name) {
                    String[] values = params[name]
                    values ? values[0] : (values == null ? null : '')
                }
    
                @Override
                Map getParameterMap() {
                    params
                }
    
                @Override
                Enumeration getParameterNames() {
                    Collections.enumeration(params.keySet())
                }
            }
        }
    
    
        // used dynamically by _Events.eventWebXmlStart
        static void prependActionSubmitParamFilter(GPathResult webXml) {
    
            def filters = webXml.filter
            def filterMappings = webXml.'filter-mapping'
    
            def firstFilter = filters[0]
            def firstFilterMapping = filterMappings[0]
    
            firstFilter + {
                filter {
                    'filter-name'('actionSubmitParam')
                    'filter-class'(ActionSubmitParamFilter.name)
                }
            }
    
            firstFilterMapping + {
                'filter-mapping' {
                    'filter-name'('actionSubmitParam')
                    'url-pattern'("/*")
                    'dispatcher'("FORWARD")
                    'dispatcher'("REQUEST")
                }
            }
        }
    }
    

    Finally, I added the following to _Events.groovy to configure the filter in web.xml by extending ControllersGrailsPlugin.doWithWebDescriptor:

    eventWebXmlStart = {
    
        pluginManager.getGrailsPlugin('controllers').with {
            def originalClosure = instance.doWithWebDescriptor  // extending
            instance.doWithWebDescriptor = { GPathResult webXml ->
    
                // static import fails after clean (before compile), so load dynamically
                def webUtils = getClass().classLoader.loadClass('com.example.util.MyWebUtils')
                webUtils.prependActionSubmitParamFilter(webXml)
    
                // call super after (so above filter comes before GrailsWebRequestFilter in chain)
                originalClosure.resolveStrategy = Closure.DELEGATE_FIRST
                originalClosure.delegate = delegate
                originalClosure(webXml)
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is form with a list of items created dynamically in PHP, each has
I have a list of items and each item has a checkbox attached to
I've got a page with a list of some items. Each item has got
When I delete a category that has been unchecked form the list of checkboxes
I have a list of items. For each item there are sublists. It is
I have written a simple CRUD form which has one select list. However the
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
The ActiveScaffold list view has a search form that is loaded via ajax when
I am working on a jquery code that has a form country dropdown list
The mailing list form I am creating has the following fields: first name, last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.