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
doubleminusdoubleminus 

Possible to populate a pageblocktable column with a String array?

It seems like the val attribute of the pageblocktable tag only works with sobjects. I'm passing it a string array populated by an apex class, with 12 items, and no dice. The table won't populate.

 

Any suggestions?

 

Code looks like this:

                       <apex:pageBlockTable value="{!strings}" var="st">
                            <apex:column value="{!st}"/>
                       </apex:pageBlockTable>

skodisanaskodisana

Hi,

 

Use the List<String> instead of just simple String array.

 

Thanks,

Kodisana

doubleminusdoubleminus

Yes, I am using List<String> in my apex. That's what I meant. No good though. It won't render the strings in the table.

Imran MohammedImran Mohammed

You should use wrapper class to achieve the functionality.

public class outerclass

{

//other functionality

public List<innerclass> innerclassList {get; set;}

 

public outerclass()

{

 innerclasslist = new List<innerclass>();

}

 

//somewherein your outerclass code you should populate 12 values like this.

innerclass ic1 = new innerclass("actual string value you want to display in vf page ");

innerclass ic2 = new innerclass("actual string value you want to display in vf page ");

...

..

innerclasslist.add(ic1);

innerclasslist.add(ic2);

...

...

 

//wrapper class

public class innerclass

{

 public String yourstring {get; set;}

 public innerclass(String s)

 {

 yourstring = s;

 }

}

 

}

 

In vf page:

<apex:pageBlockTable value="{!innerclasslist}" var="st">
 <apex:column value="{!st.yourstring}"/>
</apex:pageBlockTable>

 

 

You are done with what you want,

Make changes accordingly to the above code.

Let me know if you need further help.

Imran MohammedImran Mohammed

Did you get the solution you were looking for?

doubleminusdoubleminus

Imran,

 

For some reason my VF page gives an "unknown property" error for ApexClass.innerclasslist

 

E.g. it cannot find this value:

<apex:pageBlockTable value="{!innerclasslist}" var="st">

 

The property and class are set to public...and I made sure to define the getter and setter as you outlined: public List<innerclass> innerclassList { get; set; }

 

Any ideas?

Imran MohammedImran Mohammed

Add this method to your controller code.

 

public List<InnerClass> getInnerClassDetails()

{

   return innerClassList;

}

 

In VF page, change the pageBlock tag to

<apex:pageBlocTable value="{!innerClassDetails}" var="st">

 

Let me know if you face any issues.

doubleminusdoubleminus

Shouldn't the visualforce read as such? <apex:pageBlocTable value="{!getinnerClassDetails}" var="st">

 

Either way, this does not work, using !innerclassdetails or !getinnerclassdetails. Same error that the property is unknown.

 

I am having a hard time troubleshooting because I just don't understand the interplay here between the apex and VF and why this wouldn't work...

Imran MohammedImran Mohammed

Can you post the apex code and VF code so that i can see where the issue is?

doubleminusdoubleminus

The complete class is hundreds of lines long. The code I'm using for this particular issue is identical to what you've provided. Everything is public, permissions-wise.

Imran MohammedImran Mohammed

I feel this should resolve the issue.

public List<innerclass> innerclassList {get; set;}

Update the above line in your code to something like this

public List<innerclass> innerclasslist {get;}

or

public List<innerclass> innerclasslist;

 

Make sure you initialize the list in constructor whihc i posted earlier.

Let me know what happens after this.

doubleminusdoubleminus

Here's the code:

 

public class outerclass {

      public List<innerclass> innerclassList { get; set; }

      public outerclass () {

          innerclasslist = new List<innerclass>();

          // somewhere in your outerclass code you should populate 12 values like this.
          innerclass ic1 = new innerclass('January');
          innerclass ic2 = new innerclass('February');
          innerclass ic3 = new innerclass('March');
          innerclass ic4 = new innerclass('April');
          innerclass ic5 = new innerclass('May');
          innerclass ic6 = new innerclass('June');
          innerclass ic7 = new innerclass('July');
          innerclass ic8 = new innerclass('August');
          innerclass ic9 = new innerclass('September');
          innerclass ic10 = new innerclass('October');
          innerclass ic11 = new innerclass('November');
          innerclass ic12 = new innerclass('December');

          innerclasslist.add(ic1);
          innerclasslist.add(ic2);
          innerclasslist.add(ic3);
          innerclasslist.add(ic4);
          innerclasslist.add(ic5);
          innerclasslist.add(ic6);
          innerclasslist.add(ic7);
          innerclasslist.add(ic8);
          innerclasslist.add(ic9);
          innerclasslist.add(ic10);
          innerclasslist.add(ic11);
          innerclasslist.add(ic12);
      }
      
      public List<InnerClass> getInnerClassDetails() {
          return innerClassList;
      }   
    }

   public class innerclass {

     public String yourstring {get; set;}

     public innerclass(String s) {
         yourstring = s;
      }
  }

 

 

