Question

We need to access an instance map defined in struts action class (it has get/set methods). We need to populated that map dynamically. We generate code to populate the map at runtime using a java script based on some user input. We are using freemarker as template.

Java script code within ftl looks like:

innerHTML += '<input class="isn" onChange="validateTag(this);" name="serialsInp[\'' + listing + '\']" value=""/>';

Here serialsInp is HashMap<String, String> and listing is java script variable. Above code renders a text field. The expectation is when user enters text in this text field, serialsInp should be populated with 'listing' as key and user entered value as value.

Is this the correct way of accessing maps in javascript/ftl?

Was it helpful?

Solution

Solved! The problem was form parameters. The map key in our case contains '-', which is disallowed due to security reasons.

The issue got resolved once we change 'params' interceptor to allow '-' in parameter names by adding following code in struts.xml

            <interceptor-ref name="params">
                <param name="acceptParamNames">\w+((\.\w+)|(\[\d+\])|(\['\w+(\-\w+)*'\]))*</param>
            </interceptor-ref>

Reference 202 & post

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top