In JSP I used to have a table and a link to a record using this syntax:
<td>${person.id}</td>
So I could click the link on a table to move to a person's details page. I would like to achieve the same result using Thymeleaf, but not quite sure how. So my question is: what is Thymeleaf equivalent?
<td th:text="${trip.hrPerson}"></td>
<td><a th:href="#{/remove/trip.id}"></a> ${trip.id} </td>
First example displays static value and it's ok, second is supposed to be a link but it fails.
In Thymleaf you make link as follows
<a th:href="#{'/person/' + $person.id}" th:text="${person.id}">My User id</a>
Related
Hello all brother this is my controller
model.addAttribute("getDataHead",cartHeadStockinService.getDatahead());
System.out.println(model);
and after that I syso to review i get like this
getDataHead=[Cart_HeadStockin [id=101, invoice=fsdfsdf, po=, remark=, supplyId=1, date=null]]
and I want to show this on my Thymeleaf
th:object="${getDataHead}"
th:text="${invoice}"
Hello friend thats great you are able put the context variables in your Model
The way to print the text of your in your Thymeleaf is like this
<span th:text="${getDataHead.invoice}"></span>
Here is a reference link to Thymeleaf documentation
My app is being built with Spring Boot using a MVC pattern, and as template viewer I use Thymeleaf.
I'm generating a dynamic list with Javascript in a form, which I need to collect as a List with the controller.
I have tried to solve it with a #RequestParam, but generating the list with Javascript, as far as I'm concerned, I can't set the Thymeleaf tags.
This is the list:
<ul id="addItemList">
<li class="list-group-item" id="group" name="group" value="Outdoors">Outdoors</li>
<li class="list-group-item" id="group" name="group" value="Entertainment">Entertainment</li>
</ul>
Any indication on which approach I should take, would be much appreciated.
Thanks in advance.
Create a Model having a List as property, and pass it as #ModelAttribute in your controller.
In the end I solved this issue with ajax. I had a button to add an element to the list, which was being made with Javascript. I added a jQuery $.post function to save the item, each time that a new one was added to the list by selecting that button. I didn't find the way to move the whole list from javascript, to the Spring Controller.
Follow the process:
Get the list from controller using ajax
Parse the data then generate li with the retrieved values and update the html of id addItemList
I am practicing to use excel vba to download information from website: http://mops.twse.com.tw/mops/web/t05sr01_1
But I have no idea how to download the data behind click button, as the image shown: http://i.stack.imgur.com/KZHiZ.jpg
I excerpt its web code as below. Could anyone explain me how to code in excel vba to get its data?
Thank you very mush.
Web code:
<td style='text-align:left !important;' nowrap>鴻海</td>
<td style='text-align:left !important;'>105/01/05</td>
<td style='text-align:left !important;'>11:41:00</td>
<td style='text-align:left !important;'>說明媒體報導</td>
<td><input type='button' value='詳細資料' onclick="document.fm_t05sr01_1.SEQ_NO.value='1';document.fm_t05sr01_1.SPOKE_TIME.value='114100';document.fm_t05sr01_1.SPOKE_DATE.value='20160105';document.fm_t05sr01_1.COMPANY_NAME.value='?E??';document.fm_t05sr01_1.COMPANY_ID.value='2317';document.fm_t05sr01_1.skey.value='2317201601051';document.fm_t05sr01_1.hhc_co_name.value='?E??';ajax1(this.form,'table01');">
You haven't shown how you are getting the html.
You can use a CSS selector.
General for first input button
input[type=button]
This says element(s) with input tag having attribute type whole value is 'button'
You apply with the querySelector method, or querySelectorAll if more than one match and then use index for required element.
ie.document.querySelector("input[type=button]").Click
If in an HTMLDocument variable e.g. htmlDoc then
htmlDoc.querySelector("input[type=button]").Click
I am using Watin with Cucumber and Specflow to automate the testing of a web application using a jquery table.
I want to find a specific data in the table, but i don't know how to access the table. When I find the data i am looking for, i want to return the id of the row to pass it to an URL that navigate to the Delete page so I can delete the data.
This is my code in the page:
<tr id="S-1-5-21-373314506-2757628719-1954316189-3686" class="ui-widget-content jqgrow ui-row-ltr" role="row" tabindex="-1">
<td class="ui-state-default jqgrid-rownum" aria-describedby="list_rn" title="2" style="text-align:center;" role="gridcell">2</td>
<td aria-describedby="list_Actions" title="Edit | Details | Delete" style="" role="gridcell">
Edit
|
Details
|
Delete
Ivana Bagur
So, in this example, I want to go through my table and when i find Ivana Bagur, return the tr id attribute so then I can pass this id attribute to effectively delete the element.
Can anyone give me an idea how to go through the table until i find the data and then capture the tr id?
First, something is off in the code you posted as it is not showing entirely correctly; somehow you got actual links to display starting at 'details' rather than your code.
To find the TR ID....general idea:
Find the element containing Ivana Bagur
Find the ancestor of that element that is a TR.
If Ivana is just text in a tablcell it might look like:
string IvanaRowID = ((TableRow)(myIE.Table(myID).tablecell(Find.ByText(myRegexContainingIvanaBagur)).Ancestor("tr"))).Id;
It has been a while since I've done this, and my casting might be a bit off / non-optimal, but the general idea is there.
What's the proper way to create a hyperlink in Spring+JSP? There must be a better way than just coding in the <a href="..."> tag. Take for example a page that displays people. The URL is people.htm. The corresponding controller gets people from the database and performs optional column sorting. The JSP might look like:
<table>
<tr>
<td>Name</td>
<td>Age</td>
<td>Address</td>
</tr>
...
This seems bad as the URL people.htm is hardcoded in the JSP. There should be a way to have Spring automatically build the <a> tag using the URL defined in servlet.xml.
Edit: Maybe I should be using a Spring form.
The only thing that comes to mind is the JSTL standard tag <c:url>. For example:
<c:url var="thisURL" value="homer.jsp">
<c:param name="iq" value="${homer.iq}"/>
<c:param name="checkAgainst" value="marge simpson"/>
</c:url>
Next
Now this won't get you servlet mapping or the like but nothing will. It's not something you could really do programmatically (after all, a servlet can and usually does map to a range of URLs). But this will take care of escaping for you.
I haven't seen this kind of functionality in pure spring (although grails offers things like that).
For your specific case you might consider removing the file part and only using the query string as the href attribute:
<td>Name</td>
<td>Age</td>
<td>Address</td>
These links append the query string to the path component of the current url.
In Spring MVC in jsp:
You can use:
General Hyperlink:
Click Here
If passing from controller:
Click Here
Jsp tags
<c:url var="URL" value="login">
<c:param name="param" value="${parameter}"/>
</c:url>
Click Here
Hope it Helps.. :)
Better way to create link is:
Name
<%=request.getContextPath() %> makes sure that correct URI will be taken into account.
"sort" parameter you can get over with hidden field and change a value with a little bit of javascript:
<input type="hidden" name="sort" id="sort" value="name">
And controller method should look like this:
#RequestMapping("/people")
public String createUser(String sort) {
...
}
Import this package in your jsp file
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
when you want to redirect new page or url then use for eg.
<a href='<c:url value="url of next page" />'>Home</a>