You need to sign in to do that
Don't have an account?
Vinay J
render and rerender
Dear friends,
I have a map(integer, list) and a picklist on page with these integers (plus some extra values not present as kep in map). When user selects a value, related list should be diplayed in pageblocktable. If there's no list associated, error should be displayed and pageblocktable should not be visible at all. I have written below code which works file till user selects a value not present as key in the map. Also, in real scenario, it is possible that there's no data inobject and hence, map is empty.. in that case, neither the pageblocktable, nor the picklist should be visible. Can someone please help. It's quite urgent. Below is the code..
*********** Page ************
<apex:page controller="test">
<apex:form >
<apex:pageMessage detail="{!sError}" severity="Warning" rendered="{!sError <> null}" strength="1" title="No Data" id="message"/>
<apex:outputPanel rendered="{!isDataPresent == true}">
<apex:pageblock id="table" >
<apex:pageblocktable value="{!Data}" var="m" >
<apex:column value="{!m}" headerValue="Text"/>
</apex:pageblocktable>
</apex:pageblock>
</apex:outputPanel>
<apex:outputLabel value="Payment Year" ></apex:outputLabel>
<apex:selectlist id="pmname" value="{!selectedNumber }" multiselect="false" size="1" >
<apex:selectoptions value="{!listYearsForPage }" >
</apex:selectoptions>
<apex:actionSupport event="onchange" reRender="table,message"/>
</apex:selectlist>
</apex:form>
</apex:page>
**************** Controller ****************
public class test {
public List<SelectOption> listYearsForPage {get;set;}
public string selectedNumber {get;set;}
public boolean isDataPresent {get;set;}
public string sError {get;set;}
public test()
{
listYearsForPage = new List<SelectOption>();
listYearsForPage.add(new selectoption('1','1'));
listYearsForPage.add(new selectoption('2','2'));
listYearsForPage.add(new selectoption('3','3'));
listYearsForPage.add(new selectoption('4','4'));
isDataPresent = true;
}
public map<integer, list<string>> perpData()
{
map<integer, list<string>> a = new map<integer, list<string>>();
a.put(1,new List<String>{'a','b','c'});
a.put(2,new List<String>{'d','e','f'});
a.put(3,new List<String>{'g','h','i'});
return a;
}
public list<string> getData()
{
sError = null;
list<string> l = new list<String>();
if(selectedNumber == null)
selectedNumber = '1';
l = perpData().get(Integer.valueOf(selectedNumber));
if(l != null)
isDataPresent = true;
else {
isDataPresent = false;
sError = 'No data';
}
return l;
}
}
I have a map(integer, list) and a picklist on page with these integers (plus some extra values not present as kep in map). When user selects a value, related list should be diplayed in pageblocktable. If there's no list associated, error should be displayed and pageblocktable should not be visible at all. I have written below code which works file till user selects a value not present as key in the map. Also, in real scenario, it is possible that there's no data inobject and hence, map is empty.. in that case, neither the pageblocktable, nor the picklist should be visible. Can someone please help. It's quite urgent. Below is the code..
*********** Page ************
<apex:page controller="test">
<apex:form >
<apex:pageMessage detail="{!sError}" severity="Warning" rendered="{!sError <> null}" strength="1" title="No Data" id="message"/>
<apex:outputPanel rendered="{!isDataPresent == true}">
<apex:pageblock id="table" >
<apex:pageblocktable value="{!Data}" var="m" >
<apex:column value="{!m}" headerValue="Text"/>
</apex:pageblocktable>
</apex:pageblock>
</apex:outputPanel>
<apex:outputLabel value="Payment Year" ></apex:outputLabel>
<apex:selectlist id="pmname" value="{!selectedNumber }" multiselect="false" size="1" >
<apex:selectoptions value="{!listYearsForPage }" >
</apex:selectoptions>
<apex:actionSupport event="onchange" reRender="table,message"/>
</apex:selectlist>
</apex:form>
</apex:page>
**************** Controller ****************
public class test {
public List<SelectOption> listYearsForPage {get;set;}
public string selectedNumber {get;set;}
public boolean isDataPresent {get;set;}
public string sError {get;set;}
public test()
{
listYearsForPage = new List<SelectOption>();
listYearsForPage.add(new selectoption('1','1'));
listYearsForPage.add(new selectoption('2','2'));
listYearsForPage.add(new selectoption('3','3'));
listYearsForPage.add(new selectoption('4','4'));
isDataPresent = true;
}
public map<integer, list<string>> perpData()
{
map<integer, list<string>> a = new map<integer, list<string>>();
a.put(1,new List<String>{'a','b','c'});
a.put(2,new List<String>{'d','e','f'});
a.put(3,new List<String>{'g','h','i'});
return a;
}
public list<string> getData()
{
sError = null;
list<string> l = new list<String>();
if(selectedNumber == null)
selectedNumber = '1';
l = perpData().get(Integer.valueOf(selectedNumber));
if(l != null)
isDataPresent = true;
else {
isDataPresent = false;
sError = 'No data';
}
return l;
}
}
Here is the code,
All Answers
You have hardcode selectedNumber = '1'; so it will always return u the first list.
regarding ur scenario, u need to check if the map is empty or not.. if its not empty then u will have to check whether that map contains the selected number as the key, if it does then only do 'l = perpData().get(Integer.valueOf(selectedNumber));' else u can show appropirate message.
Here is the code,