cancel
Showing results for 
Search instead for 
Did you mean: 

displaying the String[] in table

0 Kudos

Hi,

I have a function which return String[] and i would like to display the this String Array so which type i should declare for value Attribute.

can any one help me?

Best Regards

Yasir Noman

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

It depends how you want to represent your String[]

1. If the String[] is a column then you should bind it to the context node with attribute of type String. You can use .bind(List l) method to make it simpler.

2. If the String[] is just an element of a table I would suggest to flatten it and then present it as a table element.

Hope it helps.

Victor.

0 Kudos

Hi victor,

thanks for the reply, actually i can not not give the type String to attribute of a ContextNode because i want to set it with String Array.

i tried and give me error that i can not assign String[] to a String.

any other solutions?

best regards

yasir noman

Former Member
0 Kudos

Hi,

I don't think it is possible. You can bind only simple type to the attribute and String[] is not one of them. You can use bynary wich is byte[] but I don't think this is a good idea. If you will define the Structure and not the simple type then you are requred to bind it to the node element.

So if you want to put <b>all</b> the array to one attribute instance you should flatten it to one large string.

Best Regards,

Victor.

0 Kudos

so how can i flatten it to the large String i never done it b4.

can u guide me in this case?

best regards

Yasir Noman

Former Member
0 Kudos

Hi,

It should be some java routine like the following:


String string_array[] = .....
// in order to increase the performance set the length 
//of StringBuffer in the way it shouldn't resize it. 
//Simply mulyiply the number of Strings in arrayon their 
//maximal length.
len = string_array.lenght * maxStringLen;
StringBuffer all = new StringBuffer(len);
// then append all the strings
for( int i=0;i< string_array.length;i++) {
all.append(string_array<i>);

Hope it helps.

Victor.

0 Kudos

hi victor,

how can i get he maxStringLen?

Former Member
0 Kudos

Hi,

The maxStringLen is something you assume. For example if your strings are names then you can assume that the name wouldn't be longer then 40 chars. In general you are not required to make this it is just some performace tuning. You can simply write:

StringBuffer all = new StringBuffer();

and not

StringBuffer all = new StringBuffer(len);

as I mentioned and it will work.

Regards,

Victor.

0 Kudos

ok so what will be the type of value Attribute boz i have to set the value attribute to this array.

actually thats what i write

Strin dim[]=....

wdContext.currentValueNode.setValueAttribute(dim)

i can not set it with String, so I have no option to set Array in Value Attribute.

Former Member
0 Kudos

Hi Yasir,

after appending all array elements to the StringBuffer, you get the concatted representation of all strings by the toString() method. Code snippet:

String[] yourArr = ...;
StringBuffer sb = new StringBuffer();
for (int ix = 0; ix < yourArr.length; ix++) {
  sb.append(yourArr[ix]);
}
/* Assuming you have a context value attribute of builtin type "string" 
named "concat" on root level of context */
wdContext.currentContextElement().setConcat(sb.toString());

That's all.

BTW, does it really make sense to display this in a single column? How does the content of the column look like, if you have 30 Strings of 30 characters length or so??

Hope that helps anyway.

Regards

Stefan