Hi,
I have seen a lot of questions regarding inner class in a apex class in developer community and issues that can be solved by use of inner class. So here I would like to show a problem which can also be solved by inner class.
Syntax of inner class :
Problem :
http://boards.developerforce.com/t5/General-Development/When-i-click-on-add-button-i-need-to-display-one-more-textbox/td-p/286261
When i click on add button i need to display one more textbox
Visual Force Page :
Apex Controller Class
Here textBoxClass is the inner class
In above problem we used iner class now any new text box is binded with a new item in the list listvalueOfTextBox which is of type textBoxClass.
inner class acan be intancitiated like this
outerClass.innerclass instanceOfinnerClass = new outerClass.innerclass();
in above case it will be like
addTextrBox.textBoxClass instaceOftextBoxClass = new addTextrBox.textBoxClass('Test text Box');
Regards,
Ashok.
I have seen a lot of questions regarding inner class in a apex class in developer community and issues that can be solved by use of inner class. So here I would like to show a problem which can also be solved by inner class.
Syntax of inner class :
- public class myOuterClass {
- // Additional myOuterClass code here
- class myInnerClass {
- // myInnerClass code here
- }
- }
Problem :
http://boards.developerforce.com/t5/General-Development/When-i-click-on-add-button-i-need-to-display-one-more-textbox/td-p/286261
When i click on add button i need to display one more textbox
Visual Force Page :
- <apex:page controller="addTextrBox">
- <apex:Form>
- <apex:commandButton Value="Add Text Box" action="{!addTextBox}"/>
- </br>
- <apex:repeat value="{!listvalueOfTextBox}" var="item" rendered="{!IF(listvalueOfTextBox.size > 0 , true , false)}" >
- <apex:outPutLabel value="{!item.textBoxLabel}">
- </apex:outPutLabel>
- <apex:inputText value="{!item.textBoxValue}"/>
- </br>
- </apex:repeat>
- </apex:Form>
- </apex:page>
Apex Controller Class
- public class addTextrBox
- {
- public List<textBoxClass> listValueOfTextBox
- {
- get;
- set;
- }
- public addTextrBox ()
- {
- listvalueOfTextBox = new List<textBoxClass>();
- }
- public PageReference addTextBox()
- {
- try
- {
- listvalueOfTextBox.add(new textBoxClass('TextBox' + (listvalueOfTextBox.size() + 1)));
- }
- catch(Exception e)
- {
- ApexPages.addMessages(e);
- }
- return ApexPages.currentPage();
- }
- public class textBoxClass
- {
- public string textBoxLabel{get;set;}
- public string textBoxValue{get;set;}
- public textBoxClass(String textBoxLabel)
- {
- this.textBoxLabel = textBoxLabel;
- }
- }
- }
Here textBoxClass is the inner class
In above problem we used iner class now any new text box is binded with a new item in the list listvalueOfTextBox which is of type textBoxClass.
inner class acan be intancitiated like this
outerClass.innerclass instanceOfinnerClass = new outerClass.innerclass();
in above case it will be like
addTextrBox.textBoxClass instaceOftextBoxClass = new addTextrBox.textBoxClass('Test text Box');
Regards,
Ashok.
No comments:
Post a Comment