我知道这不是一个错误。 但是我需要一个建议,我怎能不丢失检查线的检查知识?
在JSF页面上:
<h:form prependId="false" id="searchUserFormTable" >
<p:dataTable id="selectUserTable" var="user"
value="#{userListController.lazyDataModel}" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="2" paginatorPosition="bottom" rowKey="#{user}"
lazy="true"
rowsPerPageTemplate="2,10,20,30,40,50"
rendered="#{userListController.lazyDataModel != null}" selection="#{systemMessageEditController.receiverList}"
scrollable="true" scrollHeight="250" resizableColumns="false" >
<p:column selectionMode="multiple" width="18" />
<f:facet name="header">
<h:outputText value=" Users (#{userListController.lazyDataModel.rowCount})" />
</f:facet>
<p:column filterBy="#{user.name}" headerText="Name" filterMatchMode="contains" width="80">
#{user.name}
</p:column>
<p:column filterBy="#{user.surname}" headerText="Surname" filterMatchMode="contains" width="80">
#{user.surname}
</p:column>
<p:column headerText="Gender" width="80">
#{user.gender}
</p:column>
<p:column headerText="City" width="80">
#{user.address.city.name}
</p:column>
<p:column headerText="Status" width="80">
#{user.userStatus}
</p:column>
<p:column headerText="User Detail" width="80">
<h:link value="User Detail" outcome="/view/admin/usermanagement/userInfo.jsf">
<f:param name="userId" value="#{user.id}" />
</h:link>
</p:column>
</p:dataTable>
<p:commandButton value="Tamam" oncomplete="userListDlg.hide();" update=":newMessageForm"></p:commandButton>
</h:form>
所有控制器:
@ManagedBean(name="systemMessageEditController")
@ViewScoped
public class SystemMessageEditController {
@ManagedProperty(value = "#{systemMessageService}")
SystemMessageService systemMessageService;
@ManagedProperty(value = "#{securityBean}")
SecurityBean securityBean;
@ManagedProperty(value = "#{systemMessageReceiverService}")
SystemMessageReceiverService systemMessageReceiverService;
@ManagedProperty(value = "#{systemMessageAnswerService}")
SystemMessageAnswerService systemMessageAnswerService;
private SystemMessage systemMessage = new SystemMessage();
private SystemMessageAnswer systemMessageAnswer = new SystemMessageAnswer();
private SystemMessageReceiver systemMessageReceiver = new SystemMessageReceiver();
private User[] receiverList;
private boolean dummy;
public void prepareToEdit(){
systemMessage = systemMessageService.findById(systemMessage.getId());
}
public void prepareToSendMessage(){
systemMessage = new SystemMessage();
receiverList = null ;
}
public void sendMessage(){
if(Util.isNotNull(systemMessage.getTitle())){
boolean success = false;
systemMessageAnswer.setUser(securityBean.getUser());
systemMessage.getSystemMessageAnswerList().add(systemMessageAnswer);
systemMessage.setUserSender(securityBean.getUser());
systemMessageAnswer.setSystemMessage(systemMessage);
if(!systemMessage.isSendAll()){
addMessageReceiver();
}
systemMessage = systemMessageService.save(systemMessage);
systemMessageAnswer = new SystemMessageAnswer();
success = true;
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.send.success"), FacesUtils.getMessageByKey("systemmessage.send.success"));
FacesContext.getCurrentInstance().addMessage("", message);
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("success", success);
}
else{
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.null.title"), FacesUtils.getMessageByKey("systemmessage.null.title"));
FacesContext.getCurrentInstance().addMessage("", message);
}
}
public void setRead(SystemMessage message){
message.setReaded(true);
systemMessageService.save(message);
}
public void addMessageReceiver(){
for(User user : receiverList){
SystemMessageReceiver messageReceiver = new SystemMessageReceiver();
messageReceiver.setReceiver(user);
messageReceiver.setSystemMessage(systemMessage);
messageReceiver.setReaded(false);
systemMessage.getSystemMessageReceiverList().add(messageReceiver);
}
}
public void deleteMessage(){
boolean success = false;
systemMessageService.delete(systemMessageService.findById(systemMessage.getId()));
success = true;
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.delete.success"), FacesUtils.getMessageByKey("systemmessage.delete.success"));
FacesContext.getCurrentInstance().addMessage("", message);
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("success", success);
}
public void sendMessageAnswer(){
systemMessageAnswer.setUser(securityBean.getUser());
systemMessageAnswer.setSystemMessage(systemMessage);
systemMessageAnswerService.save(systemMessageAnswer);
if(!systemMessage.isSendAll()){
systemMessage.setSystemMessageReceiverList(systemMessageService.getReceiverListOfMessage(systemMessage));
for(SystemMessageReceiver systemMessageReceiver : systemMessage.getSystemMessageReceiverList()){
if(!systemMessageReceiver.getReceiver().getId().equals(securityBean.getUser().getId())){
systemMessageReceiver.setReaded(false);
systemMessageReceiver.setShowed(false);
systemMessageReceiverService.save(systemMessageReceiver);
}
}
}
systemMessage.getSystemMessageAnswerList().add(systemMessageAnswer);
systemMessageAnswer = new SystemMessageAnswer();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.send.success"), FacesUtils.getMessageByKey("systemmessage.send.success"));
FacesContext.getCurrentInstance().addMessage("", message);
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("success", true);
}
public SystemMessageService getSystemMessageService() {
return systemMessageService;
}
public void setSystemMessageService(SystemMessageService systemMessageService) {
this.systemMessageService = systemMessageService;
}
public SystemMessage getSystemMessage() {
return systemMessage;
}
public void setSystemMessage(SystemMessage systemMessage) {
ArrayList<String> fetchedAttributes = new ArrayList<String>();
fetchedAttributes.add("systemMessageAnswerList");
this.systemMessage = systemMessageService.loadWithFetchedAttributes(systemMessage.getId(),fetchedAttributes);
}
public SystemMessageAnswer getSystemMessageAnswer() {
return systemMessageAnswer;
}
public void setSystemMessageAnswer(SystemMessageAnswer systemMessageAnswer) {
this.systemMessageAnswer = systemMessageAnswer;
}
public SecurityBean getSecurityBean() {
return securityBean;
}
public void setSecurityBean(SecurityBean securityBean) {
this.securityBean = securityBean;
}
public SystemMessageReceiverService getSystemMessageReceiverService() {
return systemMessageReceiverService;
}
public void setSystemMessageReceiverService(
SystemMessageReceiverService systemMessageReceiverService) {
this.systemMessageReceiverService = systemMessageReceiverService;
}
public SystemMessageAnswerService getSystemMessageAnswerService() {
return systemMessageAnswerService;
}
public void setSystemMessageAnswerService(
SystemMessageAnswerService systemMessageAnswerService) {
this.systemMessageAnswerService = systemMessageAnswerService;
}
public SystemMessageReceiver getSystemMessageReceiver() {
return systemMessageReceiver;
}
public void setSystemMessageReceiver(SystemMessageReceiver systemMessageReceiver) {
this.systemMessageReceiver = systemMessageReceiver;
}
public User[] getReceiverList() {
return receiverList;
}
public void setReceiverList(User[] receiverList) {
this.receiverList = receiverList;
}
我正在丢失已检查的信息,同时将一个分页号码跳到另一个,当我检查了一些行,然后在数据表中跳转另一个分页号码,然后回到旧的分页号码,我松开了检查的信息,我看到没有任何变化。< / p>
答案 0 :(得分:1)
这就是@ViewScoped
的工作原理。请参阅BalusC的following answer:
只要您与同一视图进行交互(即在bean操作方法中返回void或null),视图范围的bean就会存在。当您导航到另一个视图时,例如通过单击链接或返回不同的操作结果,视图范围bean将在渲染响应结束时被删除,并且在下一个请求中不可用。
这解释了在像你这样的情况下(我只是在你的一条评论中读到你在失去选择之前跳转到另一页,你应该注意到你的问题!)豆被破坏了,所以当你导航回到dataTable
视图,它会再次重建。这就是receiverList
为空的原因=&gt;没有选择。
如果要在不同视图之间导航时保存数据,请使用范围比@ViewScoped宽的bean,或者只是将选择保存到数据库中的表。
修改强>
问题可能出在您的rowKey
属性中。在当前代码中,它指向用户对象,在这种情况下,请确保此对象具有正确的hashCode
,equals
和toString
实现。如果user
类实际上有密钥或其他内容,则将rowKey
更改为rowKey="#{user.id}"
会更容易。
答案 1 :(得分:0)
检查Showcase。我觉得它的效果就像你想要的那样。
答案 2 :(得分:0)
你可能是通过ajax请求发送数据的,你应该确保它process
dataTable本身