We're having difficulties trying to figure out why our "expenses" doesn't show up in our webpage.
The expenses is a subclass to the superclass "rental", and we've written:
<td th:text="${expenses.rental_id}"></td>
We've also tried with:
<td th:text="${rental.rental_id}"></td>
but none of the above works.
The error:
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "expenses.full_price" (template: "home/expenses" - line 54, col 9)
[It seems like it's here, the problem happen]
<td th:text="${expenses.rental_id}"></td>
<td th:text="${expenses.base_cost}"></td>
<td th:text="${expenses.rental_end_date}"></td>
<td th:text="${expenses.end_time}"></td>
<td th:text="${expenses.drop_off}"></td>
<td th:text="${expenses.drop_off_extra}"></td>
<td th:text="${expenses.km_end}"></td>
<td th:text="${expenses.repair_fee}"></td>
<td th:text="${expenses.fuel_level}"></td>
<td th:text="${expenses.full_price}"></td>
<td>
<a th:href="#{'/updateExpenses/'+${expenses.rental_id}}">
<button>Edit Expenses</button>
</a>
[This is our homecontroller, we're using when getting the error]
#GetMapping("/expenses/{rental_id}")
public String expenses(#PathVariable("rental_id") int rental_id, Model model){
model.addAttribute("expenses", expensesService.findExpensesById(rental_id));
return "home/expenses";
}
[The button that should send us to the page.]
<a th:href="#{'/expenses/'+${rental.rental_id}}">
<button>Expenses</button>
</a>
[The SQL statement we're trying to use.]
public Expenses findExpensesById(int rental_id){
String sql = "SELECT * FROM expenses WHERE rental_id = ?";
RowMapper<Expenses> rowMapper = new BeanPropertyRowMapper<>(Expenses.class);
Expenses e = template.queryForObject(sql, rowMapper, rental_id);
return e;
}
[We do have both getters and setters for full_price]
public double getFull_price(){
return full_price;
}
public void setFull_price(double full_price) {
this.full_price = full_price;
}
The field is called full_price everywhere. Even in the databasse.
private double full_price;
Related
Follow up on this question
Function to determine winner
How do I use the java function stated on the linked question in thymeleaf HTML form?
Here is the code I have so far, but the function call doesn't work:
<tr th:each="score : ${score}">
<td th:text="${score.player1name}"></td>
<td th:text="${score.player2name}"></td>
<td>
<ul th:each="round : ${score.roundScores}">
<li th:text="${round}"/>
</ul>
</td>
<td th:text="${score.finalscore}"></td>
<td th:text="score.winner : ${score.getWinningScore()}">
<td th:text="${score.sportstype}"></td>
<td><a class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this score?')" th:href="#{/delete/{id}(id=${score.gameid})}">Delete</a></td>
<td><a class="btn btn-primary" th:href="#{/edit/{id}(id=${score.gameid})}">Edit</a></td>
</tr>
</table>
New Game
Here is the funtion I'm trying to call:
public String getWinningScore() {
//Lambda Expressions to convert String array to Int array and calculate sums
int sumOfscore1 = Arrays.stream(player1score).mapToInt(Integer::parseInt).sum();
int sumOfscore2 = Arrays.stream(player2score).mapToInt(Integer::parseInt).sum();
if (sumOfscore1 > sumOfscore2) {
winner = player1name;
} else if (sumOfscore2 > sumOfscore1) {
winner = player2name;
}
return winner;
}
Here is the error I'm getting:
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "score.getWinningScore()" (template: "scorelist" - line 31, col 8)
You don't need get, just try using ${score.winningScore}
Apparently I had empty fields on my html front, and when less than max amount of rounds where played it filled the rest with blank string.
Blank string cannot be inputted to a string list.
I m encountering a problem with the '\n' or in thymleaf the problem is i need to enter to a new line. I have iteretate inside the inside of cell. I m getting the content but just in one line and i want one tweet under the other inside the cell. and i saw as well some similiar topic but it is not working in my case.
This is what i m getting:
How should i manage it to go in the next line inside one cell.
The Thymleaf code:
<tr>
<td th:text="${user.id}">1</td>
<td th:text="${user.getUsername()}">Hamdo</td>
<span th:each="tweet : ${tweets}">
<td th:text="${tweet.content} " ><br/>
<br/>
</td>
</span>
The controller :
#GetMapping({"", "/", "/index", "/index.html"})
public String followers(Principal principal, Model model) {
User user=userService.getUser(principal.getName());
model.addAttribute("tweets",
tweetService.tweetsFromUser(principal.getName()));
model.addAttribute("user",user);
return "index";
}
The service class:
private List<TweetDTO> tweetsFromUser(User user) {
return tweetRepository.findAllByAuthor(user).stream().map(TweetDTO::new).collect(toList());
}
You don't need the extra span... just loop inside of the <td />, like this:
<tr>
<td th:text="${user.id}">1</td>
<td th:text="${user.username}">Hamdo</td>
<td>
<p th:each="tweet : ${tweets}" th:text="${tweet.content}" />
</td>
</tr>
I have the following table and I am wanting to verify that "Vendor Assignment Expired" is in between "Vendor Accepted Assignment" and "Vendor Declined Assignment". What would be the best way to go about doing this?
<table cellspacing="0" cellpadding="0" border="0" style="table-layout: fixed; width: 100%; visibility: inherit;" id="x:1011327536.4:mkr:dataTbl.hdn" mkr="dataTbl.hdn">
<tbody id="x:1011327536.12:mkr:rows:nw:1" class="ig_ListItem igg_ListItem" nw="1" mkr="rows">
<tr id="x:1011327536.13:adr:0:tag:" tag="" adr="0" type="row">
<td class="grdCell" style="width:46%;" idx="0" adr="0" type="cell"> Update Disclosure Date </td>
</tr>
<!--[600001]-->
<tr id="x:1011327536.13:adr:1:tag:" class="ig_ListAlt igg_ListAlt" tag="" adr="1" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Accepted Assignment </td>
</tr>
<!--[101020]-->
<tr id="x:1011327536.13:adr:2:tag:" tag="" adr="2" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Assignment Expired </td>
</tr>
<!--[900101]-->
<tr id="x:1011327536.13:adr:3:tag:" class="ig_ListAlt igg_ListAlt" tag="" adr="3" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Declined Assignment </td>
</tr>
<!--[900102]-->
<tr id="x:1011327536.13:adr:4:tag:" tag="" adr="4" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Conditionally Declined </td>
</tr>
I know I can loop through each item like this:
List<WebElement> row = getDriver().findElements(By.cssSelector(".igg_ListItem > tr > td:nth-child(1)"));
for(WebElement el : row)
{
el.getText();
}
I'm just not sure how to capture the values to perform the assertion that the text displays between the other 2.
You can try this -
List<WebElement> row = getDriver().findElements(By.cssSelector(".igg_ListItem > tr > td:nth-child(1)"));
for (int i =0; i<row.size();i++) {
String status = row.get(i).getText();
if (status.equalsIgnoreCase("Vendor Assignment Expired")) {
if (row.get(i-1).getText().equalsIgnoreCase("Vendor Accepted Assignment")
&& row.get(i+1).getText().equalsIgnoreCase("Vendor Declined Assignment"))
System.out.println("Yes it between those values");
break;
}
}
Let me know if it works! Cheers!
You can use something like below:
Get next column Text and assert it with expected value.
String declinedAssignment = driver.findElement(By.xpath("//tr[td[text()=/"Vendor Assignment Expired/"]]//following-sibling::tr/td")).getText();
Get previous column Text and assert it with expected value.
String acceptedAssignment = driver.findElement(By.xpath("//tr[td[text()=/"Vendor Assignment Expired/"]]//preceding-sibling::tr/td")).getText();
I have html page that extract the information from:
table class="students">
<tbody>
<tr class="rz" style="color:red;" onclick="location.href='//andy.pvt.com';">
<td>
<a title="Display Andy website,Andy" href="//andy.pvt.com">15</a>
</td>
<td>Andy jr</td>
<td align="right">44.31</td>
<td align="right">23.79</td>
<td align="right">57</td>
<td align="right">1,164,700</td>
<td align="right">0.12</td>
<td align="center">
<td align="left">0.99</td>
<td align="right">
</tr>
=
I want to get Andy, 15 andy.pvt.lom.
I am able to extract this table using doc.select(table).get
I am not able to extract the information I am looking.
how to get the "tables.select("xxxx");"
can you please help me with the xxx what I am missing?
You state:
I tried ; tables = doc.select("table").get(0); than tables.select("a title).
You want something more along the lines of
tables.select("a[href]").attr("href"); // to get your String
and
tables.select("a[href]").text(); // to get your number
e.g.,
Elements tables = doc.select("table");
String hrefAttr = tables.select("a[href]").attr("href");
System.out.println("href attribute: " + hrefAttr);
String number = tables.select("a[href]").text();
System.out.println("number: " + number);
in jsp
<table width="100%" id='table1' border="0" cellspacing="2" cellpadding="2">
<tr class="tab-highlighted-2">
<td class="tab-highlighted-2" width="10%">
<div align="left">Project ID</div>
</td>
<td class="tab-highlighted-2" width="10%">
<div align="left">Project Name</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Cost Center</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Manager</div>
</td>
</tr>
<tr class="bg-row1">
<c:forEach items="${resultList}" var="resultList">
<td class="td-highlighted-2">
<div align="left">${resultList.Projid}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Projname}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Cost}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Manager}</div>
</td>
</tr>
</table>
in dao
public final class SearchProjDAO
{
private static InitialContext context;
String CLASS_NAME="DBConnectionFactory";
public ArrayList submitProjectDetails(SearchProjVO searchprojVO)
{
ArrayList ar = new ArrayList();
String methodname="createConnection";
Connection conn = null;
PreparedStatement psmt;
try {
System.out.println("in DAO");
System.out.println("searchprojVO id=="+searchprojVO.getProjid());
conn = DBConnection.getJNDIConnection();
ResultSet rs = null;
String query="select * from CR_EMPLOYEE_DETAILS";if(searchprojVO.getProjid()!=null || searchprojVO.getProjname()!=null || searchprojVO.getManager()!=null)
query=query+" where ";
if(searchprojVO.getProjid()!=null)
query=query+" PROJ_ID="+searchprojVO.getProjid();
if(searchprojVO.getProjname()!=null)
query=query+"PROJ_NAME="+searchprojVO.getProjname();
if(searchprojVO.getCost()!=null);
query=query+"PROJ_COST="+searchprojVO.getCost();
if(searchprojVO.getManager()!=null)
query=query+"PROJ_MANAGER="+searchprojVO.getManager();
psmt= conn.prepareStatement(query);
rs=psmt.executeQuery();
while(rs.next())
{
SearchProjVO projVO = new SearchProjVO();
projVO.setProjid(rs.getString("PROJ_ID"));
projVO.setManager(rs.getString("PROJ_NAME"));
projVO.setProjname(rs.getString("PROJ_COST"));
projVO.setManager(rs.getString("PROJ_MANAGER"));
ar.add(projVO);
}
System.out.println("conn==="+conn);
} catch (Exception e) {
e.printStackTrace(System.err);
}
return ar;
}
}
I spot several mistakes:
Here,
<c:forEach items="${resultList}" var="resultList">
You're overriding the list value with the value of the list item everytime. Don't do that. Give the var an unique variable name. The entity name is the most straightforward choice.
<c:forEach items="${resultList}" var="project">
Note that I'd personally also rename the nothing-saying resultList to a more self-explaining projects.
And here,
<tr class="bg-row1">
<c:forEach items="${resultList}" var="project">
the flow is wrong. You should print a new row inside each loop. Swap them.
<c:forEach items="${resultList}" var="project">
<tr class="bg-row1">
And here,
${resultList.Projid}
${resultList.Projname}
${resultList.Cost}
${resultList.Manager}
the property names must start with lowercase (and fix the item name to be the same as in var).
${project.projid}
${project.projname}
${project.cost}
${project.manager}
Note that I'd personally also get rid of proj prefix in some property names.
And finally you're forgotten a closing </c:forEach>.
</tr>
</c:forEach>
Unrelated to the concrete problem, your JDBC code is sensitive to SQL injection attacks and is leaking resources. Fix it as well.