AJAX 调用清除不相关控件中的值

发布于 2024-08-21 20:09:38 字数 2500 浏览 6 评论 0原文

我正在使用 RichFaces 的 a4j:support 来切换页面上某些控件的可见性。但是,当更改 h:selectOneRadio 按钮 rdoRequestType 时,它​​会清除 a4j:outputPanel 中 ID 为“media”的 txtLibraryServerNumber 和其他控件的值。为什么页面上的一个 AJAX 调用会干扰另一个 AJAX 面板?

我尝试在 selectOneRadio 上的 a4j:support 标记上使用“process”属性,以便将另一个面板中的文本框的值写入 Seam bean,但这没有效果。我到底做错了什么?帮助!我快失去理智了!!

<h:selectOneRadio value="#{webencode.requestType}"
  id="rdoRequestType" styleClass="radio" style="width:295px" layout="pageDirection" >
  <f:selectItem itemValue="program" itemLabel="Series or Individual Program"/>
  <f:selectItem itemValue="promo" itemLabel="Promo" />
  <f:selectItem itemValue="specific" itemLabel="Specific Format Encoding Request"/>
  <a4j:support ajaxSingle="true" event="onclick" reRender="program" process="txtLibraryServerNumber,txtDigitalMediaFileName"/>
</h:selectOneRadio>

<a4j:outputPanel id="program" ajaxRendered="true">
  <s:span rendered="#{('program' == webencode.requestType || 'promo' == webencode.requestType) ? true : false}">
    <h:selectOneMenu value="#{webencode.seriesId}" id="lstSeriesName">
      <f:selectItems value="#{webencode.programItems}"/>
    </h:selectOneMenu>
  </s:span>
  <s:span rendered="#{'specific' == webencode.requestType ? true : false}">
    <h:selectOneMenu value="#{webencode.arrVideoEncodings.get(0).videoEncoding}"
      id="lstSpecificVideoEncoding1" style="width:295px;">
      <f:selectItems value="#{webencode.videoEncodingItems}"/>
    </h:selectOneMenu>
  </s:span>
</a4j:outputPanel>             

<h:selectOneMenu value="#{webencode.inputMediaType}"
  id="lstInputMediaType">
  <f:selectItems value="#{webencode.inputMediaTypeItems}"/>
  <a4j:support ajaxSingle="true" event="onchange" reRender="media" process="lstSeriesName,lstSpecificVideoEncoding1"/>
</h:selectOneMenu>

<a4j:outputPanel id="media" ajaxRendered="true">
  <s:span rendered="#{'Tape Library # or Server ID #' == webencode.inputMediaType ? true : false}">
    <h:inputText id="txtLibraryServerNumber"
      value="#{webencode.libraryServerNumber}" maxlength="50" />
  </s:span>  
  <s:span rendered="#{'Digital Media File Name' == webencode.inputMediaType ? true : false}">
    <h:inputText id="txtDigitalMediaFileName"
      value="#{webencode.digitalMediaFileName}" maxlength="195" /><br />
  </s:span>  
</a4j:outputPanel>

I'm using RichFaces' a4j:support to toggle the visibility of some controls on the page. However, when the h:selectOneRadio button rdoRequestType is changed, it clears the values of the txtLibraryServerNumber and other controls in the a4j:outputPanel with ID "media". Why would one AJAX call on a page interfere with a different AJAX panel?

I've tried using the "process" attribute on the a4j:support tag on the selectOneRadio so it writes the values of the text boxes in the other panel to the Seam bean, but that has no effect. What the heck am I doing wrong? Help! I'm losing my mind!!

<h:selectOneRadio value="#{webencode.requestType}"
  id="rdoRequestType" styleClass="radio" style="width:295px" layout="pageDirection" >
  <f:selectItem itemValue="program" itemLabel="Series or Individual Program"/>
  <f:selectItem itemValue="promo" itemLabel="Promo" />
  <f:selectItem itemValue="specific" itemLabel="Specific Format Encoding Request"/>
  <a4j:support ajaxSingle="true" event="onclick" reRender="program" process="txtLibraryServerNumber,txtDigitalMediaFileName"/>
</h:selectOneRadio>

