You need to sign in to do that
Don't have an account?
doubleminus
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>
Hi,
Use the List<String> instead of just simple String array.
Thanks,
Kodisana
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.
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.
Did you get the solution you were looking for?
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?
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.
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...
Can you post the apex code and VF code so that i can see where the issue is?
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.
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.
Here's the code:
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.
If I get rid of the get and set statements, then I cannot initialize, manipulate, or otherwise access the list.
If I declare a class within a class I get an error: "unexpected token: class"
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.
Imran,
I am very appreciative of all the help.
The code I am using is posted above.
With the class within a class:
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.
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;}
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".
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.
Wizard,
You stumped me out man.