Portlet namespace in Spring MVC forms on Liferay 6.2

Is there a way to get Spring MVC form names for portlets? I do not want to install

<requires-namespaced-parameters>false</requires-namespaced-parameters>

to get Spring mvc forms running under Liferay 6.2.

I was thinking of redefining Spring-taglib form so that it puts the portlet namespace prefix in front of the form field names / identifiers that are not actually trying to associate them with bean -properties with the namespace (which obviously won't work), but it seems very time consuming.

Does anyone know of a different way to solve this problem?

Here is an example form to show the exact problem:

<portlet:actionURL var="actionURL">
    <portlet:param name="action" value="search"/>
</portlet:actionURL>

<form:form action="${actionURL}" commandName="searchSettings">
    <form:input path="textField"/>
    <form:input path="anotherTextField"/>
    <input type="submit" value="Search"/>
</form:form>

And its corresponding bean will be:

public class SearchSettings {

    private String textField;
    private String anotherTextField;

    // .. getters & setters

}

This will not work in Liferay 6.2, since the input to the form is not replaced by names. They should be placed like this:

<c:set var="ns"><portlet:namespace/></c:set>

<form:input path="${ns}textField"/>

Spring

SearchSettings._namespace_portlet_textField

, , .

- , Spring MVCs Form-Taglib? , Spring JIRA (https://jira.springsource.org/browse/SPR-11176), .

.

+4
2

Spring taglib (3.0.7.RELEASE), . , Tag (, InputTag):

protected void writeDefaultAttributes(TagWriter tagWriter) throws JspException

, :

@Override
protected void writeDefaultAttributes(TagWriter tagWriter) throws JspException {
    writeOptionalAttribute(tagWriter, "name", getNamespace() + getName());
    writeOptionalAttribute(tagWriter, "id", getNamespace() + resolveId());
    super.writeDefaultAttributes(tagWriter);
}

, tagdescriptor, .

protected int writeTagContent(TagWriter tagWriter) throws JspException;

, writeDefaultAttributes.

, .

EDIT:

jQuery:

$(document).ready(function() {
    // Alle inputs
    $('input').each(function() {
        var pnamespace = '<portlet:namespace/>';
        $(this).attr('id', pnamespace + this.id);
        $(this).attr('name', pnamespace + this.name);
    });
    // alle selects
    $('select').each(function() {
        var pnamespace = '<portlet:namespace/>';
        $(this).attr('id', pnamespace + this.id);
        $(this).attr('name', pnamespace + this.name);
    });
});

. .

+1

aui tag. , , .

<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:actionURL var="saveChartURL" name="saveChart" />
<aui:form action='${saveChartURL}' method='post' name='form'>
<aui:button type='button' name='save' value="Save" />
<aui:input id='json'
            type='textarea'
            name='jsonData'
            label=''
            spellcheck='false'  
            cssClass='json'
            style='disply:none;' />
</aui:form>
<script>
(function(run){run(window.jQuery)}(
    function($){
        $(document).ready(function(){
            var pNS = '<portlet:namespace/>';   
            $('#'+pNS+'save').click(function(){      
                var dataserialized = $('#'+pNS+'form').serialize();
                $.post( "${saveChartURL}", dataserialized );
            });
        }); 
    })
);
</script>

....

@ActionMapping(value="saveChart")
public void saveChart( 
    @RequestParam(defaultValue="{}") String jsonData, 
    @RequestParam(defaultValue="doughnut2d") String chartType,
    PortletPreferences pp) {

    /* TODO do Action */
}
+1

Source: https://habr.com/ru/post/1527326/


All Articles