function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KeithJKeithJ 

Explicity call a setter in my controller

Hi there. Does anyone know how to do this?

In my visualforce code, I have 2 apex-repeat components.

The first one loops through a list of all the keys of a map M.

The second embedded apex-repeat loops through the value of the

Map M for the key of the outer repeat.

 

I'm having trouble trying to figure out how to do this because

I need to pass through to the controller, the current value of the key (outer most repeat).

 

Can figure it out! I tried using apex-outputText with an embedded param but it doesn't work for me.

 

Here's my controller code:

 

 

public Map<String,List<ChartRow>> chartDataMap { get; set; } //KeySet and Values are used in VisualForce page. public String keyStr { get; set { keyStr = value; System.debug('***** KEYSTR VALUE IS: ' + keyStr); } } public List<String> chartDataKeySet { get { List<String> keyList = new List<String>(); for(String s : chartDataMap.keySet()) keyList.add(s); return keyList; } set; } public List<ChartRow> chartRowRecord { get { System.debug('***** CHART ROW RECORD PROPERTY IS: ' + chartDataMap.get(keyStr)); return chartDataMap.get(keyStr); } set; }

 I want to set the property keyStr from the value of the outer apex-repeat

as in - 

 

 

<apex:repeat value="{!chartDataKeySet}" var="rigNatureVar"> <!-- the map key --> <!-- I want to set keyStr here so the following apex repeat will return the correct value from the map --> <apex:repeat value="{!chartRowRecord}" var="chartDataRecord"> <apex:outputText value="{!chartDataRecord}" /> </apex:repeat> </apex:repeat>

 

Many thanks.

 

 

 

 

mattdarnoldmattdarnold

It seems like you could accomplish what you're looking for by modifying your chartRowRecord getter to cycle through the keyset of your chartDataMap, populate one List with the data from each List contained in chartDataMap, and then return that list requiring just one repeat component in the VF page.

 

I didn't test this, but the chartRowRecord getter might look like this:

 

public List<chartRow> chartRowRecord {
get {
List<ChartRow> outputRows = new List<ChartRow>();

for(String s : chartDataMap.keySet()) {
// Use addAll to add all the elements of the returned list
// to the outputRows list
outputRows.addAll(chartDataMap.get(keyStr));
}

return outputRows;
}
set;
}

 

This assumes your trying to output a list of text that goes something like

 

   Array 1-Row 1

   Array 1-Row 2

   Array 1-Row 3

   Array 2-Row 1

   Array 2-Row 2

....

 

So instead of cycling through each list and then each row within each list, you just merge them together and can then output using the standard repeat component.

 

It seems like this is what you were trying to do - but let me know if I misunderstood.

 

-- Matt

 

KeithJKeithJ

Hi Matt.

Thank you very much for the help.

Yes, that is the structure I am trying to construct.

The addAll may be what I am looking for.

 

What I really want to achieve, is in the VF

page, to be able to output the Key

and then the records associated with the key.

 

So I would ideally like is:

 

Array 1

Row 1

Row 2

Row 3

 

Array 2

Row 1 

Row 2

Row 3

Row 4

 

Array 3

Row 1

. . . 

 

Is this achievable?
Thanks again for your help.

 

mattdarnoldmattdarnold

Try something like this:

Create a custom class that will hold the data from your ChartRow object as well as the chartDataMap key. So your code would look like this:

 

:: Controller ::

 

// Custom class to hold the combined data from the map and chartRow array
public class outputData {
public String key { get; set; }
public String id { get; set; }
public String name { get; set; }
// And this would continue as you build the fields you'll need in outputData
}

public Map<String,List<ChartRow>> chartDataMap { get; set; }

public List<outputData> chartRowRecord {
get {
List<outputData> outputRows = new List<outputData>();

for(String s : chartDataMap.keySet()) {
// Use addAll to add all the elements of the returned list
// to the outputRows list

for(ChartRow r : chartDataMap.get(keyStr)) {
outputData d = new outputData();
d.key = s;
d.id = r.id;
d.name = r.name;
outputRows.add(d);
}
}

return outputRows;
}
set;
}

 

 :: Page ::

 

<apex:repeat value="{!chartRowRecord}" var="chartDataRecord">
<apex:outputText value="{!chartDataRecord.key}" /> <apex:outputText value="{!chartDataRecord.name}" />
</apex:repeat>

 

This will produce something similar to what you're after, but it won't group the data into sections by array. Instead, you'll either need to custom code a table to do this or use a library that provides this functionality as I don't think you can do it in VF. (ExtJS provides a nice grouping table widget.)

-- Matt

 

 

KeithJKeithJ

Thanks for all your help Matt,

Appreciate it.