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
Kirill_YunussovKirill_Yunussov 

ISSUE: Assigning data directly to array elements. Possible?

Hi,

 

There seems to be some problem in VisualForce/Apex where it just won't assign values to elements of arrays if you access the elements by subscript number.   So weird.   Maybe I am not using correct syntax?   Please advise!!

 

 

//controller

public String[] someStrings {get;set;}

someStrings = new String[5];

//page

<apex:inputText value="{!someStrings[0]}">


// when using the syntax of someStrings[0], it compiles, but breaks somewhere before even running a method.  Is this a syntax issue or SF limitation??

 

Best Answer chosen by Admin (Salesforce Developers) 
BussBuss

Hi,

 

In VF pages does n't support displaying the array elements as you wrote.

Here you want to dispay only array first element then store that value in a variable (declare as a apex property), then access that variable in VF page.

 

public string str {set; get;}

str = someString[0];

 

<apex:inutField value ={!str}>

 it works...

 

Others wise you wish to to display entire array use data table or page block table with apex:column tag.

 

regards,

Buss.

All Answers

BussBuss

Hi,

 

In VF pages does n't support displaying the array elements as you wrote.

Here you want to dispay only array first element then store that value in a variable (declare as a apex property), then access that variable in VF page.

 

public string str {set; get;}

str = someString[0];

 

<apex:inutField value ={!str}>

 it works...

 

Others wise you wish to to display entire array use data table or page block table with apex:column tag.

 

regards,

Buss.

This was selected as the best answer
Kirill_YunussovKirill_Yunussov

Thanks for clarification, Buss!