You need to sign in to do that
Don't have an account?
levon levon
Multiplication Table in Visualforce
Hi, I am creating a simple multiplication table in which I should be selecting numbers from dropdowns which would be a range to generate a multiplication table.
Below is the code I have developed so far. but I am unable to put this multiplicaiton table into proper format. Anyone can please help me.
<apex:page controller="tables">
<apex:form id="frmId">
<apex:sectionHeader title="tables"/>
<apex:pageblock id="pgBlck">
<apex:pageblockSection columns="2">
<apex:outputPanel >
<apex:commandButton value="Generate Table" action="{!generateTable}" />
<apex:commandButton value="Clear Table" action="{!clearTable}"/>
</apex:outputPanel>
<br/>
<apex:pageblocksectionitem >
<apex:outputPanel >
<apex:outputLabel value="Select Table Starting Number"> </apex:outputLabel>
<apex:selectList value="{!selectedNumberOne}" size="1">
<apex:selectOptions value="{!TableNumberList}" />
</apex:selectList>
</apex:outputPanel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputPanel >
<apex:outputLabel value="Select Table Starting Number"> </apex:outputLabel>
<apex:selectList value="{!selectedNumberTwo}" size="1">
<apex:selectOptions value="{!TableNumberList2}" />
</apex:selectList>
</apex:outputPanel>
</apex:pageblocksectionitem>
</apex:pageblockSection>
</apex:pageblock>
<apex:repeat value="{!lstInt}" var="t">
<table>
<tr>
<td>
<apex:outputtext value="{!t}"/>
</td>
</tr>
</table>
</apex:repeat>
</apex:form>
</apex:page>
public with sharing class tables {
public List<Integer> lstInt {get;set;}
public List<List<Integer>> LstIntTbl;
public map<Integer,List<Integer>> mapIntToTableList{get;set;}
public List<Integer> lstOfIInt {get;set;}
public PageReference generateTable() {
mapIntToTableList = new map <Integer,List<Integer>> () ;
lstOfIInt= new List<Integer> ();
lstInt = new List<Integer> ();
for(Integer i=selectedNumberOne; i<= selectedNumberTwo;i++) {
for(Integer j=1; j<selectedNumberTwo;j++ ) {
system.debug('j--'+j);
Integer Sum = j*i;
system.debug('Sum --'+Sum );
lstInt.add(sum);
lstOfIInt.add(i);
system.debug('lstOfIInt--'+lstOfIInt);
if(!mapIntToTableList.ContainsKey(i)){
mapIntToTableList.put(i,lstInt);
}
system.debug('mapIntToTableList--'+mapIntToTableList);
}
}
return null;
}
public integer selectedNumberOne{get;set;}
public integer selectedNumberTwo{get;set;}
//public list<SelectOption> selectOptions {get;set;}
public list<SelectOption> getTableNumberList() {
List<SelectOption> TableNumberList = new List<SelectOption>();
for(Integer i=1; i<=10; i++){
TableNumberList.add(new SelectOption(String.ValueOf(i),String.ValueOf(i)));
}
return TableNumberList;
}
public void clearTable(){
lstInt.clear();
}
public list<SelectOption> getTableNumberList2() {
List<SelectOption> TableNumberList2 = new List<SelectOption>();
for(Integer i=11; i<20; i++){
TableNumberList2.add(new SelectOption(String.ValueOf(i),String.ValueOf(i)));
}
return TableNumberList2;
}
}
Thanks in advance,
Levon Levon
Below is the code I have developed so far. but I am unable to put this multiplicaiton table into proper format. Anyone can please help me.
<apex:page controller="tables">
<apex:form id="frmId">
<apex:sectionHeader title="tables"/>
<apex:pageblock id="pgBlck">
<apex:pageblockSection columns="2">
<apex:outputPanel >
<apex:commandButton value="Generate Table" action="{!generateTable}" />
<apex:commandButton value="Clear Table" action="{!clearTable}"/>
</apex:outputPanel>
<br/>
<apex:pageblocksectionitem >
<apex:outputPanel >
<apex:outputLabel value="Select Table Starting Number"> </apex:outputLabel>
<apex:selectList value="{!selectedNumberOne}" size="1">
<apex:selectOptions value="{!TableNumberList}" />
</apex:selectList>
</apex:outputPanel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputPanel >
<apex:outputLabel value="Select Table Starting Number"> </apex:outputLabel>
<apex:selectList value="{!selectedNumberTwo}" size="1">
<apex:selectOptions value="{!TableNumberList2}" />
</apex:selectList>
</apex:outputPanel>
</apex:pageblocksectionitem>
</apex:pageblockSection>
</apex:pageblock>
<apex:repeat value="{!lstInt}" var="t">
<table>
<tr>
<td>
<apex:outputtext value="{!t}"/>
</td>
</tr>
</table>
</apex:repeat>
</apex:form>
</apex:page>
public with sharing class tables {
public List<Integer> lstInt {get;set;}
public List<List<Integer>> LstIntTbl;
public map<Integer,List<Integer>> mapIntToTableList{get;set;}
public List<Integer> lstOfIInt {get;set;}
public PageReference generateTable() {
mapIntToTableList = new map <Integer,List<Integer>> () ;
lstOfIInt= new List<Integer> ();
lstInt = new List<Integer> ();
for(Integer i=selectedNumberOne; i<= selectedNumberTwo;i++) {
for(Integer j=1; j<selectedNumberTwo;j++ ) {
system.debug('j--'+j);
Integer Sum = j*i;
system.debug('Sum --'+Sum );
lstInt.add(sum);
lstOfIInt.add(i);
system.debug('lstOfIInt--'+lstOfIInt);
if(!mapIntToTableList.ContainsKey(i)){
mapIntToTableList.put(i,lstInt);
}
system.debug('mapIntToTableList--'+mapIntToTableList);
}
}
return null;
}
public integer selectedNumberOne{get;set;}
public integer selectedNumberTwo{get;set;}
//public list<SelectOption> selectOptions {get;set;}
public list<SelectOption> getTableNumberList() {
List<SelectOption> TableNumberList = new List<SelectOption>();
for(Integer i=1; i<=10; i++){
TableNumberList.add(new SelectOption(String.ValueOf(i),String.ValueOf(i)));
}
return TableNumberList;
}
public void clearTable(){
lstInt.clear();
}
public list<SelectOption> getTableNumberList2() {
List<SelectOption> TableNumberList2 = new List<SelectOption>();
for(Integer i=11; i<20; i++){
TableNumberList2.add(new SelectOption(String.ValueOf(i),String.ValueOf(i)));
}
return TableNumberList2;
}
}
Thanks in advance,
Levon Levon
Here is the code for Multiplication table.
VF
Controller