Search code examples
liferayliferay-auiautofield

Auto fields liferay in custom portlet


I have a doubt.

I have a main.jsp that includes another 2 jsp and a submit button. Both of them are part of a form. The second one includes an auto field with a validator:

<div id="groupwork-fields" >
    <div class="lfr-form-row lfr-form-row-inline">
        <div class="row-fields">
            <aui:input fieldParam='name' id="repetibleName" cssClass="full-size"
                name="<%=AwardConstants.FIELD_OTHERS_NAME%>"
                label='<%=AwardConstants.LABEL_NAME %>'
                value="">
                <aui:validator name="custom" errorMessage="fill-name">
                        function (val, fieldNode, ruleValue) {
                            var result = true;
                                var selector = document.getElementById("<portlet:namespace/>select-group").value;
                                if (selector == 1 && val === "") {
                                    result = false;
                                }
                                return result;
                        }
                    </aui:validator>
                </aui:input>
                <aui:input cssClass="full-size"
                    id="email0" fieldParam='email0'
                    name="email0"
                    label='<%=AwardConstants.LABEL_EMAIL %>'
                    value="">
                    <aui:validator name="maxLength">100</aui:validator>
                    <aui:validator name="email"></aui:validator>
                    <aui:validator name="custom" errorMessage="fill-email">
                        function (val, fieldNode, ruleValue) {
                            var result = true;
                            var name = document.getElementById("<portlet:namespace/>name0").value;
                            if (name !== "" && val === "") {
                                    result = false;
                             }
                            return result;
                        }
                    </aui:validator>
            </aui:input>
        </div>
    </div>
</div>

After validating those fields and pressing the submit button goes to the next method:

public void saveAutofieldData(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException,  SystemException {

    String groupworkIndexes = actionRequest.getParameter("groupworkIndexes");
    _log.info("::::::::::::::::groupworkIndexes:::::::::::::::::::::::" + groupworkIndexes); 

    /**
     * Split the row index by comma
     */

    String[] indexOfRows = groupworkIndexes.split(",");
    _log.info("::::::::::::::::indexOfRows.length:::::::::::::::::::::::"+ indexOfRows.length);

    for (int i = 0; i < indexOfRows.length; i++) {

        String name = (actionRequest.getParameter("name"+ indexOfRows[i])).trim();
        String email = (actionRequest.getParameter("email"+ indexOfRows[i])).trim();
        _log.info("::::::::::::Name::::::::::::::" + name);
        _log.info("::::::::::::Email::::::::::::::" + email);
    }
}

The problem is when It tries to read: actionRequest.getParameter("groupworkIndexes"); I get null.

Thank you in advance


Solution

  • I finally got the solution. All examples I've seen it have been with "actionRequest" to retrieve the data:

        String groupworkIndexes = actionRequest.getParameter("groupworkIndexes");
        String name = actionRequest.getParameter("name" + indexOfRows[i]));
    

    But in my case i've used the following lines:

        String name = (uploadPortletRequest.getParameter("name" + indexOfRows[i]));
        String groupworkIndexes =  (uploadPortletRequest.getParameter("groupworkIndexes"));
    

    Not always we would get the prefered values with actionRequest