on 01-05-2005 10:51 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.
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
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.