为什么我在删除后刷新页面可以而在提交那个去可以刷新?
页面代码
下为后台处理类:可能不能刷新原因是:a4j:buttom 的原因吧~!
页面代码
<h:form>
<rich:datascroller align="left" for="list" maxPages="20" rendered="#{selectManyAction.count > 20}"/>
<rich:spacer height="10" rendered="#{selectManyAction.count>20}" />
<rich:dataTable width="100%" id="list" rows="20" columnClasses="col" value="#{selectManyAction.selectedDataList}" var="List" columnsWidth="30px,350,90px,120px,40px;" onRowMouseOver="this.style.backgroundColor='#f1f1f1'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
<rich:column headerClass="tableheader">
<f:facet name="header">
<h:outputText value="选择" styleClass="colheader"/>
</f:facet>
<h:selectBooleanCheckbox value="#{manySelect.lisMap[List.id]}">
</h:selectBooleanCheckbox>
</rich:column>
<rich:column headerClass="tableheader">
<f:facet name="header">
<h:outputText value="用户名" styleClass="colheader"/>
</f:facet>
<h:outputText value="#{List.userName}" />
</rich:column>
<f:facet name="footer">
<rich:column colspan="2">
<h:selectBooleanCheckbox value="#{selectManyAction.error}">
<a4j:support event="onclick" reRender="datetable" action="#{selectManyAction.setAll()}" />
</h:selectBooleanCheckbox>
<h:commandButton value="Get selected items" action="#{selectManyAction.getSelectedItems}" />
<a4j:commandButton action="#{selectManyAction.removeSelect}" value="删 除" styleClass="signin_right02_center_right_button"/>
</rich:column>
</f:facet>
</rich:dataTable>
</h:form>
下为后台处理类:可能不能刷新原因是:a4j:buttom 的原因吧~!
@Name("selectManyAction")
@Scope(ScopeType.PAGE)
public class SelectManyAction {
// Init --------------------------------------------------------------------------------------
@In
EntityManager entityManager;
@In
ManySelect manySelect;
private List<User> selectedDataList;
private List<User> selectList;
// Actions -----------------------------------------------------------------------------------
private long count;
private boolean error = false;
@SuppressWarnings("unchecked")
@Create
public void init(){
selectedDataList = entityManager.createQuery("select o from User o").getResultList();
for(User user:selectedDataList){
System.out.println("userId======"+user.getId());
}
manySelect.clear();
for(User user:selectedDataList){
manySelect.put(user.getId(), false);
}
Map<Long, Boolean> map = manySelect.getLisMap();
map.entrySet();
}
/*
* 复选框中在同一层中时可以直接从页面传入ID和ID所对应的boolean型保存在一个对象中,当复选框为一层而事件处理为
* 另一层时,复选框类型在服务端所对应的map类型会重新加载。
*/
public String getSelectedItems() {
// Get selected items.
selectList = new ArrayList<User>();
setCount(selectedDataList.size());
for (User dataItem : selectedDataList) {
System.out.println(manySelect.getLisMap().get(dataItem.getId()));
}
return "selectMany.xhtml";
}
public void setAll(){
Map<Long, Boolean> map = manySelect.getLisMap();
for(Map.Entry<Long, Boolean> entry:map.entrySet()){
entry.setValue(error);
}
}
@Transactional
public String removeSelect() {
Map<Long, Boolean> map = manySelect.getLisMap();
for(Map.Entry<Long, Boolean> entry:map.entrySet()){
if(entry.getValue()){
Long sid = entry.getKey();
System.out.println("id====="+sid);
User user = entityManager.find(User.class, sid);
entityManager.remove(user);
}
}
return "selectMany.xhtml";
}
// Getters -----------------------------------------------------------------------------------
public List<User> getSelectedDataList() {
return selectedDataList;
}
public void setCount(long count) {
this.count = count;
}
public long getCount() {
return count;
}
public List<User> getSelectList() {
return selectList;
}
public void setSelectList(List<User> selectList) {
this.selectList = selectList;
}
public void setSelectedDataList(List<User> selectedDataList) {
this.selectedDataList = selectedDataList;
}
public boolean isError() {
return error;
}
public void setError(boolean error) {
this.error = error;
}
}
selectMany是由自己定义封装好的一个hashMap类,里面一系列操作可以更具自己多多选框的要求来设置,如不用selectMany也可以在此类中重新构造一个map函数