我正在使用p:datatable来显示列表中的值。我在一个按钮点击事件中将此列表放在会话映射中。现在我想从另一个使用javascript打开的jsf页面更新此列表。更改值后,我在控制器中获得更新列表,但它没有在datatable中更新。所以,如果有人有想法,请告诉我。这里请注意,我没有使用会话bean只使用会话映射与其他jsf页面共享对象。
这是我的代码.. 控制器1
@ViewScoped
@Controller
public class Controller1 implements Serializable {
private List<Object[]> dataList = new ArrayList<Object[]>();
public List<Object[]> getDataList () {
return dataList;
}
public void setDataList(List<Object[]> dataList) {
this.dataList = dataList;
}
//on action
public String getRecords(){
//retrieved from database
dataList=dataService.getData();
ExternalContext externalContext = FacesContext.getCurrentInstance()
.getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
sessionMap.put("data", dataList);
return null;
}
public String openWindow(){
//some logic
return null;
}
}
的index.xhtml
<p:commandButton id="buttonID" value="Populate Data"
ajax="false"
action="#{controller1.getRecords}"/>
<p:dataTable var="dataList1" id="dataListID"
value="#{controller1.dataList}"
rowIndexVar="index">
<p:column headerText="Sr. No.">
<h:outputText value="#{index + 1}" />
</p:column>
<p:column
headerText="Order No.">
<h:outputText value="#{dataList1[0]}" />
</p:column>
</p:dataTable>
<p:commandButton id="openButtonID"
action="#{controller1.openWindow}" value="Populate Data"
oncomplete="return windowPopup();"/>
<script>
function windowPopup() {
var windowPopup = null;
windowPopup = window.open(
"index2.jsf?faces-redirect=true",
"ChildWindow",
"toolbar=no,menubar=no,scrollbars=yes,location=no,width=1000,height=600");
windowPopup.focus();
}
</script>
控制器2
@ViewScoped
@Controller
public class Controller2 implements Serializable {
private List<Object[]> itemList = new ArrayList<Object[]>();
public List<Object[]> getItemList () {
return itemList;
}
public void setItemList(List<Object[]> itemList) {
this.itemList= itemList;
}
@PostConstruct
@Loggable
public void init() {
itemList = (List<Object[]>) FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap().get("data");
}
public String processItem() {
for (Object[] item: itemList) {
item[0] = Integer.parseInt(item[0].toString())+1;
}
ExternalContext externalContext = FacesContext.getCurrentInstance()
.getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
sessionMap.put("data", itemList);
return null;
}
}
index2.xhtml
<p:commandButton value="Submit"
action="#{controller2.processItem}"
/>
现在我关闭index2.xhtml。但我无法在index1.xhtml的p:datatable中看到更新的值。我能够在index2.xhtml中看到itemList的值。我也可以在Controller1中获得更新值。