+ Start a Discussion
renuamirenuami 

rerendered issue

Hi -

 

I know i am doing something wrong with in redendering, i am unable to figure out the issue can someone please help?..thanks

 

We have 4  AirLineItems

 

  - United

  - US Airways

  - Delta

  - Jet Blue

 

 

when Jet Blue is selected, then under DestinationColumn we do not want to show/render the  inputfield for that particular row. For all other selections DestinationColumn/rows should be rendered.

 

I tried the following two but no luck...

 

 rendered="{t.airlinesSelection <> 'Jet Blue'}"

 rendered="{t.airlinesSelection != 'Jet Blue'}" 

 

Please advise....

 

My page

 

<apex:page controller="Travel_Details">
<apex:form>
<apex:pageBlock >
<apex:pageBlockTable value="{!travels}" var="t" id="travelTable">

<apex:column headervalue="AirLines" id="Aircolumn">
<apex:selectList value="{!t.airlinesSelection}">
<apex:selectOptions value="{!AirLineItems}"/>
<apex:actionSupport event="onchange" rerender="travelTable"/>
</apex:selectList>
</apex:column>

<apex:column headervalue="Detail" id="Destinationcolumn">
<apex:inputField value="{!t.ct.AccountId}" rendered="{t.airlinesSelection!='Jet Blue'}" />
</apex:column>

</apex:pageBlockTable>
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

Message Edited by renuami on 03-26-2010 10:10 AM
Message Edited by renuami on 03-26-2010 10:20 AM
jwetzlerjwetzler

I think you forgot the '!'

 

rendered="{!t.airlinesSelection != 'Jet Blue'}"

renuamirenuami

Jill..Thanks for the response.

 

 I did use ! this, but there was a typo when i posted.

 

rendered="{!t.airlinesSelection != 'Jet Blue'}" 

rendered="{!t.airlinesSelection <> 'Jet Blue'}" 

 

Niether of these are working...Please advise

 

Thanks

jwetzlerjwetzler

hmm.  This works fine for me.  Are you sure that airlinesSelection is that exact string?  Try putting something like this on your page:

 

<apex:column> "{!t.airlinesSelection}" </apex:column>

 

 Use the quotes to make sure it's not a white space issue.  If there are spaces on either side of Jet Blue your equality won't match.

 

I used the following to test in my own org.  Notice that we only display the index for selections that are not 'Jet Blue'.

 

<apex:page controller="airlineCon"> <apex:pageBlock> <apex:pageBlockTable value="{!records}" var="t"> <apex:column> <apex:outputText value="{!t.i}" rendered="{!t.airlineSelection != 'Jet Blue'}"/> </apex:column> <apex:column> <apex:outputText value="{!t.airlineSelection}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>

 

public class airlineCon { public List<record> records {get; set;} public airlineCon() { records = new List<record>(); for (integer i = 0; i < 5; i++) { records.add(new record(i, 'Jet Blue')); } for (integer i = 5; i < 10; i++) { records.add(new record(i, 'United')); } for (integer i = 10; i < 15; i++) { records.add(new record(i, 'US Airways')); } for (integer i = 15; i < 20; i++) { records.add(new record(i, 'Delta')); } } public class record { public String airlineSelection { get; set; } public Integer i { get; set; } public record(Integer i, String airlineSelection) { this.i = i; this.airlineSelection = airlineSelection; } } }

 

 

 

 

renuamirenuami

Thanks Jill.

Yes. you are correct this works fine. But the problem with my code is,

The inputfield is lookup to Account in the Destination column and required=true 

 

when visualforce is rerendering it is rerendering the whole column. I thought VF is smart enough to rerender the row and not the whole column. 

Because of this, since the Destination column is required lookup to Account, When 'Jet Blue' is selected in the first row then whole column is rerendering and Enter a Value error message is displaying..(When it should have not shown the lookup for that row) Please see the screen below.

 

Is there any work around for this issue? Please advise...thanks

 

 

 

Message Edited by renuami on 03-28-2010 06:51 PM
jwetzlerjwetzler

specify immediate="true" on your actionSupport component

 

Spoke too soon.  I think what you want is to surround your selectList with apex:actionRegion

Message Edited by jwetzler on 03-28-2010 06:52 PM
renuamirenuami

Jill-

 

I did already tried apex:actionregion tag..When item is selected in the selecList, the validation error is not coming up, but the Destination column is not rerendering.

 

With apex:actionregion included when 'Jet Blue' is selected nothing happens in thedestination column.

 

Please advise..thanks

 

<apex:page controller="Travel_Details"> <apex:form> <apex:pageBlock > <apex:pageBlockTable value="{!travels}" var="t" id="travelTable"> <apex:column headervalue="AirLines" id="Aircolumn"> <apex:actionRegion> <apex:selectList value="{!t.airlinesSelection}"> <apex:selectOptions value="{!AirLineItems}"/> <apex:actionSupport event="onchange" rerender="travelTable"/> </apex:selectList> </apex:actionRegion> </apex:column> <apex:column headervalue="Detail" id="Destinationcolumn"> <apex:inputField value="{!t.ct.AccountId}" rendered="{!t.airlinesSelection != 'Jet Blue'}" /> </apex:column> </apex:pageBlockTable> <apex:commandButton action="{!save}" value="Save" /> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

