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
pallipalli 

how to Display list of values using List<string>

Hi,

Controller

================

public class ListPrimitiveDataype
{
public List<String> fstName{get;set;}
public List<String> lstName{get;set;}

public ListPrimitiveDataype()
{
fstName= New List<String>();
lstName= New List<String>();
}

public List<String> getfstName()
{
List<String> lst = New List<String>();
lst.add('anil');
return lst;
}

}

 

page

=================

<apex:page controller="ListPrimitiveDataype">
<apex:form >
<apex:pageBlock>
<apex:pageblockTable value="{!fstName}" var="f">
<apex:column value="{!f.lst}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

i have error message here   "  Error: Unknown property 'String.lst'  .....

 

please help me 

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

try this 

 

 

you were not declaring the variable.

 

public class ListPrimitiveDataype
{
Public List<String> fstName{get;set;}
public ListPrimitiveDataype()
{
fstName= New List<String>();
fstName.add('praveen');
fstName.add('anil');
fstName.add('karthik');
}
}

 

 

All Answers

Laxman RaoLaxman Rao

try this

 

you are displaying the list<string> so you do not need any dot notation

 

Vf Page :

<apex:page controller="ListPrimitiveDataype">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!fstName}" var="f">
<apex:column value="{!f}"/>
</apex:pageblockTable>

<apex:pageblockTable value="{!lstName}" var="f">
<apex:column value="{!f}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex Class:

public class ListPrimitiveDataype
{
public List<String> fstName{get;set;}
public List<String> lstName{get;set;}

public ListPrimitiveDataype()
{
fstName= New List<String>();
lstName= New List<String>();

fstName.add('fstName element1');
fstName.add('fstName element2');
fstName.add('fstName element3');

lstName.add('lstName element1');
lstName.add('lstName element2');
lstName.add('lstName element3');
}
}

Praveen KimarPraveen Kimar

Hi,

 

Please try the below code and let me know if it works.

 

public class ListPrimitiveDataype
{
Public List<String> () 
public ListPrimitiveDataype()
{
	fstName= New List<String>();
	fstName.add('praveen');
	fstName.add('anil');
	fstName.add('karthik');
}
}
 
<apex:page controller="ListPrimitiveDataype">
<apex:form >
<apex:pageBlock>
<apex:pageblockTable value="{!fstName}" var="f">
<apex:column value="{!f}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thanks,

Praveen K.

Praveen KimarPraveen Kimar

Sorry, please correct this and try..

 

public class ListPrimitiveDataype
{
Public List<String> {get;set;} 
public ListPrimitiveDataype()
{
	fstName= New List<String>();
	fstName.add('praveen');
	fstName.add('anil');
	fstName.add('karthik');
}
}
 
<apex:page controller="ListPrimitiveDataype">
<apex:form >
<apex:pageBlock>
<apex:pageblockTable value="{!fstName}" var="f">
<apex:column value="{!f}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Laxman RaoLaxman Rao

try this 

 

 

you were not declaring the variable.

 

public class ListPrimitiveDataype
{
Public List<String> fstName{get;set;}
public ListPrimitiveDataype()
{
fstName= New List<String>();
fstName.add('praveen');
fstName.add('anil');
fstName.add('karthik');
}
}

 

 

This was selected as the best answer
Praveen KimarPraveen Kimar

Thanks for the correction Laxman.. 

 

I was just provided the way to display..

 

 

Laxman RaoLaxman Rao

i thought it was palli.

pallipalli

Thank you very much Laxman........

pallipalli

Thank u very much Praveen

pallipalli

hi Laxman now how to display set<string> values in the same manner.........

 

 

please help me

Laxman RaoLaxman Rao

yes you have to display in same manner.

Praveen KimarPraveen Kimar

replace list with set..

 

but make sure set will not accept duplicates strings..

 

Thanks,

Praveen K.