How do I nest ${} in gsp - gsp

This is in my gsp and it doesn't work
<g:select name="head.id" from="${com.hive.Persons.findAllByFirstname(${variable})}" optionKey="id" value="${organizationInstance?.head?.id}" />
I think that the main reason is that I am nesting ${}. How can I accomplish this.
${variable} is a string passed from the controller.
thanks!

You don't need the nested ${}
<g:select name="head.id" from="${com.hive.Persons.findAllByFirstname(variable)}" optionKey="id" value="${organizationInstance?.head?.id}" />
should work.

Your from attribute should be populated in controller on the server side.
As a dirty hack you can use the following code:
<g:findAll in="${com.hive.Persons.findAll()}" expr="it.firstname == ${variable}">
<option>${it.firstname}</option>
</g:findAll>

Related

VueJS-3 How to access raw text of a v-model expression

For example if my HTML tag says <input v-model=“foo.bar”> I need the actual text foo.bar, rather than the object that foo.bar resolves to.
In Vue 2 my component was able to use this.$vnode.data.model.expression
What is the equivalent in Vue 3?
It's not documented, and kind of a hack, but I just solved it like this:
For v-model="foo.bar"
In vue2: node.$vnode.data.model.expression
In vue3: node.$attrs['onUpdate:modelValue'].toString() returns $event => ((_ctx.foo.bar) = $event), so you can get your foo.bar from there.

How to write an XPath or CSS expression?

<span class="left-menu-title selectorgadget_selected" data-xpal="xpath-verify-selected" style="">Admin</span>
How can I write an XPath or CSS expression? I tried the plug-ins does not work.
If anyone knows how to click an item from the left-side bar after log-in to the site will be a great help. it does not click, the script fails.
#FindBy(xpath = "//SPAN[#class='left-menu-title'][text()='Admin']")
WebElement clickOnAdmin;
public WebElement adminClick() {
return clickOnAdmin;
}
There are multiple classes but you are checking left-menu-title only.
The case of a SPAN tag name may also be a problem depending on a driver.
Fixed version, using contains() (note that it is not an ideal class XPath check - you need the concat and normalize-space, strictly speaking):
//span[contains(#class, 'left-menu-title')][text()='Admin']
what #alecxe wrote is a very good pointer.
Usually when a website has a strong front-end code embedded with data+JS, you should use functionalities. Especially when absolute xpath does not work such as your case with data var on the front-end. "data-xpal="xpath-verify-selected"
Guru99 xpath fonctionalities
also please verify if your application or website is not embedded with iFrames.
if so please change iframe window.
if you can provide the stackTrace Error. I assume you are talking about NullPointerException or NotFindElementException.
As per the HTML you have shared, the following code block must work :
#FindBy(xpath = "//span[#class='left-menu-title selectorgadget_selected' and contains(.,'Admin')]")
WebElement clickOnAdmin;
public WebElement adminClick() {
clickOnAdmin.click();
}
Note : As you named the function as adminClick(), assuming you want to invoke click() method on the WebElement clickOnAdmin, click() method won't return anything. hence you have to discard the return clickOnAdmin; statement as well.
I would suggest trying writing your XPATH as //span[contains(#class,'left-menu-title') and .='Admin']
And instead of just element.click(); use javascript executor click. Like how it's below:
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", driver.findElement(By.xpath("//span[contains(#class,'left-menu-title') and .='Admin']")));
Hope this works for you! Let me know.

Thymeleaf errors messages optimization

I looked at this tutorial: https://spring.io/guides/gs/validating-form-input.
Using th:errors results in <br> separeted error messages. I want to have an unordered list. So I've defined a fragment like this ...
<td th:fragment="validationMessages(field)" th:if="${#fields != null and field != null and #fields.hasErrors(field)}">
<ul>
<li th:each="error : ${#fields.errors(field)}" th:text="${error}"></li>
</ul>
</td>
... and using it with ...
<td th:replace ="form :: validationMessages('age')"></td>
Is there a "clean code" solution / best practice, like overriding the render implementation of th:errors?
You could probably create your own Thymeleaf Processor, based on org.thymeleaf.spring4.processor.attr.SpringErrorsAttrProcessor, that used your own method of delimiting errors, and then use that rather than the one Thymeleaf gives you. It doesn't look particularly designed for extending, though.
I think the way you did it is probably best. I tend to prefer my HTML templates to be in a templating language (like Thymeleaf) rather than in Java code. You can modify as needed (such as adding styling classes) and it's clear what the code does. This is exactly the kind of thing template fragments are made for.

How to add variable and do loop in CSS

Is it possible to add variable and do loop in css like php:
for($a=6; $a<9; $a++) { "#divShow"+$a }
So, the result will be:
#divShow6 #divShow7 #divShow8
Any idea? Thanks in advance.
No. There are no 'variables' or 'loops' in CSS. It is not a Turing-complete language. This is what CSS classes are for, so you don't have to generate IDs.
You don't have loops in CSS, but if you want to match all the tags with an id that starts with divShow you can use (example http://jsfiddle.net/diegof79/mUGsj/):
div[id^="divShow"]
But I'll recommend to use a class instead.
Also your question shows a match of childrens: divShow8 inside a divShow7. You don't need that kind of selector, because probably the problem can be resolved in another way (by using classes or different id).
Take a look to http://www.w3schools.com/cssref/sel_nth-child.asp maybe it gives you other ideas.

How do you define a single blendable design time instance?

The default Windows 8 project template has a CollectionViewSource in the template.
<CollectionViewSource
x:Name="itemsViewSource"
Source="{Binding Model.Invitations}"
d:Source="{Binding Invitations, Source={d:DesignInstance Type=vm:DesignerFilteredInvitations, IsDesignTimeCreatable=True}}" />
Obviously not all pages have a collection as their model, you can define a DataContext like this:
<vm:MySingleItemViewModel x:Key="Model" />
How do you define the design instance for this kind of model?
Well, design time data is best accomplished like this: http://blog.jerrynixon.com/2012/08/most-people-are-doing-mvvm-all-wrong.html
I realize your question is asking about using d:DesignInstance which also works with this type of technique - just not demonstrated in that article.
All it requires is a good constructor.
Okay, using this works fine:
<Page
d:DataContext="{d:DesignInstance Type=Models:ViewModel, IsDesignTimeCreatable=True}"
And using this works fine:
<d:Page.DataContext>
<Models:ViewModel/>
</d:Page.DataContext>
I must tell you the latter is an easier approach, too. It is also what Visual Studio will generate when you setup a data source in the designer. It also gives you fully-typed bindings. But either is acceptable.
Another note. I can see no good reason to set an object directly to the source of a CollectionViewSource. Normally you would be binding the CVS's Source property to a property inside your ViewModel. But, given your question: Here's how:
<CollectionViewSource
x:Name="TestCVS" Source="{Binding}"
d:DataContext="{Binding Source={d:DesignInstance Type=Models:ViewModel, IsDesignTimeCreatable=True}}"/>
Binding to the Source in the designer caused me endless trouble. But it irritated me more because I knew I would never do it this way. This is what I wanted to do:
<d:Page.DataContext>
<Models:ViewModel/>
</d:Page.DataContext>
<Page.Resources>
    <CollectionViewSource x:Name="TestCVS" Source="{Binding}" />
</Page.Resources>
You better have a great reason for your approach!
Best of luck!

Resources