Thymeleaf write Placeholder name instead of null - spring-mvc

I don't know if this has already been discussed here, but i have a question.
Is is possible in Thymeleaf to print the Variable name instead of null if it's not there.
For example, in Velocity if i have ${variable1} and i dont set the variable1, it just prints ${variable1}
Thanks

You can do it by Extending Thymeleaf features. I suppose you are thinking of this because of debug reasons, so simply do this:
<p th:text="${var}">var</p>
If the variable does not exist, the text inside is printed.

Related

In gatling, how do I validate the value of a string extracted via the css check?

I'm writing a Gatling simulation, and I want to verify both that a certain element exists, and that the content of one of its attributes starts with a certain substring. E.g.:
val scn: ScenarioBuilder = scenario("BasicSimulation")
.exec(http("request_1")
.get("/path/to/resource")
.check(
status.is(200),
css("form#name", "action").ofType[String].startsWith(BASE_URL).saveAs("next_url")))
Now, when I add the startsWith above, the compiler reports an error that says startsWith is not a member of io.gatling.http.check.body.HttpBodyCssCheckBuilder[String]. If I leave the startsWith out, then everything works just fine. I know that the expected form element is there, but I cant confirm that its #action attribute starts with the correct base.
How can I confirm that the attribute start with a certain substring?
Refer this https://gatling.io/docs/2.3/general/scenario/
I have copied the below from there but it is a session function and will work like below :-
doIf(session => session("myKey").as[String].startsWith("admin")) { // executed if the session value stored in "myKey" starts with "admin" exec(http("if true").get("..."))}
I just had the same problem. I guess one option is to use a validator, but I'm not sure how if you can declare one on the fly to validate against your BASE_URL (the documentation doesn't really give any examples). You can use transform and is.
Could look like this:
css("form#name", "action").transform(_.startsWith(BASE_URL)).is(true)
If you also want to include the saveAs call in one go you could probably also do something like this:
css("form#name", "action").transform(_.substring(0, BASE_URL.length)).is(BASE_URL).saveAs
But that's harder to read. Also I'm not sure what happens when substring throws an exception (like IndexOutOfBounds).

Dynamic Url in Jitterbit Http Target

I am wanting to call the following URL in my Jitterbit HTTP target:
https://xxx.visualstudio.com/DefaultCollection/_apis/wit/workitems/[vstsId]?api-version=1.0
where [vstsId] is dynamic and should be supplied from a global variable.
Is it possible to have dynamic urls in the target?
I could make the whole url dynamic if need be.
Any ideas? (I'm using javascript scripting rather than the Jitterbit scripting)
Thanks
Martin
Yes, you have it typed out correctly. At the beginning of your operation chain (or at the point where you know what $vstsld should be, and you can declare it), simply add a script to declare it, or add it into a transformation where you get the data from. At any point after that, in the current operation chain, you can access the value in that variable. Just make sure you set it with the $ symbol, which makes it global.
$vstsld='some value';
As W3bguy said. you call it in the script as $vstsld. Now you can pass in a test value data into your variable as well. just add the curly brackets inside your variable like the below
example
https://xxx.visualstudio.com/DefaultCollection/_apis/wit/workitems/[vstsId{1234}]?api-version=1.0

OSB reporting, report multiple content. $body, $inbound, $outbound

I am trying to put multiple values inside this content with this XQuery Expression Builder. I tried to use a string function like thisfn:concat($body, $inbound, $inbound), but this does not seems to keep the whole message.
Is there any way that I can put all these variables in one report action? If this is possble then how should I read these values out after they are stored in the database(some key value structure would be perfect).
You only need to form a xml with the content you want to show in your report:
<report>
<body>{$body}</body>
<inbound>{$inbound}</inbound>
...
</report>
the only requirement is that the output have to be an XML no matter the structure.
Not sure, but I would try something like this:
<myroot>{$body, $inbound, $outbound}</myroot>
Or if you really need a string returned:
fn:serialize(<myroot>{$body, $inbound, $outbound}</myroot>)
Note, fn:serialize is only in OSB 12c+.

How should I get Keyword Key from DWT

This is similar to this XSLT question, but ultimately for DWT.
We can get a keyword's key via a C# TBB.
ItemFields fields = new ItemFields(component.Metadata, component.Schema);
KeywordField keywordField = fields["state"] as KeywordField;
String stateValue = package.EvaluateExpression("Component.Metadata.state");
package.PushItem("statekey", package.CreateStringItem(ContentType.Text, keywordField.Value.Key));
In DWT, I sometimes want the key of a selected keyword in a component.
Is adding and getting these from the package the correct approach?
##Component.Metadata.State## gets me the value. Referencing the key directly from DWT would be great, but I haven't seen anything to suggest DWT exposes it.
As another alternative to John's answer. How about taking a similar approach to Will's "Get Component Template Uris" and write a TBB that iterates over a category's keywords and writes them out into the package with the desired output value? You'd then be able to use these values directly from DWT with a "double-evaluation" like:
##Keyword${Component.Metadata.state}Value##
I suspect for this you would need to go down the TBB route as you suggest, or even write your own DWT function to expose it.
You can find an example of creating DWT functions here: http://www.tridiondeveloper.com/get-and-set-variables-in-dwts

How to extract element id attribute values from HTML

I am trying to work out the overhead of the ASP.NET auto-naming of server controls. I have a page which contains 7,000 lines of HTML rendered from hundreds of nested ASP.NET controls, many of which have id / name attributes that are hundreds of characters in length.
What I would ideally like is something that would extract every HTML attribute value that begins with "ctl00" into a list. The regex Find function in Notepad++ would be perfect, if only I knew what the regex should be?
As an example, if the HTML is:
<input name="ctl00$Header$Search$Keywords" type="text" maxlength="50" class="search" />
I would like the output to be something like:
name="ctl00$Header$Search$Keywords"
A more advanced search might include the element name as well (e.g. control type):
input|name="ctl00$Header$Search$Keywords"
In order to cope with both Id and Name attributes I will simply rerun the search looking for Id instead of Name (i.e. I don't need something that will search for both at the same time).
The final output will be an excel report that lists the number of server controls on the page, and the length of the name of each, possibly sorted by control type.
Quick and dirty:
Search for
\w+\s*=\s*"ctl00[^"]*"
This will match any text that looks like an attribute, e.g. name="ctl00test" or attr = "ctl00longer text". It will not check whether this really occurs within an HTML tag - that's a little more difficult to do and perhaps unnecessary? It will also not check for escaped quotes within the tag's name. As usual with regexes, the complexity required depends on what exactly you want to match and what your input looks like...
"7000"? "Hundreds"? Dear god.
Since you're just looking at source in a text editor, try this... /(id|name)="ct[^"]*"/
Answering my own question, the easiest way to do this is to use BeautifulSoup, the 'dirty HTML' Python parser whose tagline is:
"You didn't write that awful page. You're just trying to get some data out of it. Right now, you don't really care what HTML is supposed to look like. Neither does this parser."
It works, and it's available from here - http://crummy.com/software/BeautifulSoup
I suggest xpath, as in this question

Resources