views:

295

answers:

3

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>
A: 

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.

hqrsie
Thanks, hqrsie. Unfortunately, there's no UpdateMode on the RichFaces a4j:outputPanel control.
Alex
+1  A: 

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

Damo
Thanks, Damo. I took the ajaxRendered attribute off of the output panels. They work correctly now on my localhost; but on the server, running the same version of JBoss, the AJAX does nothing now. Very strange.
Alex
Check that you don't have any nested forms. Easy to accidentally do if you're using Facelets.
Damo
I've seen this problem before: It seems that if you have required fields on a page, and you set ajaxRendered=false, the panel won't show. The only way I can get the panel to show is to set that to true, and when I do, it wipes out the values of the fields in the other panel.
Alex
Nope. No nested forms. Just checked the browser's view source. Only one Form tag.
Alex
@Alex if you leave off the ajaxRendered attribute it defaults to false. I find it hard to believe that it is causing the effects you are seeing.
Damo
Hi, Damo. That's what's causing me to lose my mind. It works the way it should on my Localhost (leaving off the ajaxRendered attribute), but if I leave the ajaxRendered=True off on the server, running the same version of JBoss, the AJAX calls are ignored completely. What explains this? I'm at a complete loss. I've cleared my browser cache, restarted JBoss a 100 times, and deployed the WAR file after removing the old WAR file on the server. What am I doing wrong?
Alex
By the way, the page also has non-AJAX fields that have required=true. I've read that this can cause ajaxRendered=true to be required, otherwise panels won't display. I'm so desperate, I've ripped out the AJAX calls and am using plain old JavaScript to try to show/hide stuff. But it's a pain.
Alex
All I can suggest is to strip your page down to the basics if you haven't already. When I come across problems like this I remove everything until it's the smallest possible page reproducing the problem. Usually you can identify the issue this way.
Damo
Thanks, Damo. Please see answer I found below. Thanks, everyone, for looking at my question and answering. It's much appreciated :)
Alex
A: 

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.

Alex