Donuts-spring2+hibernate3+jsf开发日志(2)

    1-20)tomhowk1.1.3和trinidad1.0.1混用的时候发生冲突,<t:datatable> 翻页的链接不能正常显示,必须取消faces-config.xml文件中的trinidad的renderkit标签
  <!-- Use the Trinidad RenderKit
       <default-render-kit-id>
         org.apache.myfaces.trinidad.core
       </default-render-kit-id>
       -->
    1-21)jsf传递参数显示格式化。<h:outputformat> <h:param/></h:outputformat>
    1-22)<f:attribute value="left" name="align" />可以设置父对象属性。
                       <h:column id="column2">
                             <f:facet name="header">
                                   <h:outputText styleClass="outputText" value="Alias" id="text3"></h:outputText>
                             </f:facet>
                             <h:outputText id="text4" value="#{varfcBarcelona.alias}"
                                   styleClass="outputText">
                             </h:outputText>
                             <f:attribute value="left" name="align" />
                       </h:column>
    1-23)各行中引用t:dataTable的行号  设置属性:rowIndexVar="rowId"  用例:index="#{rowId}"
    1-24)jsf在datatable页面中点击某条记录编辑时,faces-config.xml中的数据导航不能是redirect跳转,否则编辑页面不能获得编辑对象的id等参数
    1-25)MyFaces installation :make sure that there is no jsf-api.jar or jsf-impl.jar
  (i.e. Suns API and implementation) 使用myface的jsf1.2核心时,需要清除jsf-api.jar,jsf-impl.jar 并且bean全部重新编译一下。???问题依旧。
                后来,重新定义了myeclipse里的preference配置,在javaee5里清除jsf-api.jar,jsf-impl.jar这两个包。项目重新编译,ok 运行错误NoClassDefFoundError: com.sun.faces.taglib.jsf_core.ViewTag不再出现。问题解决,到此为止。他妈的自欺欺人,那两个jar竟然还在lib目录里,去掉问题还在。
           1-26)删除操作时,记录仍然会显示在页面上,需要设置一下faces-config.xml 就是删除操作后是redirect到本datapata页面。
    1-27)在 Backing Bean 中有这样的一个方法:
  public  String query()
  {
   dataModel.setWrappedData(getDataPage( 0 , getPageSize()));
    return   " success " ;
  }
  只是把数据清空,并强制 PagedListDataModel 读取数据,然后我们返回相同的页面,

   1-28)You have a classic case of LIE - Lazy Initialization error. This topic has been discussed so many times that I suggest to do a search on the forum and point to the hibernate documentation. Basically, you are using lazy relationships that require an open session (so the lazy loading can happen). Inside Spring you can use OpenSessionInViewFilter/Interceptor or the HibernateInterceptor to keep a Hibernate session open during a request or method calls.

   1-29)Hi,guoshiguan 对于第一个问题,JSF是可以通过Tag的binding属性来动态生成UI组件的JSP: 代码
  <h:panelGroup id="dynamicGroup" binding="#{dynaHandler.dynamicPanelGroup}"></h:panelGroup> 
  Java code
  代码
  private HtmlPanelGroup panelGroup;  
  public HtmlPanelGroup getDynamicPanelGroup(){  
         Application application = FacesContext.getCurrentInstance().getApplication();  
         if (this.panelGroup == null) {  
              this.panelGroup = (HtmlPanelGroup) application  
                     .createComponent(HtmlPanelGroup.COMPONENT_TYPE);  
         }  
         List children = this.panelGroup.getChildren();  
         children.clear();  
          HtmlOutputText outputText = (HtmlOutputText) application  
                .createComponent(HtmlOutputText.COMPONENT_TYPE);  
          outputText.setValue("JSF");  
  children.add(outputText);  
  return this.panelGroup;  
  }
  这样就可以在页面中动态生成一段Text文本

         1-30)<rtexprvalue>true<rtexprvalue/>指明tld tag 属性值是否必须接受EL表达式,如果设成true则必须接受EL表达式,否则跑出错误,当然也可以在代码里判断来避免错误。

  1-31)jsf-tag自定义问题终于解决了,!!!!!在tld里多一句话:害死人啊!!!!<jsp-version>2.1</jsp-version>
  if you migrate from jsf 1.1 to jsf 1.2, you have got to do this with your whole application.
  just look at your tld, its tag definitions are old style, so validation of the tags attribute causes this error.
  a good reference for migration ist the following link
  http://java.sun.com/products/jsp/reference/techart/unifiedEL.html
  add following line to your tld
  <jsp-version>2.1</jsp-version>
  add a deffered description to your attributes, for example the actionListener
  <attribute>
  <name>actionListener</name>
        <required>false</required>
        <deferred-method>
        <method-signature>void actionListener(javax.faces.event.ActionEvent)</method-signature>
        </deferred-method>
        <type>java.lang.String</type>
      </attribute>
  参考:http://java.sun.com/products/jsp/reference/techart/unifiedEL.html

  1-32)  备份怪异表达式 ${"<input type='checkbox' name='chk' value=\""}<h:outputText value="#{row.dictTypeId}"/>${"\">"}

  1-33) <!-- Spring 刷新Introspector防止内存泄露 -->
  <listener>
  <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  1-34)延迟加载配置:
  <!--OpenSessionInViewFilter配置-->
      <filter> 
          <filter-name>OpenSessionInViewFilter</filter-name> 
          <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
          <init-param>   
              <param-name>singleSession</param-name>   
              <param-value>true</param-value> 
          </init-param> 
      </filter> 
      <filter-mapping>   
          <filter-name>OpenSessionInViewFilter</filter-name>   
          <url-pattern>/*</url-pattern>   
      </filter-mapping>
  1-35) LinkedHashMap 特性 按插入和访问顺序排序
  1-36)重大发现1:jsf里调用bachingbean,如果页面修改对象是bachingbean.modelbean,那么这个必须在bachingbean里声明时初始化modelbean=new ModwlBean();或者在getModelBean()方法里判断是否为空再初始化,这个相当重要,不然jsf页面提交的时候会出错。。我的天老爷。
  1-37)重大发现2:modelBean对象包含many-to-one的子对象时,在model里必须先初始化,不然jsf调用modelBean.sunModelBean时,页面提交时,jsf提示出错,告诉无法找到sunModelBean属性,切记,不然很麻烦。。。。好像跟jsf在页面内持久化model对象时保存的数据结构有关系。或者在bachingbean的getModelBean()方法里初始化ModelBean时同时初始化sunModelBean属性,不能为null。
 1-38)当在容器中通过action调用service代码保存对象时,不能成功保存对象,同时出现如下类似错误:
  Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
  FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
  这时修改filter的配置singleSession=false,增加如下代码:
      <filter>
          <filter-name>hibernateFilter</filter-name>
          <filter-class>
              org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
          </filter-class>
          <init-param>
              <param-name>singleSession</param-name>
              <param-value>false</param-value>
          </init-param>
      </filter>
 1-39)看来延迟的过滤器不能用;javax.servlet.ServletException: Illegal attempt to associate a collection with two open sessions

 

你可能感兴趣的:(spring,jsp,Hibernate,bean,JSF)