有关spring中bean的@Scope 和richfaces 中表单分页的处理方式

来源:互联网 发布:spss预测下一年数据 编辑:程序博客网 时间:2024/06/06 03:47
冲突情景:

     在spring的中vew controller bean 如果用@Controller标签进行定义。缺省的Scope是session的。这样用户在界面上输入的内容一直保留。如果使用@Scoper来强制定义成request,那么可以解决这个问题。但是这个时候使用<rich:dataTabel>和<rich:datascroller>进行前台分页。就会无法显示第二个页面。因为这个组件使用了session。

 

解决问题的思路:

1.仍然保持每个controller的bean 的@Scpoer。例如

view plain
  1. @Controller("detailQuery2Bean")  
  2. @Scope("request")  
  3. public class DetailQuery2Bean  implements Serializable {  
  4. }  

2.在前台的xhtml文件中强制指定某个具体的bean的@Scope使用session。注意下面代码中的<a4j:keepAlive beanName="detailQueryBean"/> 语句

 

view plain
  1. <rich:dataTable id="resultTable" value="#{detailQueryBean.result}"  
  2.         var="row" reRender="ds" rows="20">  
  3.         <rich:column style="text-align:center" mce_style="text-align:center" sortBy="#{row.sgfssj}">  
  4.             <f:facet name="header">  
  5.                 <h:outputText value="事故发生时间" />  
  6.             </f:facet>  
  7.             <h:outputText value="#{row.sgfssj}" />  
  8.         </rich:column>  
  9.         <rich:column style="text-align:center" mce_style="text-align:center" sortBy="#{row.severityNo}">  
  10.             <f:facet name="header">  
  11.                 <h:outputText value="事故等级" />  
  12.             </f:facet>  
  13.             <h:outputText value="#{row.severityNo}" />  
  14.         </rich:column>  
  15.         <rich:column style="text-align:left" mce_style="text-align:left">  
  16.             <f:facet name="header">  
  17.                 <h:outputText value="事故形态" />  
  18.             </f:facet>  
  19.             <h:outputText value="#{row.formNo}" />  
  20.         </rich:column>  
  21.         <rich:column style="text-align:left" mce_style="text-align:left">  
  22.             <f:facet name="header">  
  23.                 <h:outputText value="事故原因" />  
  24.             </f:facet>  
  25.             <h:outputText value="#{queryHelperBean.mapReasons[row.reasonNo]}" />  
  26.         </rich:column>  
  27.         <rich:column style="text-align:left" mce_style="text-align:left" sortBy="#{row.lm}">  
  28.             <f:facet name="header">  
  29.                 <h:outputText value="LM" />  
  30.             </f:facet>  
  31.             <h:outputText value="#{row.lm}" />  
  32.         </rich:column>  
  33.         <f:facet name="footer">  
  34.             <rich:datascroller id="ds"></rich:datascroller>  
  35.         </f:facet>  
  36.     </rich:dataTable>