jwetzlerjwetzler

Did you do what I asked earlier?  Put just the airline selection between quotes to see if you have white space issues or maybe case sensitivity problems.

 

I'm not sure what else I can do for you, this works fine for me, and I even augmented my page and controller to use a selectList like yours.  If you try my example in your own org, you'll see that when you make new selections from the drop downs the index will disappear/reappear accordingly and the right hand column will update.

 

 

<apex:page controller="airlineCon"> <apex:form> <apex:pageBlock id="theTable"> <apex:pageBlockTable value="{!records}" var="t"> <apex:column> <apex:actionRegion> <apex:selectList value="{!t.airlineSelection}" size="1" required="true"> <apex:selectOptions value="{!options}"/> <apex:actionSupport event="onchange" rerender="theTable"/> </apex:selectList> </apex:actionRegion> </apex:column> <apex:column > <apex:outputText value="{!t.i}" rendered="{!t.airlineSelection != 'Jet Blue'}"/> </apex:column> <apex:column > <apex:outputText value="{!t.airlineSelection}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

 

 

public class airlineCon { public List<record> records {get; set;} public airlineCon() { records = new List<record>(); for (integer i = 0; i < 5; i++) { records.add(new record(i, 'Jet Blue')); } for (integer i = 5; i < 10; i++) { records.add(new record(i, 'United')); } for (integer i = 10; i < 15; i++) { records.add(new record(i, 'US Airways')); } for (integer i = 15; i < 20; i++) { records.add(new record(i, 'Delta')); } options = new List<SelectOption>(); options.add(new SelectOption('Jet Blue', 'Jet Blue')); options.add(new SelectOption('United', 'United')); options.add(new SelectOption('US Airways', 'US Airways')); options.add(new SelectOption('Delta', 'Delta')); } public List<SelectOption> options { get; set; } public class record { public String airlineSelection { get; set; } public Integer i { get; set; } public record(Integer i, String airlineSelection) { this.i = i; this.airlineSelection = airlineSelection; } } }

 

The answer to the original question is that {!t.airlineSelection != 'Jet Blue'} is the proper syntax.  If that's not working for you then you have other problems on your page.  Possibly airlineSelection is not exactly 'Jet Blue', or possibly that expression has nothing to do with your problem at all, and you've got something else going on.

 

You really need to make sure you know exactly what the value is, which is what I suggested in my second reply. Similarly you can put {!NOW()} next to the inputField with the rendered attribute to make sure that that column is getting rerendered (it will put a timestamp on your page and if your column is getting rerendered, you'll see the timestamp update).

 

Hope this helps.

 

renuamirenuami

Hi Jill -

Thanks for your continuous guidance.

 

Yes i did tried all of your earlier suggestions and the sample code you provided. They are working fine.

 

But for my functionality for some reason isnt working for me.

If i remove actionRegion tag then rerendering is working fine, but the validation issue exists. If actionregion is added then rerendering is not working. Not sure where i am doing wrong .As suggested I added {!Now()} and it is not showing up

 

 

I made some modifications and here is my complete Page and class. 

 

 

 

<apex:page controller="Travel_Details">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!travels}" var="t" id="travelTable">

<apex:column headervalue="AirLines" id="Aircolumn">
<apex:actionRegion >
<apex:selectList value="{!t.airlinesSelection}" required="true" multiselect="false" size="1">
<apex:selectOptions value="{!AirLineItems}"/>
<apex:actionSupport event="onchange" rerender="travelTable"/>
</apex:selectList>
</apex:actionRegion>
</apex:column>

<apex:column headervalue="Detail" id="Destinationcolumn">
<apex:inputField value="{!t.travelRecord.AccountId__c}" rendered="{!t.airlinesSelection != 'Jet Blue'}" required="true"/>
</apex:column>

</apex:pageBlockTable>
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

public class Travel_Details
{
public PageReference save() {
return null;
}


public List<TravelWithUIData> travels { get; private set; }

public Travel_Details()
{
List<Travel__c> travelRecords = [Select Id,AccountID__c,ownerid from Travel__c Where OwnerId = :UserInfo.getUserId() and CreatedDate <= LAST_N_DAYS:7];
this.travels = new List<TravelWithUIData>();

for (Travel__c travelRecord : travelRecords)
{
TravelWithUIData t = new TravelWithUIData();
t.airlinesSelection = '--Select--';
t.travelRecord = travelRecord;
this.travels.add(t);
}

}

public List<SelectOption> getAirLineItems()
{
List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('--Select--','--Select--'));
options.add(new SelectOption('Jet Blue', 'Jet Blue'));
options.add(new SelectOption('United', 'United'));
options.add(new SelectOption('US Airways', 'US Airways'));
options.add(new SelectOption('Delta', 'Delta'));

return options;
}


public class TravelWithUIData
{
public String airlinesSelection { get; set; }
public Travel__c travelRecord { get; set; }
}
}