Imran MohammedImran Mohammed

Are you sure that the inner class is defined inside the Outer class?

I see it is defined outside the Outer class in you code.

doubleminusdoubleminus

 


Imran Mohammed wrote:

I feel this should resolve the issue.

public List<innerclass> innerclassList {get; set;}

Update the above line in your code to something like this

public List<innerclass> innerclasslist {get;}

or

public List<innerclass> innerclasslist;

 

Make sure you initialize the list in constructor whihc i posted earlier.

Let me know what happens after this.


If I get rid of the get and set statements, then I cannot initialize, manipulate, or otherwise access the list.

 

doubleminusdoubleminus

If I declare a class within a class I get an error: "unexpected token: class"

Imran MohammedImran Mohammed

I dont know whats happening wrong here.

Public class outerClass

{

public class innerclass

{

}

}

This is allowed in apex.

 

i recommend you to chop and post the relevant code for me to look into.

 

doubleminusdoubleminus

Imran,

 

I am very appreciative of all the help.

 

The code I am using is posted above.

 

With the class within a class:

 

public class outerclass {

      public List<innerclass> innerclassList { get; set; }

      public outerclass () {

          innerclasslist = new List<innerclass>();

          // somewhere in your outerclass code you should populate 12 values like this.
          innerclass ic1 = new innerclass('January');
          innerclass ic2 = new innerclass('February');
          innerclass ic3 = new innerclass('March');
          innerclass ic4 = new innerclass('April');
          innerclass ic5 = new innerclass('May');
          innerclass ic6 = new innerclass('June');
          innerclass ic7 = new innerclass('July');
          innerclass ic8 = new innerclass('August');
          innerclass ic9 = new innerclass('September');
          innerclass ic10 = new innerclass('October');
          innerclass ic11 = new innerclass('November');
          innerclass ic12 = new innerclass('December');

          innerclasslist.add(ic1);
          innerclasslist.add(ic2);
          innerclasslist.add(ic3);
          innerclasslist.add(ic4);
          innerclasslist.add(ic5);
          innerclasslist.add(ic6);
          innerclasslist.add(ic7);
          innerclasslist.add(ic8);
          innerclasslist.add(ic9);
          innerclasslist.add(ic10);
          innerclasslist.add(ic11);
          innerclasslist.add(ic12);
      }
      
      public List<InnerClass> getInnerClassDetails() {
          return innerClassList;
      }


         public class innerclass {

         public String yourstring {get; set;}

         public innerclass(String s) {
          yourstring = s;
      }
  } 

}

 

 

And visualforce:

                   <apex:pageBlockTable value="{!innerclasslist}" var="st">
                             <apex:column value="{!st.yourstring}"/>
                   </apex:pageBlockTable>

 

 

Also note that !getinnerclasslist does not work.

 

If class within a class is allowed...I do not understand how. I am unable to deploy code because of the aforementioned unexpected token error.

Imran MohammedImran Mohammed

Are you able to save the code with inner class defined in the Outer class.

If yes,

in VF code make the following change.

<apex:pageBlockTable value="{!innerclassDetails}" var="st">
<apex:column value="{!st.yourstring}"/>
</apex:pageBlockTable>

 

In Apex code,

Update the innerClassList declaration to this. Remove {get;set;}

public List<innerclass> innerclassList;

 Please do the changes as i specified and that should work.

Let me know if any issues faced.

doubleminusdoubleminus

 


Imran Mohammed wrote:

Are you able to save the code with inner class defined in the Outer class.

If yes,

in VF code make the following change.

<apex:pageBlockTable value="{!innerclassDetails}" var="st">
 <apex:column value="{!st.yourstring}"/>
</apex:pageBlockTable>

 

In Apex code,

Update the innerClassList declaration to this. Remove {get;set;}

public List<innerclass> innerclassList;

 Please do the changes as i specified and that should work.

Let me know if any issues faced.


 

Imran,

 

As I said before, I cannot declare class within a class. I get an unexpected token error. When I try the above I get the same error, that innerclasslist is an "unknown property".

WizradWizrad

Youre getting some funky replies here.  There is no reason you can't just use a list of strings with a pageBlockTable.

 

Here is some code that is working.

 

 

public with sharing class TestingRandomController {
  public List<String> strList {get; set;}
  
  public TestingRandomController() {
  	strList = new List<String>{'hi','my', 'name', 'is', 'phil'};
  }
}

 

 

 

 

 

<apex:page controller="TestingRandomController">
	<apex:pageBlock >
		<apex:pageBlockTable value="{!strList}" var="str">
			<apex:column value="{!str}" />
		</apex:pageBlockTable>
	</apex:pageBlock>
</apex:page>

 

 

Imran MohammedImran Mohammed

Wizard,

 

You stumped me out man.