on 05-09-2005 1:42 PM
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
HI,
for(int i=0;i<wdContext.node<<NodeName>>().size();i++)
{
wdContext.node<<NodeName>>().getElementAt(i).getAttributeValue("VEHICLE_REF").equals("<<")
{
//To Do
}
}
Regards, VIP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi:
try:
/people/peter.vignet/blog/2007/01/03/generic-web-dynpro-java-table-filter
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this.
if (e.element("CUSTOMER_REF").getText().equals( wdContext.currentContextElement().getKunde()))
{
wdContext.currentContextElement().setKunde(e.element("CUSTOMER_REF").getText());
}
Regards, VIP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.