您似乎根本没有意识到HTTP和Web应用程序是如何工作的。您必须了解请求/响应周期。
AJAX对您来说是您想做的事情的正确名称,但是正如名称所言,AJAX是异步 Javascript-
您尝试将java方法调用放在onchange属性中。这行不通。
要首先执行您要的操作,您必须找到您的Portlet类,并实现
serveResource(ResourceRequest req,ResourceResponse resp)方法,在该方法中您将收到选定的值(
String selectedVal =req.getParameter("selectedVal")),并根据该值返回一些值。String result = null; if ("blah".equals(selectedVal)) { result = "Something"; } else { result = "Something Else"; } resourceResponse.getPortletOutputStream().write(result.getBytes("UTF-8"));然后,您必须对该方法进行AJAX调用。应该大致如下所示:
<portlet:resourceUrl var="resourceUrl"><portlet:param name="selectedVal" value="PARAM_PLACEHOLDER_SELECTED_VAL" /></portlet:resourceUrl><aui:script use="io">function ajax<portlet:namespace />MySelect(selectedVal) { A.io( '${resourceUrl}'.replace("PARAM_PLACEHOLDER_SELECTED_VAL", selectedVal), { on: { success: <portlet:namespace />processResponse(select, response); } } );function <portlet:namespace />processResponse(response) {alert("Here's what java pre returned:"+response+". Do whatever you want with it - with javascript");}</aui:script>...<aui:select label="My Selection" name="ms" id="ms" onchange="ajax<portlet:namespace>MySelect(this.values[this.selectedIndex])" > <% for(String item : itemList){ %> <aui:option selected="<%= item.equals(selItem) %>" value="<%=item%>"><%=item%></aui:option> <%}%></aui:select>希望这可以帮助。



