ajax - Liferay Content Update based on select component value -
i newbie liferay. have jsp page select element.
<aui:row> <aui:col span="3"> <label>optionspanel</label> </aui:col> <aui:col span="3"> <aui:form name="fm" id="fm"> <aui:select id="options" name="options" label=""> <aui:option value="option1" selected="true">option1</aui:option> <aui:option value="option2">option2</aui:option> </aui:select> </aui:form> </aui:col> </aui:row> <c:choose> <c:when test="${selectedoption eq 'option1'}"> <aui:row> <aui:col> option1 </aui:col> </aui:row> </c:when> <c:when test="${selectedoption eq 'option2'}"> <aui:row> <aui:col> option2 </aui:col> </aui:row> </c:when> </c:choose> i want dynamically display content based on value of selected option. nested inside <c:choose> , <aui:row> tags exists <aui:col></aui:col> element want container dynamic content.
based on this, have tried following solution:
@override public void serveresource(resourcerequest resourcerequest, resourceresponse resourceresponse) throws ioexception, portletexception { string action = resourcerequest.getparameter("action"); //load view folder content if (action.equals("view_content")) { include("/content.jsp", resourcerequest, resourceresponse, portletrequest.resource_phase); } } content.jsp
<c:choose> <c:when test="${selectedoption eq 'option1'}"> <aui:row> <aui:col> option1 </aui:col> </aui:row> </c:when> <c:when test="${selectedoption eq 'option2'}"> <aui:row> <aui:col> option2 </aui:col> </aui:row> </c:when> </c:choose> view.jsp
<portlet:resourceurl var="viewcontenturl"> <portlet:param name="action" value="view_content" /> </portlet:resourceurl> <div id="<portlet:namespace/>contentview"> <aui:row> <aui:col> option1 </aui:col> </aui:row> </div> <aui:script> function selectcontent() { aui().use('aui-base','aui-io-request', function(a){ var selectedvalue = a.one("#<portlet:namespace />options").get('value'); a.io.request('<%=viewcontenturl%>',{ datatype: 'json', method: 'post', form: {id: '<portlet:namespace />fm'}, data: {<portlet:namespace/>selectedoption: selectedvalue}, on: { failure: function() { alert('failure'); }, success: function(event, id, obj) { var instance = this; var message = instance.get('responsedata'); aui().one('#<portlet:namespace/>contentview').html(message); } } }); }); } </aui:script> however, not work , not want use separate jsp. need code in same jsp file.
Comments
Post a Comment