jxls forEach tag : how to define local variables? - jxl

Can we define local variables in jxls which can be used to set an incrementing count for a column.
For eg: Consider the following
<jx:forEach items="${myList}" var="myVar">
-- i need to define a local integer variable here which will have an initial value as 0
-- and i will increment it and display in the output xls's first column
</jx:forEach>
Basically my requirement is to have somekind of local variable declaration in jxls code which i would increment and display in xml.
Any other alternatives are welcome.
Regards,
Rahul

jx:forEach tag support varStatus attribute which defines a name of loop status object which will be passed into bean context for each iteration. The loop status object is an instance of LoopStatus class which has single 'index' property identifying the index of the current item in the collection being iterated
<jx:forEach items="${employees}" var="employee" varStatus="status">
| ${status.index} | ${employee.name} | ${employee.payment} | ${employee.bonus}
</jx:forEach>

Figured it out.... We can use <jx:out expr="hssfRow.getRowNum()" /> in the column where we want to display the numbering. We can keep the above piece of code inside <jx:forEach items="${myList}" var="myVar"> tag

Related

Fetch value from XML using dynamic tag in ESQL

I have an xml
<family>
<child_one>ROY</child_one>
<child_two>VIC</child_two>
</family>
I want to fetch the value from the XML based on the dynamic tag in ESQL. I have tried like this
SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;
Here num is the value received from the input it can be one or two. The result should be value = ROY if num is one and value is VIC if num is two.
The chapter ESQL field reference overview describes this use case:
Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).
So can change your code like this:
SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};
Notice the change of the element type as well, see comment of #kimbert.

0 xsd:anyURI using esql.IBM Integration Bus

<payload xsi:type="ns787:SomeRequest" xmlns:ns787="http://ws.abc.efg.com"/>
I'm working with IIB v10.0.0.7. I'd like to define one of the XML elements to be of type xsd:anyURI using esql. output should be like given above:
I assume that you are asking about the xsi:type attribute. The XMLNSC parser does not automatically populate the namespace prefix in the value of the xsi:type attribute - you must set the entire value (prefix:localName) as a literal text string.
DECLARE namespace787 NAMESPACE 'http://ws.abc.efg.com';
DECLARE namespaceXSI NAMESPACE 'http://www.w3.org/2001/XMLSchema-instance';
CREATE LASTCHILD OF OutputRoot.XMLNSC.payload TYPE XMLNSC.Attribute NAMESPACE namespaceXSI NAME 'type' VALUE 'ns787:SomeRequest';
CREATE LASTCHILD OF OutputRoot.XMLNSC.payload TYPE XMLNSC.NamespaceDecl NAME 'xmlns:ns787' VALUE namespace787;
or, if you prefer using SET instead of CREATE:
...
SET OutputRoot.XMLNSC.payload.(XMLNSC.Attribute)namespaceXSI:type = namespaceXSI;
SET OutputRoot.XMLNSC.payload.(XMLNSC.NamespaceDecl)xmlns:ns787 = namespace787;
If you are still stuck then you may find this technique useful: How to create a complex object in ESQL

Jmeter, Name and value pairs are dynamic in jmeter

I have situation where name and value pair are dynamic,
I did two correlations for name and Value separately.
I have used foreach controller and gave input-value as reference name of "Value" regularexpression. which is executing the loop correctly as the match number of Value.
ForEach controller input index is "Cor_OutputValue" and output index is "Cor_OutputValue1".
Problem is how do i change the "Name" for each request .
Regards,
Sai
ForEach Controller save index of loop in a special variable you can use:
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0
So in case of your controller name is ForEach Controller to get corresponding value of Value variable use __V function:
${__V(Value_${__jm__ForEach Controller__idx})}
If your values start with index 1 you can increment different variable,as idx inside JSR223 PreProcessor:
vars.put("idx", String.valueOf(Integer.parseInt(vars.get("__jm__ForEach Controller__idx"))+1));
And use it later
${__V(Value_${idx})}

Generate and store random variables

I am trying to create some dynamic user defined variables, use them within http requests in JMETER and also save them to file. Basically I'm testing the creation of accounts and would like to save the accounts I've created.
The problem is when I use User Defined Variables and then set the values as below, it only generated the random strings once and in subsequent loops it uses the same data and fails as email already exists:
FIRSTNAME1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
LASTNAME1 Surname${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
EMAIL1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}#emailaddres.com
To save this to file I use:
name1 = vars.get("EMAIL1");
name2 = vars.get("FIRSTNAME1");
name3 = vars.get("LASTNAME1");
f = new FileOutputStream("C://test/Register_new_user_Jmeter.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(name1 + "," + name2 + "," + name3);
f.close(
How do I set this up so I can generate random strings, use them to create new accounts and also save the info to file? Thanks
Yes, User Defined Variables are used for defining once (static) variables, use other component, especially User Parameters for dynamic values.
If a runtime element such as a User Parameters Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then this will replace the initial value, and all other test elements in the thread will see the updated value.
User Parameters are creating variables same as User Defined Variable, but can override pervious values
If there are more threads than values, the values get re-used. For example, this can be used to assign a distinct user id to be used by each thread. User variables can be referenced in any field of any JMeter Component.

Xpath: find an element value from a match of id attribute to id anchor

I would like to find the value of an element matched on id attribute for which I only have the ref - the bit with #, the anchor.
I am looking for the value of partyId:
< party id="partyA" >
< partyId >THEID< /partyId >
but to get there I only have the href from the following
< MyData >
< MyReference href="#partyA" />
Strip the # sign does not look good to me.
Any hints?
Because you haven't provided complete XML documents, I have to use // -- a practice I strongly recommend to avoid.
Suppose that
$vDataRef
is defined as
//MyData/MyReference/#href
and its string value is "#partyA", then one possible XPath expression that selects the wanted node is:
//party[#id=substring($vDataRef,2)]
In case the XML document has a DTD in which the id attribute of party is defined to be of type ID, then it is more convenient and efficient to use the standard XPath function id():
id(substring($vDataRef,2))
Assuming you have your ID as a variable already (lets say $myId), then try using:
//party[contains($myId, #id)]
The contains() function will look to see on each matching node whether or not the partyId attibute is in the value that you pass in.
Alternatively (as that could be considered 'ropey'), you can try:
//party[#id=substring($myId, 2, 1 div 0)]
the substring() function should be a little more precise.

Resources