I need to set custom attribute (data-validation-matches-message) value from messages resources.
<input data-validation-matches-message="Text from messages resources" />
I can receive and print messages resources value as:
<p th:text="#{user.notfound}"></p>
But how I can set this value for a custom attribute (data-validation-matches-message)?
UPD (I use this)
<input th:attr="data-validation-matches-message=#{user.notfound}"/>
Since Thymeleaf 2.1 you can do this:
<a data-th-attr="data-groupid=${somevalue}, data-groupname=${someothervalue}">...</a>
source
Try this:
<input th:attr="data-validation-matches-message='\'' + #{user.notfound}" + '\''"/>
Using 3.0.9.RELEASE:
<td th:text="${item.description}" th:attr="width=${isSplit} ? '44%' : '59%'" />
This will add width="44%" or width="59%according to a boolean set in the variables.
width might as well have been any other custom attribute.
Related
Is it possible with thymeleaf to retrieve an input "generated" name attribute ?
I need to create a div with an id equals to an input name attribute.
Input names are generated via the th:field.
Markup:
<input type="radio" id="winterTiresInstalled" th:field="*{winterTiresInstalled.value}" />
Generated markup:
<input id="fld_winterTires" type="radio" name="vehicle.winterTiresInstalled.value" />
What I want :
<div th:id="???" />
to obtain :
<div id="vehicle.winterTiresInstalled.value" />
So, how can I retrieve the generated name attribute value "vehicle.winterTiresInstalled.value" with thymleaf ?
I could do it in js but I would prefer doing it in my template.
Thank you.
David
th-attr is best suited for this use case.
<a href="#" th:attr="data-id=${object.getId()}, data-name=${object.getName()}"/>
The above will result is something like this(haven't tested)
<a href="#" data-id="420" data-name="user-link"/>
Did the solution in javascript for now. I change the id of div after the page loads.
I would prefer do it directly in my template but can't figure out a way to do it with thymeleaf.
I am stuck in changing the font color of
<s:textfield name="name" key="user.name"/>
Here user.name=User comes from resource bundle. So in JSP HTML page, it displays User Name label and a textfield, but I want to change the font of User Name label.
You can do this with CSS attribute selector. Give your <s:textfield> an id and reference this id in CSS like that:
<style type="text/css">
label[for="nameFieldId"] {
color: red;
}
</style>
<s:textfield id="nameFieldId" name="name" key="user.name"/>
This will work because xhtml theme generates <label> for <s:textfield> tag with for attribute.
Can you try below code
<s:label value="user.name" cssStyle="color: #ffffff;"/>
<s:textfield name="name" required="true"/>
if not work above code
Struts support Theme and template feature for more information refer below link
http://www.mkyong.com/struts2/working-with-struts-2-theme-template/ (Link have exmple for showing error message with color)
and do changes according to your requirement
1.First define your textfield like this:
<s:textfield id="tf1" size="150%" />
2.Then create a label tag pointing to your created textfield like this:
<s:label for="tf1" style="font-family:Arial;color: #af2d2d" value="my textfield"/>
Hope this helps!!
Can you check <s:testfield> tag will support style attribute? If supports do like this
<s:testfield name=“name” key=“user.name” style="color:red;"/>
or else do like this
<span style="color:red;">
<s:testfield name=“name” key=“user.name” style="color:red;"/>
</span>
in above line displays red color..if your want your custom color change red to your custom color
I would put my JSP file in HTML5 format.
I have a problem with the tag struts radio button;
when I put cssclass"disabled" ( or other like cssClass"red" ) , when I look the source I get twice attribute class="disabled".
But It works nice for the other struts tag.
See example below:
JSP file:
<s:radio cssClass="disabled" name="mirror.swiBlo" list="Y"/>
source:
<input type="radio" name="mirror.swiBlo" id="consultation_mirror_swiBloY" value="Y" class="disabled" class="disabled"/>
If someone has any idea to solve that.
Thanks
Actually it's a bug in struts.
In simple/radiomap.ftl setting of class and style occurs twice.
source code:
<#if parameters.cssClass??>
class="${parameters.cssClass?html}"<#rt/>
</#if>
<#if parameters.cssStyle??>
style="${parameters.cssStyle?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/css.ftl" />
And css.ftl handle class and style again.
How to get the attribute of Title in the input element
<input type="image" title="Previous Page">
<input type="image" title="First Page">
<input type="image" title="Next Page">
<input type="image" title="Last Page">
What have you tried? Typically something like the following should work:
WebElement element = driver.findElement(By.tagName("input"));
String title = element.getAttribute("title");
The answer provided by Jim Evans is the correct one imo, but for a more specific one i'd advise something like below. Remeber that copy-pasta might not work and you need to change something to be able to work on your full HTML.
List<WebElement> elements = driver.findElements(By.tagName("input"));
for (WebElement element : elements) {
if (element.getAttribute("type").equals("image")) {
System.out.println(element.getAttribute("title"));
}
}
The above code will loop for all the in your webpage that are from type="image" and print on the console the "title" attribute of each one of those.
Still thing you should vote Jim's answer as the correct one though.
First, you need to identify the input element from which you want to get the value of the attribute title .
Then something like the following must work.
element.getAttribute("title");
Its very simple and work for as well.
String title = driver.getTitle();
I have a table, using display tag, in my application, that is using spring web flow. I would like to have a check box in each row, a button that allows me to select/uselect all and a button to execute a function. After clicking the button, the action will perform some database actions and the page should be render, so we can see these changes.
I don´t know which could be the best option, submitting the whole table
<form method="POST" (more params)>
<display:table id="row">
....
</display:table>
</form>
Or only the checkbox column. I this case I wouldn´t know how to implement it.
I have tryed two different approaches:
1. Using a simple input text, checkbox type. This is not possible, because when I submit the form, I need to set a path to another page.jsp (I am working with flows). Besides, I wouldn´t know how to send these values to java backend.
Using spring tags.
In this case, the problem comes whith the class conversationAction
I found some examples, but allways using MVC and controller cases.
How could I implement this issue??
EDIT
I have found a kind of solution, but I faced a new problem...
flow.xml
var name="model1" class="com.project.Model1"/>
var name="model2" class="com.project.Model2"/>
view-state id="overview" model="formAggregation">
...
</view-state>
page.jsp
form:form modelAttribute="formAggregation.model1" id="overviewForm">
...
/form:form>
...
form:form method="POST" modelAttribute="formAggregation.model2">
display:table id="row" name="displayTagValueList" requestURI="overview?_eventId=tableAction">
display:column title="">
form:checkbox path="conversationIds" value="${row.threadId}"/>
/display:column>
/display:table>
input type="submit" name="_eventId_oneFunction" value="Send>>"/>
/form:form>
FormAggregation.java
#Component("formAggregation")
public class FormAggregation {
private Model1 model1;
private Model2 model2;
//Getters and setters
I need this aggregator, because I need both models. I have tested it one by one and it is working as wished. Any idea about that??
Thanks!!
I couldn´t find a solution to add two model in a view-state. So I made a workaround, adding the fields I needed to the model I was using, com.project.Model1. So the result is:
page.jsp
<form:form method="POST" id="tableForm" modelAttribute="model1">
<display:table id="row">
<display:column title="">
<form:checkbox path="chosenIds" value="${row.id}"/>
</display:column>
<display:footer>
<div class="tableFooter" >
<input type="submit" name="_eventId_workIds" value="Send"/>
</div>
</display:footer>
</display:table>
</form:form>
flow.xml
<var name="model1" class="com.project.Model1"/>
...
<transition on="workIds" to="overview" validate="false">
<evaluate expression="actionBean.workIds(model1.chosenIds)" />
</transition>
java class
public void workIds(List<Long> ids) {
Hope it helps