JSF复选框值未发送到bean
虽然视图可以从bean中获取所有值,但当选中复选框(JSF复选框值未发送到bean,jsf,richfaces,javabeans,Jsf,Richfaces,Javabeans,虽然视图可以从bean中获取所有值,但当选中复选框(h:selectBooleanCheckbox)时,bean不会更新。从不从视图中调用项中的setSelected()方法 我尝试将bean的作用域更改为应用程序,使用映射而不是所选属性的值,并愚蠢地尝试编写自己的ajax javascript函数 我使用的应用程序有点遗留,所以我使用Tomcat6、JSF1.2和Richfaces 3.3.3.Final 看起来应该很简单,我想我遗漏了一些明显的东西,但我已经做了两天了,不明白为什么bean没
h:selectBooleanCheckbox
)时,bean不会更新。从不从视图中调用项
中的setSelected()
方法
我尝试将bean的作用域更改为应用程序,使用映射而不是所选属性的值,并愚蠢地尝试编写自己的ajax javascript函数
我使用的应用程序有点遗留,所以我使用Tomcat6、JSF1.2和Richfaces 3.3.3.Final
看起来应该很简单,我想我遗漏了一些明显的东西,但我已经做了两天了,不明白为什么bean没有更新
我的看法是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<title>JSF</title>
</head>
<body>
<h:form id="tableForm">
<rich:dataTable id="table" value="#{managedBean}" var="item" width="100%">
<rich:column label="Select" align="center" width="40px" >
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
<h:selectBooleanCheckbox value="#{item.selected}" >
<a4j:support execute="@this" event="onclick" ajaxSingle="true"/>
</h:selectBooleanCheckbox>
</rich:column>
<rich:column label="Name" align="center" width="40px">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{item.name}" />
</rich:column>
</rich:dataTable>
</h:form>
</body>
</html>
我想,你的
html
,头
和体
标签可能会导致这种情况
Ajax内容(javascript)有时必须进入页面的
部分(以及所需的脚本引用)。因为JSF使用的是组件,所以在将组件添加到底层对象模型时,它需要插入特定组件所需的javascript
因此,JSF本身需要管理html
、head
和body
标记
因此,不要将它们创建为普通html,而是使用适当的
、
和
标记,这将把这个任务移交给JSF。这样,应该生成onclick事件处理程序所需的javascript代码,并且复选框应该按预期工作 问题是我没有正确设置web.xml
我缺少将请求路由到richfaces的以下内容:
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
RichFaces过滤器
富人
org.ajax4jsf.Filter
富人
Facesservlet
要求
向前地
包括
感谢您的回复,不幸的是我错过了web.xml中的配置。在JSF中工作时,在答案中使用标记是最佳实践吗?看起来是的。
import org.richfaces.model.DataProvider;
public class ItemProvider implements DataProvider<Item>{
private List<Item> items = new ArrayList<Item>();
public ItemProvider(){
for(int i = 0; i < 10; i++){
items.add(new Item(i, "Item "+i));
}
}
public Item getItemByKey(Object key) {return items.get((Integer)key);}
public List<Item> getItemsByRange(int fromIndex, int toIndex) {
return new ArrayList<Item>(items.subList(fromIndex, toIndex));
}
public Object getKey(Item arg0) {return arg0.getId();}
public int getRowCount() {return items.size();}
}
public class Item {
private final int id;
private final String name;
private boolean selected;
public Item(int id, String name) {
this.id = id;
this.name = name;
selected = false;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public boolean isSelected(){
return selected;
}
public void setSelected(boolean selected){
this.selected = selected;
}
}
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>