cancel
Showing results for 
Search instead for 
Did you mean: 

populating dropdown with values fetched from the database

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...

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 (2)

Answers (2)

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

Try this code inside your loop


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

Mandeep Virk

Former Member
0 Kudos

Hii Mandeep,

My code is

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++;

}

so it is not possible to put the query within the while loop.

Please do suggest.

Former Member
0 Kudos

try this code:


IPrivate<YourView>.IMIVDetalsSearchVNElement mivNoelement;
// replace <YourView> with actual value

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");



while(group_rs.next())
{
mivNoelement = wdContext.createMIVDetalsSearchVNElement();
String miv_no="" +group_rs.getLong(1);
mivNoelement.setMivNo( miv_no);
wdContext.nodeMIVDetalsSearchVN().addElement(mivNoelement);

}

group_rs.close();
group_st.close();
}
catch(Exception e)
{
e.printStackTrace();
}