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
shoesmanshoesman 

how to show the array data in visualforce

hi all,

 

Could someone kindly advise me the below, :smileysad:

 

I have just start coding apex, and am currently trying to develop "math drill application",

but I have completely no idea how to show the array data in visualforce.

 

-----------------------------------

Apex class)

 

Integer [] a = new Integer[2];
       a[0] = 10;
       a[1] = 2;
       a[2] =(a[0]+a[1]);
       return a;

------------------------------------

this is an example of apex class I code, I hope this formula should be alright...

if I want to show this array data "a" in visualforce, how do you code that ????

 

Formula of apex class maybe alright but if its in Java, it should be "system.out.println(a[0]+a[1]);",

but its not accepeted in apex class (Ive got a error when I save it.....) ,therefore I code like "return (value)",

 

---------------------------

Visualforce)

 

{!a[0]}+{![1]}={![2]}

---------------------------

this is the one I code in visualforce, off course, it doesnt work. 


 

There are no information in developper's guide, so could someone advise me with an example???

 

thanks :smileyindifferent:

prageethprageeth

Hello Shoesman;

I don't think that I have completely understood your requirement. Could you show the output that you are expecting to display on the VF page.

 

If you need only to display the data on the page you can use following way. 

How ever your apex code should be changed as below.(Changes are marked in red.) 

 

Controller: 

 

 public Integer[] getMyArray() {

Integer [] a = new Integer[3];

a[0] = 10;

a[1] = 2;

a[2] =(a[0]+a[1]);

return a; 

} 

 Page:

 

<apex:page Controller="ShoesMan">

{!myArray}

</apex:page> 

 

 

 

bob_buzzardbob_buzzard

Can you tell us what you are trying to achieve in terms of the displayed page?

 

I recall from an earlier thread that you were attempting to display the problem, and then the answer.

 

Is the intention to display a single problem in a page, or will there be multiple problems?  

bob_buzzardbob_buzzard

Try this out - I think this is doing what you want:

 

Controller

 

public class MathDrillController { public Problem problem {get; set;} public Boolean showAnswer{get; set;} public MathDrillController() { showAnswer=false; problem=new Problem(); problem.val1=10; problem.val2=2; } public PageReference displayAnswer() { showAnswer=true; return null; } public class Problem { public Integer val1 {get; set;} public Integer val2 {get; set;} public Integer getAnswer() { return val1+val2; } } }

 

Page:

 

 

<apex:page controller="MathDrillController"> <h1>Math Drill</h1> <apex:form > Problem:<br/> What is {!problem.val1} + {!problem.val2}? <apex:outputText rendered="{!showAnswer}">&nbsp;&nbsp;<font color="red">{!problem.answer}</font></apex:outputText> <br/> <apex:commandButton value="Show Answer" action="{!displayAnswer}" rendered="{!NOT(showAnswer)}"/> </apex:form> </apex:page>