on 01-02-2008 2:06 PM
Hi all,
I want to fill up a drop down box dynamically. i am using ejb to retrive the data from the database.
i got the value for the fiels say for instance "empname" in string [] emp..in my command bean(java bean).
now my empname is like "user1 user2 user3"
want i want is these user1,user2,user3 must be listed in a drop down box.
please help me to fix this problem.
thanx in advance.
Arjun.G
Hi Arjun,
i hope u r using ddbi...instaed use ddbk and use the code as below...
hope that will fix ur issue...
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
IWDNodeInfo ctnam = wdContext.nodeMyBean().getNodeInfo();
// IWDAttributeInfo attInfo = ctnam.getAttribute("empname");
IWDAttributeInfo attInfo = ctnam.getAttribute(IPrivateDropbykey.IMyBeanElement.EMP);
ISimpleTypeModifiable mstype = attInfo.getModifiableSimpleType();
IModifiableSimpleValueSet valueSet = mstype.getSVServices().getModifiableSimpleValueSet();
for(int i=0; i<cat.length;i++) {
valueSet.put(cat<i>,cat<i>);
wdContext.currentMyBeanElement().setEmpname(cat<i>);
}
bye,
xxxxxxxxxxxxxxxxxxxxxxx
shravan..
Edited by: Armin Reichert on Jan 4, 2008 1:08 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To fill a drop-down list (*ByIndex) you need a context node, say "Items", with an attribute "text" (type "string") for storing the texts.
If the content of node "Items" should depend on a property of your bean, use a supply function that creates and adds elements to node "Items" and sets the text attribute values from the bean property.
Example:
void supplyItems(..., IItemsNode node)
{
String[] users = bean.getUsers();
for (int i = 0; i < users.length; ++i)
{
IItemsElement item = node.createItemsElement();
node.addElement(item);
item.setText( users<i> );
}
}
Every time the bean changes, just call invalidate() on node "Items". This will cause the supply function to be called when needed.
Bind the property "texts" of the DropDownByIndex element to the context attribute "Items.text".
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Arjun,
Are the values are as follows:
empname[0] = user1
empname[1] = user2
and so on
Bind a context to the dropdown by index
say node1-->attribute1
add values to these node1 elements as follows
for(int i=0; i<empname.length;i++)
{
IPrivate<viewname>.INode1Element ele = wdContext.nodeNode1().createNode1Element();
ele.setAttribute1(empname<i>);
wdContext.nodeNode1().addElement(ele);
}
Regards,
Murtuza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Murtuza,
my values are as follows
String [] empname = user1 user2 user3
so i cant bind it , as u said... is there by any other means can i use this collection in my drop down...
also i tried to set the attribute using the for loops but it sets the last value alone ...
pls help and thanx 4 ur reply...
Arjun.G
Edited by: arjun swamy on Jan 3, 2008 7:53 AM
Hi,
It will set the last value alone bcoz it is over-writting the previous values. Put the attribute inside a node. Inside a for loop you can create the element of the node and set it with the empname and then add this element to your node.
I didn't got you why you can't use the solution provided by Murtaza.
thanks & regards,
Manoj
Hi,
This is my code :
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
String starr = null;
for(int i=0;i<cat.length;i++){
starr = starr + cat<i>;
wdContext.currentMyBeanElement().setAttributeValue("empname",cat<i>) ;
}
cat [] has got the values as user1 user2 user3 ..
we have the node element defined in our context...as "empname"
now when i use the above code it assigns the last user alone ..but i need all the users to be listed in drop down box...
I hope nw my issue is clear to u all...
thanx.
Arjun.G
Hi,
"This is my code :
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
String starr = null;
for(int i=0;i<cat.length;i++){
starr = starr + cat;
// This is the reason why the last element is displayed you are populating the current Element attribute this will be alwys one
wdContext.currentMyBeanElement().setAttributeValue("empname",cat) ;
}
cat [] has got the values as user1 user2 user3 ..
we have the node element defined in our context...as "empname"
now when i use the above code it assigns the last user alone ..but i need all the users to be listed in drop down box..."
Try
Create a node Named "MyNode"
Create an attribute "MyAttr"
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
String starr = null;
for(int i=0;i<cat.length;i++){
IWDNodeElement nodeElement =wdContext().nodeMyNode().createAndAddElement();
nodeElement.setAttributeValue("MyAttr",cat[<i>]);
}
wdContext().nodeMyNode().setLeadSelection(0);
bind this attribute to the dropdownbyindex.
Regards
Ayyapparaj
Hi Ayyaparaj,
I was able to see the createElement method , but i didnt try it...
The craeteMyBeanElement is also seen, when i initalise this method it gives the error
as "arguments are not appicalble"
This is the code:
Collection starr1 = new Vector();
IPrivateDrop.IMyBeanNode ny = null;
IPrivateDrop.IMyBeanElement myElement = null ;
IWDModel ny1 = null;
myElement = wdContext.currentMyBeanElement();
for(int i =0 ; i<cat.length;i++){
myElement.setEmpname(cat<i>);
starr1.add(myElement);
wdContext.nodeMyBean().bind(starr1);
//wdContext.nodeMyBean().setLeadSelection(0);
/ }
Thanx
Arjun.G
Hi,
Based on the code posted by you
//Returns the values from your bean
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
//Iterate through the values
for(int i=0;i<cat.length;i++){
//Create an instance of the node where the attribute bound to the drop down
IPrivateDrop.IMyBeanElement nodeElement =wdContext().nodeMyBeanNode().createAndAddMyBeanElement();
//Set the value to attribute
nodeElement.setAttributeValue("<YourAttr>",cat[<i>]); // Idont know why this editor behaves like this when i put an [[ ]] around this.
}
//Setting the leadSelection of the node, so that the first element is selected by default. pl take care the node is not null
wdContext().nodeMyBeanNode().setLeadSelection(0);
Regards
Ayyapparaj
Hi Ayyaparaj,
I tried the same what you have posted...
I tried using node element also...it gave me the last value alone because I dont get createAndAddMyBeanElement()..so I used Current Element()..
Can u suggest me the alternative for createAndAddMyBeanElement()...
and Iam using eclipse 2.09,..is that an issue..
Thanx 4 ur replies and patience...
Arjun.G
Edited by: arjun swamy on Jan 4, 2008 10:30 AM
Hi
Alternative
String[] cat = wdContext.currentMyBeanElement().modelObject().dropdown();
ArrayList elements = new ArrayList();
for(int i=0;i<cat.length;i++){
IPrivateDrop.IMyBeanElement nodeElement =wdContext().nodeMyBeanNode().createMyBeanElement();
nodeElement.setAttributeValue("<YourAttr>",cat[<i>]); // Idont know why this editor behaves like this when i put an [ ] around this.
elements.add(nodeElement);
}
wdContext.nodeMyBeanNode().bind(elements);
Regards
Ayyapparaj
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.