<a4j:outputPanel id="program" ajaxRendered="true">
  <s:span rendered="#{('program' == webencode.requestType || 'promo' == webencode.requestType) ? true : false}">
    <h:selectOneMenu value="#{webencode.seriesId}" id="lstSeriesName">
      <f:selectItems value="#{webencode.programItems}"/>
    </h:selectOneMenu>
  </s:span>
  <s:span rendered="#{'specific' == webencode.requestType ? true : false}">
    <h:selectOneMenu value="#{webencode.arrVideoEncodings.get(0).videoEncoding}"
      id="lstSpecificVideoEncoding1" style="width:295px;">
      <f:selectItems value="#{webencode.videoEncodingItems}"/>
    </h:selectOneMenu>
  </s:span>
</a4j:outputPanel>             

<h:selectOneMenu value="#{webencode.inputMediaType}"
  id="lstInputMediaType">
  <f:selectItems value="#{webencode.inputMediaTypeItems}"/>
  <a4j:support ajaxSingle="true" event="onchange" reRender="media" process="lstSeriesName,lstSpecificVideoEncoding1"/>
</h:selectOneMenu>

<a4j:outputPanel id="media" ajaxRendered="true">
  <s:span rendered="#{'Tape Library # or Server ID #' == webencode.inputMediaType ? true : false}">
    <h:inputText id="txtLibraryServerNumber"
      value="#{webencode.libraryServerNumber}" maxlength="50" />
  </s:span>  
  <s:span rendered="#{'Digital Media File Name' == webencode.inputMediaType ? true : false}">
    <h:inputText id="txtDigitalMediaFileName"
      value="#{webencode.digitalMediaFileName}" maxlength="195" /><br />
  </s:span>  
</a4j:outputPanel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淤浪 2024-08-28 20:09:38

如果您将面板的 UpdateMode 属性设置为“始终”,它将在发生任何回发时进行更新。如果将其设置为“条件”,则仅当其自身的触发器之一导致回发时才会更新。

我不知道这是否会清除您的控件,但这是一个可能的答案,说明为什么一个面板会影响另一个面板。

If you have the UpdateMode property of the panel set to "always" it will update with any postback occurs. If you set it to "conditional" it will only update when one of it's own triggers causes a postback.

I don't know if this would clear your controls, but it is a possible answer to why one panel is effecting another.

2024-08-28 20:09:38

您的 Webencode bean 的范围是什么?它必须是 Page 或更长,否则每次调用时您的值都会丢失。请记住,如果您不指定范围,则默认为 Request,并且每个 Ajax 调用都是一个 Request。

您的媒体面板始终会刷新,因为您使用 ajaxRendered 属性指定了它,这就像在说“即使我没有被要求重新渲染,无论如何也要重新渲染我”。除非您有充分的理由使用 ajaxRendered (例如,始终像状态消息一样呈现的内容),否则您最好从明确指定要重新渲染的内容开始。

process 属性在这里不是必需的 - 去掉它。

干杯,

D

What is the scope of your Webencode bean? It will have to be Page or longer or your values will be lost with each call. Remember that if you don't specify a scope it defaults to Request and each Ajax call is a Request.

Your media panel is always being refreshed as you've specified it with the ajaxRendered attribute which is like saying "even if I'm not asked to be reRendered, reRender me always anyway." Unless you have a good reason to use ajaxRendered (eg. something that is always rendered like status messages), then you are better off starting with explicity specifying what to reRender.

The process attribute isn't necessary here - get rid of it.

Cheers,

D

冷弦 2024-08-28 20:09:38

找到解决方案:非常奇怪,但是在运行 Apache 和 JBoss 的服务器上,需要将 limitToList 属性设置为 true:

<a4j:support ajaxSingle="true" event="onchange" reRender="media" 
     limitToList="true"/>

这确保仅重新呈现指示的控件(在本例中为“媒体”)。仍然不知道为什么服务器上需要它而不是本地主机上需要它。一定是 Apache 的问题以及它如何与 JBoss 通信,但不确定。

Found the solution: Very strange, but on the server, which is running Apache with JBoss, it needs to have the limitToList attribute set to true:

<a4j:support ajaxSingle="true" event="onchange" reRender="media" 
     limitToList="true"/>

This ensures only the control indicated (in this case "media") is re-rendered. Still don't know why it's required on the server but not on the localhost. Gotta be something with Apache and how it communicates with JBoss, but not sure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文