cancel
Showing results for 
Search instead for 
Did you mean: 

get special line from tableview

Former Member
0 Kudos
49

hi,

first - my java is crap, but i have to deal with a webdynpro application.

I collect data in a table - but actually i do not need the whole table but only a certain record.

I fill a list in a while loop. Looks like this:


while (iter.hasNext()) {
  Element e = (Element) iter.next();
  IPrivateStep2.ITable1Element Table1 = wdContext.createTable1Element();
  Table1.setORDER_NO(e.element("ORDER_NO").getText());
  if (e.element("DATE") != null) {
    Table1.setDATE(e.element("DATE").getText());
  }
  if (e.element("CUSTOMER_REF") != null) {
    Table1.setCUSTOMER_REF(e.element("CUSTOMER_REF").getText());
  }
  if (e.element("VEHICLE_REF") != null) {
    Table1.setVEHICLE_REF(e.element("VEHICLE_REF").getText());
  }
  wdContext.nodeTable1().addElement(Table1);
}

Now, how do I get a certain record, where in my case the VEHICLE_REF equals a given value.

In fact I don't want the whole table to be shown at all, but only this certain record.

any ideas welcome,

regards, matthias

Message was edited by: Armin Reichert

Edited code section for readability

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

for(int i=0;i<wdContext.node<<NodeName>>().size();i++)

{

wdContext.node<<NodeName>>().getElementAt(i).getAttributeValue("VEHICLE_REF").equals("<<")

{

//To Do

}

}

Regards, VIP

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi:

try:

/people/peter.vignet/blog/2007/01/03/generic-web-dynpro-java-table-filter

regards

monalisa_biswal
Contributor
0 Kudos

U have to iterate over node.Find the value of attribute VEHICLE_REF for each element and compare with the given value.

for(int i=0;i<wdContext.nodeTable1().size();i++)

{

if(wdContext.nodeTable1().getElementAt(i).getAttributeAsText (VEHICLE_REF).equals("Your Text"))

{

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable1().getElementAt(i).getAttributeAsText(CUSTOMER_REF));

break;

}

}

Former Member
0 Kudos

Hi,

Please try the following

if((e.element("CUSTOMER_REF").getText()!=null)&& (wdContext.currentContextElement().getKunde()))

{

if ((e.element("CUSTOMER_REF").getText().equals(wdContext.currentContextElement().getKunde())) && (e.element("VEHICLE_REF").getText().equals(wdContext.currentContextElement().getFahrzeug()))){ wdContext.currentContextElement().setTest(e.element("ORDER_NO").getText());}

}

Regards, VIP

Former Member
0 Kudos

Hi:

try:

/people/peter.vignet/blog/2007/01/03/generic-web-dynpro-java-table-filter

regards

Former Member
0 Kudos

Try this.

if (e.element("CUSTOMER_REF").getText().equals( wdContext.currentContextElement().getKunde()))

{

wdContext.currentContextElement().setKunde(e.element("CUSTOMER_REF").getText());

}

Regards, VIP

Former Member
0 Kudos

I do not understand what you want to achieve, so I must guess.

Do you want to determine a context node element (a table row) that fulfills a certain condition?

Can you please give some more details?

Armin

Former Member
0 Kudos

Yes, I need a certain table row. talking sql it's supposed to become something like: Select * from table where Vehicle_ref = '0815'.

this can become a new table-row.

Do you get what I mean?

thanx, matthias

Former Member
0 Kudos

Where are these data stored, in a Web Dynpro model, a controller context, ...? Shall the result be displayed in a view?

Please give more details.

Armin

Former Member
0 Kudos

I've got a view-context node 'table1' which contains value attributes, which provide the values for my table1. Talking ABAP I'd say, this is an intern table - not a dictionary table. During the while-loop (source above) the value attributes get their values - In layoutmode I created a tableview. I can display the whole tableview afterwards.

But I only want the certain record. During the while-loop I tried something like:

if (e.element("CUSTOMER_REF").getText() == wdContext.currentContextElement().getKunde()){
wdContext.currentContextElement().setKunde(e.element("CUSTOMER_REF").getText());
}

But does not work...

Do you get the idea?

Thanx, Matthias

Former Member
0 Kudos

I guess what you really want is filtering of node elements...

The following code sketch might be useful:


// Returns all elements of the context node that
// fulfill the given condition.
List select(IWDNode node, Condition condition)
{
  List result = new ArrayList();
  for (int i = 0; i < node.size(); ++i)
  {
    IWDNodeElement element = node.getElementAt(i);
    if (condition.holdsFor(element))
    {
      result.add(element);
    }
  }
  return result;
}

// Represents a condition for a node element.
interface Condition
{
  boolean holdsFor(IWDNodeElement element);
}

//@@begin others
private List unfilteredData = new ArrayList(0);
private List filteredData = new ArrayList(0);
//@@end

wdDoInit()
{
  Condition all = new Condition()
  {
    public boolean holdsFor(IWDNodeElement element) { return true; }
  };
  unfilteredData = select(wdContext().nodeTableData(), all);

  Condition customerIs4711 = new Condition()
  {
    public boolean holdsFor(IWDNodeElement element) { return "4711".equals(element.getAttributeValue("Kunde")); }
  };
  filteredData = select(wdContext().nodeTableData(), customerIs4711);

  setFilter(true);
}

void setFilter(boolean filter)
{
  wdContext().nodeTableData().bind(filter ? filteredData : unfilteredData);
}

From an action event handler, you can then call method setFilter() to switch the table display between filtered and unfiltered.

Only a sketch, but I hope you get the idea.

Armin

Former Member
0 Kudos

Hi Armin,

your last solution seems a bit too much for me.

If this would work:


if ((e.element("CUSTOMER_REF").getText().equals(wdContext.currentContextElement().getKunde()))
  && (e.element("VEHICLE_REF").getText().equals(wdContext.currentContextElement().getFahrzeug())))
{
  wdContext.currentContextElement().setTest(e.element("ORDER_NO").getText());
}

I shall be fine - still I get an "null" error

the syntax is ok, though...

thanx, matthias

Message was edited by: Armin Reichert

Edited code section for readability

Former Member
0 Kudos

Ok, try this:


// NULL-safe equals
private boolean equals
(
  Element e,
  String field,
  Object value
)
{
  if (e.element(field) == null)
    throw new IllegalArgumentException("Invalid field " + field);

  String fieldValue = e.element(field).getText();
  if (fieldValue == null)
    return value == null;

  return fieldValue.equals(value);
}

// caller
if ( equals(e, "CUSTOMER_REF", wdContext.currentContextElement().getKunde())
  && equals(e, "VEHICLE_REF", wdContext.currentContextElement().getFahrzeug())
{
  ...
}

Nevertheless, try to understand the code example in my previous post.

Armin