on 07-19-2010 12:45 PM
Did someone has a sample for creating dynamic checkboxes on a view?
Hi
As for your question 'How to assign the node to the the checkboxes':
For doing that, you should create a CheckBoxGroup and then assign the node to it.
if (firstTime)
{
IWDTransparentContainer container = (IWDTransparentContainer)view.getElement("TransparentContainerCheckboxYear");
IWDCheckBoxGroup cbg =
(IWDCheckBoxGroup) view.createElement(
IWDCheckBoxGroup.class,
"<id for the CheckBoxGroup e.g. yearscbg >");
cbg.bindTexts("Years.YearName");
container.addChild(cbg);
}
However, there is no need to add any of this code. You can very well achive this with few clicks and without any of these lines of code
1.Create a CheckBoxGroup in your view in NWDS
2.Bind the texts property to the 'YearName' property of your 'Years' node.
3. You have already added the elements to 'Years' node in your wdIniti() method.
4.After you deploy the application, the checkboxgroup will directly display the checkboxes with the texts in the Years Node.
In nutshell:
If you need to display the checkboxes dynamically, there is no need to create them in wdModifyView using dynamic programming on all occassions. the CheckBoxGroup actually displays the checkboxes eual in number to the number of elements in the node to wich the texts property is bound. And the texts will be eual to the value of the Attribute of that node to which the texts Property is bound. In short - The context node is the dat source for you checkboxgroup. You just need the elements in your node to display the checkboxgroup.
Regards,
Ajay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I've followed the PDF previously mentionned and it's all ok.
Now, I want to know if it's possible to check (at least) the first checkbox of the checkbox group ? I can't figure out how to access a single checkbox of a checkboxgroup ?
Thanks.
Edited by: Loic Ebran on Aug 12, 2010 11:09 AM
Hi
What's your exact requirement when you say 'creating dynamic checkboxes'?
Do you want to display a set of checkboxes for displaying some options and you don't know the no. of those options at design time or you really wan't to create the checkboxes at runtime using the dynamic programming to create the UI elements in We Dynpro Java?
If displaying the checkboxes group in which the no. of checkboxes is not certain at design time( i.e. you'l know the the number at runtime based on the data in your context node), then you can use a CheckBoxGroup:
1.Create a checkbox group
2.Bind the checkboxgroup's 'texts' property to the attribute of the context node having selection cardinality 0..n
3.Fille the elements in this node
4.Checkboxes will be displayed on the screen with the text same as the value of the attribute of the context node you bind to the texts properties of the CheckBoxGroup and the number equal to the number of elements of the Context Node.
If you actually wanted to create the checkboxes at runtime using Dynamic Programming, you can actually avoid that programming by using the above steps. As the number of checkboxes displayed will be dynamic based on the number of elements in the node anyway. also if you want to make the checboxes visible/invisible then you have an option of doing that by binding the property 'visible' of the checkboxgroups to the context attribute of the type 'IWDVisibility' and you can change the visibility to visible or none at runtime.
Regards,
Ajay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
PLs find below the sap document how to create dynamic checkboxes.
Regards,
Lavanya G
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI ,
Search for the :'how to add dynamic check boxes in webdynpro java page'
go to goole link below and down load the PDF:
http://www.google.co.in/search?hl=en&rlz=1R2SNYK_enIN345&&sa=X&ei=2oJETMi4E4iUrAey5pDnDQ&ved=0CBQQBS...toadddynamiccheckboxesinwebdynprojava+page&spell=1
Regards,
Lavanya.G
Actually I have followting coding:
In wdDoInit:
// Get actual year
Calendar cal = java.util.Calendar.getInstance();
int year = cal.get(java.util.Calendar.YEAR);
int yearold = 2000;
// Get difference between actual year and old year
int difference = year - yearold;
// Add elements to node "Years"
for (int i = 0; i < difference; i++) {
IPrivateViewReplyUISI.IYearsElement Element = wdContext
.createYearsElement();
Element.setYearName("2000");
wdContext.nodeYears().addElement(Element);
}
In Element.setYearName("2000") I say that the text of the added element is always 2000. How can I make this dynamic, so if the value of difference is 10 I want to add elements with text
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
Hi,
Please try this :
// Add elements to node "Years"
cal.add(Calendar.YEAR, -difference);
for (int i = 0; i < difference; i++) {
IPrivateViewReplyUISI.IYearsElement Element = wdContext.createYearsElement();
Element.setYearName(new Integer(cal.get(Calendar.YEAR)).toString(););
wdContext.nodeYears().addElement(Element);
cal.add(Calendar.YEAR,1);
}
Hope it will helps
Regards
Arun Jaiswal
Edited by: Arun Jaiswal on Jul 20, 2010 2:29 PM
Hello Arun,
thank you for your help. I will try this but I can see the result if I create checkboxes for the added elements which is my next problem.
I look to the script how to add dynmaic checkboxgroup to transparent container.But how can I use this for my issue to add checkboxes for the created elements in wdDoModifyView.
Can you please guide me through this part?
For creating test checkboxes in wdModifyView I have following code which works fine:
if (firstTime) {
IWDTransparentContainer container = (IWDTransparentContainer)view.getElement("TransparentContainerCheckboxYear");
for(int i=0; i<10; i++) {
IWDCheckBox CheckBox = (IWDCheckBox)view.createElement(IWDCheckBox.class, "Test" +i);
CheckBox.setText("Dynamisch");
wdContext.getNodeInfo().addAttribute("Year" +i, "com.sap.dictionary.boolean");
CheckBox.bindChecked(wdContext.getNodeInfo().getAttribute("Year" +1));
container.addChild(CheckBox);
}
But how can I add the elements from wdDoInit to this part? I know that I have to refer the "for" part to the size of the node
with for(int i=0; i<node.size(); i++) {
but how I have to go on?
Hi,
I have solve it with a different way like mentioned. I have the coding only in the part wdModifyView as follows:
// Get actual year
Calendar cal = java.util.Calendar.getInstance();
int year = cal.get(java.util.Calendar.YEAR);
final int Yearold = 2000;
// Get difference between actual year and old year
int difference = year - Yearold;
if (firstTime) {
IWDTransparentContainer container = (IWDTransparentContainer) view
.getElement("TransparentContainerCheckboxYear");
cal.add(Calendar.YEAR, -difference);
for (int i = 0; i < difference; i++) {
IWDCheckBox checkbox = (IWDCheckBox) view.createElement(
IWDCheckBox.class, "checkbox" + i);
checkbox.setText(new Integer(cal.get(Calendar.YEAR)).toString());
wdContext.getNodeInfo().addAttribute("checkbox" + i, "com.sap.dictionary.boolean");
checkbox.bindChecked(wdContext.getNodeInfo().getAttribute("checkbox" +i));
container.addChild(checkbox);
cal.add(Calendar.YEAR, 1);
}
}
If someone has a nicer solution please insert it into this thread.
Thanks for all your reply.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.