简体   繁体   English

JSF 1.2和Rich Faces中的Ajax和Request范围豆

[英]Ajax and Request Scoped beans in JSF 1.2 and Rich Faces

I'm using JSF 1.2 and RichFaces 3.3, I have a page called NewsItemDetails with the following structure 我正在使用JSF 1.2和RichFaces 3.3,我的页面名为NewsItemDetails,结构如下

<h:form>
  <h:panelBar>
    <h:panelBarItem>
      <myTag:searchModule />
    </h:panelBarItem>
  </h:panelBar>
</h:form>

and the backing bean of that page is of a request scope, and here is a snippet of the faces-config.xml: 并且该页面的后备bean在请求范围内,这是faces-config.xml的片段:

<managed-bean>
  <managed-bean-name>newsItemDetails</managed-bean-name>
  <managed-bean-class>class.location...</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
     <property-name>id</property-name>
     <value>#{param['id']}</value>
  </managed-property>
</managed-bean>

And to be complete here's a snippet of the searchModule tag: 为了完整起见,这是searchModule标记的片段:

<ui:composition>
   <rich:tabPanel>
     <rich:tab label="Images">
       <h:panelGrid columns="2">
         <h:inputText value="#{newsItemDetails.searchLabel}" />
         <a4j:commandButton value="Search" actionListener="#{newsItemDetails.onSearch}" reRender="mediaItemsSearchResults, imagesDataTable" />
       </h:panelGrid>

       <a4j:outputPanel id="mediaItemsSearchResults" ajaxRendered="true">
         <rich:dataTable id="imagesDataTable" value="#{newsItemDetails.searchResults}" var="image">
           <h:column>
             <h:outputText value="#{image.title}"/>
           </h:column>
         </rich:dataTable>
       </a4j:outputPanel>

     </rich:tab>
   </rich:tabPanel>
</ui:composition>

Now the problem is, whenever I hit the search button, the action listener is never called, but I could see a request sent to the server through Firebug. 现在的问题是,每当我按下搜索按钮时,就不会调用动作侦听器,但是我可以看到通过Firebug发送到服务器的请求。 And here's the strange thing if I call the same searchModule tag, just outside the rich:panelBarItem and I hit the search button the action listener is called, but the dataTable is not re-rendered, and it's only called the first time I hit the button. 如果我在rich:panelBarItem外部调用相同的searchModule标记,然后按一下搜索按钮,即会调用动作侦听器,但这是奇怪的事情,但是dataTable不会重新呈现,这只是我第一次点击按钮。

So if anyone has a clue why this is happening, I would be more than grateful. 因此,如果有人知道为什么会发生这种情况,我将不胜感激。

Thanks in advance 提前致谢

I've figured out the answer, apparently the scope of the backing bean had to be set to session scope instead of request. 我已经找到了答案,显然必须将后备bean的范围设置为会话范围而不是请求。 Having done that everything works great. 完成后,一切正常。 So the entry in the faces-config.xml is: 因此,faces-config.xml中的条目为:

<managed-bean>
  <managed-bean-name>newsItemDetails</managed-bean-name>
  <managed-bean-class>class.location...</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

And as you can see I had to remove the entry, and instead get it from the request object in the backing bean. 正如您所看到的,我必须删除条目,而是从支持bean中的request对象获取它。

Thanks all. 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM