cancel
Showing results for 
Search instead for 
Did you mean: 

to fill drop down box dynamically

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

I tried ur code usind the drop down by key...

i used the same code and it worked fine....

though i need it in dd by index this one solves my need...

thanx a lot....

Arjun.G

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Pl go through this

and align your code.

Regards

Ayyapparaj

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

hai,

even this also get last value populated into drop down box

i tried the above example of get the values into dropdownbox

Former Member
0 Kudos

Hi Ayyaparaj,

As per ur suggestion i tried modifying the code but i dont get the

createMyBeanElement(); method , instead i get only currentMybeanElement..

Kindly help me to fix it...

Thanx.

Arjun.G

Former Member
0 Kudos

Hi,

If you have replied for this line

IWDNodeElement nodeElement =wdContext().nodeMyNode().createAndAddElement

are you able to see the method createElement();

Can you post the entire code what you have written and what is not available

Regards

Ayyapparaj

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

I tried this too...

It gives me an error arguments not applicable for the method..createMyBeanElement() ;

error is:

IPrivateDrop.IContextNode is not applicable for the arguments ();

Thanx..

Arjun.G

Former Member
0 Kudos

Hi,

Finally one question is this a model bounded node????

Try the above with a vlue node.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi ,

This is a model bounded node...

should i create a value attrivte within my context which holds the model.in component controller..

Thanx.

Arjun.G.

Edited by: arjun swamy on Jan 4, 2008 10:52 AM