cancel
Showing results for 
Search instead for 
Did you mean: 

how to populate a drop-down

Former Member
0 Kudos

hiii,

I have a dropdown where i populate values from the database...and the code i have written is...

IModifiableSimpleValueSet mivNoValues = wdContext.nodeMIVDetailsSearchVN().getNodeInfo().getAttribute("mivNo").

getModifiableSimpleType().

getSVServices().getModifiableSimpleValueSet();

mivNoValues.clear();

mivNoValues.put(null,"");

try {

InitialContext ctx = new InitialContext();

DataSource ds = (DataSource)ctx.lookup("jdbc/SAP" + (String) System.getProperties().get("SAPSYSTEMNAME")+"DB");

Connection conn = ds.getConnection();

Statement group_st = null;

ResultSet group_rs = null;

group_st = conn.createStatement();

group_rs = group_st.executeQuery("SELECT MIV_NO FROM EALPS_MIV_DRW");

int index=0;

while(group_rs.next())

{

String miv_no="" +group_rs.getLong(1);

mivNoValues.put(null,miv_no);

index++;

}

group_rs.close();

group_st.close();

}

catch(Exception e)

{

e.printStackTrace();

}

But the only the last record for mivNo is being populated.Please do help out...

and what should be the cardinality for the concerned node??

NB: I have used value node here.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Create a value node say ctx_vn_mivno(1..n) and a value attribute say ctx_va_mivno(long type) in it.

Bind this attribute to ur dropDownByIndex and make the following changes in ur code.



wdContext.nodeCtx_vn_mivno().Invalidate();
 while(group_rs.next())
  {
     IWDNodeElement element =   wdContext.nodeCtx_vn_mivno().createElement();
    element.setAttributeValue("ctx_va_mivno", group_rs.getLong(1));
    wdContext.nodeCtx_vn_mivno().addElement(element);
  }

and whenevr u want to get the selected value u can just get the current selected element of ctx_vn_mivno node.

Regards

Surender Dahiya

Answers (3)

Answers (3)

Former Member
0 Kudos

You use the same key (NULL) for all entries so what do you expect?

Armin

Former Member
0 Kudos

Hi,

Instead of using dropDownBykey u should use dropDownByIndex.

Create a value node (1..n cardinality) and create a value attribute in it.Bind ur dropDownByIndex to this value attribute.

Regards

Surender Dahiya.

Former Member
0 Kudos

Hi,

Why dont you use the drop down by index?

and specify selection cardinality 0..1

Replace the context node and attribute with that of yours.

Ex:Context Structure

NodeX cardinality 0..n seleCardianlity 0..1

Attribute type String


DataSource ds;
	  Connection conn;
	  Statement group_st = null;
	  ResultSet group_rs = null;
	  InitialContext ctx = new InitialContext();
	  try {
	  	  ds = (DataSource)ctx.lookup("jdbc/SAP" + (String) System.getProperties().get("SAPSYSTEMNAME")+"DB");
	  	  conn = ds.getConnection();
		  group_st = conn.createStatement();
		  group_rs = group_st.executeQuery("SELECT MIV_NO FROM EALPS_MIV_DRW");

		  while(group_rs.next())
		  {
			  String miv_no= String.valueOf(group_rs.getLong(1));
			  IWDNodeElement element = wdContext.node<YourNode>().createElement();
			  element.setAttributeValue("<YourAttribute>", miv_no);
			  wdContext.nodeOrders().addElement(element);
		  }
	  }
	  catch(Exception e)
	  {
	  e.printStackTrace(); 
	  }
	  finally
	  {
		  group_rs.close();
		  group_st.close();
		  conn.close();
	  }

Regards

Ayyapparaj