Tuesday, April 28, 2015

Call Action URL using javascript function in Liferay

Sometimes we will get a requirement that we need to hit the "Action URL" using java script function.
May be my blog will be help you fot that requirement.

   <%
           PortletURL actionURL = renderResponse.createActionURL();
           actionURL.setParameter(ActionRequest.ACTION_NAME, "getPrice");
    %>
// creating action URL which will hit the Action method called "getPrice".

<aui:form name="fm" method="POST" >

<aui:input type="text" name="price" label=""  required="true"  onclick="getPrice()" inlineLabel="true">
                                    <aui:validator name="number"></aui:validator>
                                </aui:input>

<aui:button-row>
                    <aui:button type="submit" for="Submit" key="submit" value="Submit"/>                 </aui:button-row>
</aui:form>

// I have created one form with one text field  when i click that field i need to call getPrice action URL

<script>
        function getPrice() {
            document.<portlet:namespace/>fm.action = '<%=actionURL.toString()%>';
            document.<portlet:namespace/>fm.submit();
        }

    </script>

// The above javascript code is usefull  to hit the aciton URL with javascript function without clicking the submit button through javascript we are clicking the submit button.

Hope this is helpfull for you

No comments:

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...