[Ajax4JSF] <:selectOneMenu>的<a4j:support event="onchange" 没有响
lywzj2008
2009-03-21
源码是这样的,
<h:panelGroup> <h:selectOneMenu id="selectParameter" value="#{bean.parameterName}" > <a4j:support event="onchange" action="#{bean.doSpcCalc}"></a4j:support> <f:selectItems id="parameterValue" value="#{bean.parameters}" /> </h:selectOneMenu> </h:panelGroup> 后台: String parameterName; //seter ,geter public void doSpcCalc() { ... }; public List<SelectItem> getParameters() { List<SelectItem> items = new ArrayList<SelectItem>(); for (String param : hash.keySet()) { items.add(new SelectItem(param)); } return items; } onchang事件没有响应。当select 的值改变时。 |
|
terryzhou
2009-03-21
try actionListener
|
|
lywzj2008
2009-03-23
thank you very much! I try,
|
|
sailing19
2009-07-16
actionListener可以实现,但是用action也没有什么错。现在我碰到一个类似的问题。先看一个示例,我从网上找的:
package net.moon.jsf.bean; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; public class DemoBean { private List<SelectItem> provinces = new ArrayList<SelectItem>(); private List<SelectItem> cities = new ArrayList<SelectItem>(); private String province; private String city; public List<SelectItem> getPrivinces() { return provinces; } public void setPrivinces(List<SelectItem> privinces) { this.provinces = privinces; } public List<SelectItem> getCities() { return cities; } public void setCities(List<SelectItem> cities) { this.cities = cities; } public String getPrivince() { return province; } public void setPrivince(String privince) { this.province = privince; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public DemoBean() { super(); provinces.add(new SelectItem("")); provinces.add(new SelectItem("北京")); provinces.add(new SelectItem("上海")); // TODO Auto-generated constructor stub } public String refreshCities() { cities.clear(); if (("北京").equals(province)) { cities.add(new SelectItem("东城区", "东城区")); cities.add(new SelectItem("西城区", "西城区")); cities.add(new SelectItem("崇文区", "崇文区")); } if ("上海".equals(province)) { cities.add(new SelectItem("黄浦区", "黄浦区")); cities.add(new SelectItem("卢湾区", "卢湾区")); cities.add(new SelectItem("徐汇区", "徐汇区")); } return null; } } <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <f:view> <h:form> <h:selectOneMenu id="privince" value="#{demoBean.privince}"> <f:selectItems value="#{demoBean.privinces}"/> <a4j:support action="#{demoBean.refreshCities}" event="onchange" reRender="city"></a4j:support> </h:selectOneMenu> <h:selectOneMenu id="city" value="#{demoBean.city}"> <f:selectItems value="#{demoBean.cities}"/> </h:selectOneMenu> </h:form> </f:view> </body> </html> <managed-bean> <managed-bean-name>demoBean</managed-bean-name> <managed-bean-class>net.moon.jsf.bean.DemoBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> 这个我试过,没有问题。然后我自己拿来改掉了几个变量名,结果就调用不到action绑定的方法了,我觉得很奇怪。大家看下面的代码几乎跟上面一模一样,但是action的功能就不好用了。 package com.xxx.xxx; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; public class Regional { private List<SelectItem> states = new ArrayList<SelectItem>(); private List<SelectItem> cities = new ArrayList<SelectItem>(); private String state; private String city; public List<SelectItem> getStates() { return states; } public void setStates(List<SelectItem> states) { this.states = states; } public List<SelectItem> getCities() { return cities; } public void setCities(List<SelectItem> cities) { this.cities = cities; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public Regional() { super(); states.add(new SelectItem("")); states.add(new SelectItem("北京")); states.add(new SelectItem("上海")); // TODO Auto-generated constructor stub } public String refreshCities() { cities.clear(); System.out.println("called"); if (("北京").equals(state)) { cities.add(new SelectItem("东城区", "东城区")); cities.add(new SelectItem("西城区", "西城区")); cities.add(new SelectItem("崇文区", "崇文区")); } if ("上海".equals(state)) { cities.add(new SelectItem("黄浦区", "黄浦区")); cities.add(new SelectItem("卢湾区", "卢湾区")); cities.add(new SelectItem("徐汇区", "徐汇区")); } return null; } } <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <f:view> <h:form> <h:selectOneMenu id="state" value="#{regional.state}"> <f:selectItems value="#{regional.states}"/> <a4j:support action="#{regional.refreshCities}" event="onchange" reRender="city"></a4j:support> </h:selectOneMenu> <h:selectOneMenu id="city" value="#{regional.city}"> <f:selectItems value="#{regional.cities}"/> </h:selectOneMenu> </h:form> </f:view> </body> </html> <managed-bean> <managed-bean-name>regional</managed-bean-name> <managed-bean-class>com.xxx.xxx.Regional</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> |
|
sailing19
2009-07-16
这个论坛怎么不能编辑自己的帖子啊?
不好意思,上面帖子第一个jsp文件显示不正常,我重新排版了一下,如下: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <f:view> <h:form> <h:selectOneMenu id="privince" value="#{demoBean.province}"> <f:selectItems value="#{demoBean.provinces}"/> <a4j:support action="#{demoBean.refreshCities}" event="onchange" reRender="city"></a4j:support> </h:selectOneMenu> <h:selectOneMenu id="city" value="#{demoBean.city}"> <f:selectItems value="#{demoBean.cities}"/> </h:selectOneMenu> </h:form> </f:view> </body> </html> |
|
无双Rama
2009-07-16
lywzj2008 写道 源码是这样的,
<h:panelGroup> <h:selectOneMenu id="selectParameter" value="#{bean.parameterName}" > <a4j:support event="onchange" action="#{bean.doSpcCalc}"></a4j:support> <f:selectItems id="parameterValue" value="#{bean.parameters}" /> </h:selectOneMenu> </h:panelGroup> 后台: String parameterName; //seter ,geter public void doSpcCalc() { ... }; public List<SelectItem> getParameters() { List<SelectItem> items = new ArrayList<SelectItem>(); for (String param : hash.keySet()) { items.add(new SelectItem(param)); } return items; } onchang事件没有响应。当select 的值改变时。 lz 如果你的前台和后台代码都确保没错的话,没响应的原因就是因为你的 <a4j:support />里面少了一个reRender="你要影响的控件的id" |
|
terryzhou
2009-07-16
action适合页面跳转,actionListener适合页面内
+<a4j:region/> sailing19 写道 这个论坛怎么不能编辑自己的帖子啊?
不好意思,上面帖子第一个jsp文件显示不正常,我重新排版了一下,如下: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <f:view> <h:form> <h:selectOneMenu id="privince" value="#{demoBean.province}"> <f:selectItems value="#{demoBean.provinces}"/> <a4j:support action="#{demoBean.refreshCities}" event="onchange" reRender="city"></a4j:support> </h:selectOneMenu> <h:selectOneMenu id="city" value="#{demoBean.city}"> <f:selectItems value="#{demoBean.cities}"/> </h:selectOneMenu> </h:form> </f:view> </body> </html> |
|
lywzj2008
2009-07-16
谢谢。
|
|
sunshineparasol
2011-01-11
借贵宝地一用
我的jsp <h:dataTable value="#{acl.fnCodeNameList}" var="item"> <h:column> <h:selectBooleanCheckbox > <h:outputText value="#{item.fncode}" id="hello"></h:outputText> <a4j:support event="onclick" reRender="hello" actionListener="#{acl.save_fn}" /> </h:selectBooleanCheckbox> </h:column> </h:dataTable> 我的 后台 public void save_fn(){ System.err.println("----------save_fn---------"); } 我的也是不响应请求,谁帮我看一下好吗? |
|
sunshineparasol
2011-01-11
<h:dataTable value="#{acl.fnCodeNameList}" var="item"> <h:column> <h:selectBooleanCheckbox > <h:outputText value="#{item.fncode}" id="hello"></h:outputText> <a4j:support event="onclick" reRender="hello" actionListener="#{acl.save_fn}" /> </h:selectBooleanCheckbox> </h:column> </h:dataTable> |