I have a list of objects. Every Object has a name with a specific prefix. Now I want to replace this prefix with an empty String.
My Code:
Controller:
#Secured("ROLE_ADMIN")
#RequestMapping(value = "/admin/userManagement", method = RequestMethod.GET)
public String showUserManagement(Model model) {
model.addAttribute("userList", userDelegate.getAllUserForClient(getCompanyAuthority().getName()));
model.addAttribute("companyName", getCompanyAuthority().getName());
return "admin/user_management";
}
My html snippet:
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>E-mail</th>
<th th:text="#{adminArea.userManagementReport}">Reports</th>
<th th:text="#{adminArea.userManagementRole}"></th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr th:each="user,itrStat : ${userList}">
<td th:text="${itrStat.index}"></td>
<td th:text="${user.username}"></td>
<td>
<small th:each="report : ${user.reports}"
th:utext="${#strings.replace(report.name,companyName + '_','')} : ${companyName}"></small>
<br th:each="report : ${user.reports}"></br></td>
</tr>
</tbody>
</table>
the Important part is:
<small th:each="report : ${user.rep orts}"
th:utext="${#strings.replace(report.name,companyName + '_','')} : ${companyName}"></small>
For every report name, I want to remove the companyName prefix. So TEST_filename.txt -> filename.txt
Can someone help me?
Use substringAfter:
<small th:each="report : ${user.reports}"
th:utext="${#strings.substringAfter(report.name,'_'}></small>
Of course, you'll want to make sure that your company names don't also contain the underscore delimiter before doing this.
don’t do that ,try this instead ,
to split the String based on "_" and take the second word by mentioning the index .
Related
My Bokeh version is 2.3.1. I'm able to use the CustomJSHover to specify some javascript to execute on hover, with the input being a field (from a column data source). However, I'm trying to map different CustomJSHover's to the same field, and specify them differently in the HTML. An example snippet of what I have is
customjs = CustomJSHover(code="""///do some javascript here on the value var.""")
hover_points = HoverTool(tooltips="""
<div $x{custom} id=$index style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<div>
<span style="font-weight:bold;">Name:</span>
<span>#input_x{custom}</span>
</div>
""",
formatters={
'#input_x' :customjs
},
point_policy='snap_to_data')
This works great, but I want to have multiple custom formaters on input_x. If I try something like this
c1 = CustomJSHover(code="console.log(1);")
c2 = CustomJSHover(code="console.log(2);")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{c2}</td>
<td style="padding:5px;">#input_x{c1}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
'#input_x':c2
},
I only get the console log for c2. Is this possible to achieve? Thanks.
After sleeping on it, I finally found out how to do this.
Within the bracket, you can map a prefix to a formatter. This is in the docs, but the doc's don't tell you how to use it. Within the CustomJSCode argument, you can access this prefix (or if you want just specify the name) with the format variable.
c1 = CustomJSHover(code="""
if(format == 'agg'){ return //do something with agg}
else if(format == 'mean'){return //do something to get the mean}
""")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{agg}</td>
<td style="padding:5px;">#input_x{mean}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
},
If there is a better way to do this, please post an answer. Thanks.
I am using python3.6 with XPath library. Crawling inside the table gives me an empty list. And need to crawl to specific th.
My tr contents are dynamically generated. I need to crawl to tr which has a specific th value. Example In HTML code, the Rank appears in the second tr but it can appear in anywhere in tr. It doesn't have a specific index. Need to get the href from the tr having the Rank th.
My html file:
<tbody>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Product Number
</th>
<td class="a-size-base">
B003NR57BY
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Rank
</th>
<td>
<span>
<span>#3 in Computer Mice</span>
<br>
</span>
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Created Date
</th>
<td class="a-size-base">
June 7, 2010
</td>
</tr>
</tbody>
</table>
Python code:
listings_details = parser.xpath(XPATH_PRODUCT_DETAILS)
for row in listings_details:
th = row.xpath("./th/text()")
if th[0].strip() == 'Rank':
categories = row.xpath("./td/span/span//text()")
qid_url= row.xpath("./td/span/span//#href")
I expect the output to be
Rank: 3,
url : /gp/bestsellers/pc/11036491/ref=pd_zg_hrsr_pc_1_1_last,
category: Computer Mice
Need to get the href from the tr having the Rank th.
Use:
/table/tbody/tr[normalize-space(th)='Rank']/td//a/#href
Note: this works for your provided fragment (now well-formed). You need to add later a context for selecting the table element.
<table>
<tbody>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Product Number</th>
<td class="a-size-base">B003NR57BY</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Rank</th>
<td>
<span>
<span>#3 in
Computer Mice
</span>
<br/>
</span>
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Created Date</th>
<td class="a-size-base">June 7, 2010</td>
</tr>
</tbody>
</table>
Test in http://www.xpathtester.com/xpath/53808ee94dfbc5b38f12791cf857ffb9
I'm trying to implement a method in express router, that would delete an embedded document from a parent document by its _id.
My code looks like this:
.hbs
<table class="table table-striped table-bordered">
<tr>
<th>Title</th>
<th>Description</th>
</tr>
<tr>
<td>{{movie.title}}</td>
<td>{{movie.genre}}</td>
</tr>
</table>
<br>
<table class="table table-striped table-bordered">
<tr>
<th>Author</th>
<th>Comment</th>
<th>Action</th>
</tr>
{{# each movie.comments}}
<tr>
<td>{{this.author}}</td>
<td>{{this.comment}}</td>
<td>Delete</td>
</tr>
{{/each}}
</table>
I can easily get an _id of my embedded doc (single comment), but I can't get an _id of my parent (movie) doc.
On back-end everything seems to be ok, but I get 404 error, because movie._id is empty so my link(/movie/comment/delete//58111f46d7cf8730305e1d5c) doesn't match its pattern in router.
I populate my view with this:
Movie.findById(req.params.id).populate('comments').exec(function(err, movie)
and render the movie object
Since the context changes in #each, try going up a level:
Delete
I am using MVC 5 and Entity framework 6 (Database First) in my application.
I need to update "value" field in View page\index.cshtml.
Is it possible to use #Html.EditorFor to edit Value field for each Item on single button click?
Here is the code in index.cshtml
<table>
<tr>
<th>
Number
</th>
<th>
Name
</th>
<th>
Value
</th>
<th>
Description
</th>
</tr>
foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.number)
</td>
<td>
#Html.DisplayFor(modelItem => item.name)
</td>
<td>
#Html.EditorFor(modelItem => item.value)
#*#Html.ValidationMessageFor(modelItem => item.value) *#
</td>
<td>
#Html.DisplayFor(modelItem => item.description)
</td>
#* <td>
#Html.ActionLink("Edit", "Edit", new { id=item.id })
</td>*#
</tr>
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
On clicking Save button I should update the data in Value field for any number of rows.
It's done in Database First so action for Edit,View,Details are included in Controller.
You'll have to put everything in a to post the details to the server, then you can manage the posted elements. You'll post a list of itens. Maybe this will help you: How can I post a list of items in MVC
Thanks in advance for taking the time to try to help. I am using the Jade templating engine in node.js, and want to generate an HTML table with rows grouped into sections (tbody tags).
Let's say I have the following object in memory:
[
{ type: 'Fruit', name: 'Apple' }
, { type: 'Fruit', name: 'Orange' }
, { type: 'Vegetable', name: 'Carrot' }
, { type: 'Vegetable', name: 'Spinach'}
]
(for simplicity, let's assume the array comes pre-ordered by the "type" column).
And I want to generate a table with rows for each object inside a tbody section for each "type" (Fruit vs. Vegetable). So the HTML I'm trying to generate is:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit">
<tr>
<td>Fruit</td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit</td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable">
<tr>
<td>Vegetable</td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable</td>
<td>Spinach</td>
</tr>
</tbody>
</table>
I think I would want my jade to look something like:
table
thead
th Type
th Name
- var lastType;
each o in objs
- if(o.type != lastType)
tbody(id='#{o.type}')
- lastType = o.type;
tr
td #{o.type}
td #{o.name}
But this generates:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit" />
<tbody>
<tr>
<td>Fruit</td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit</td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable" />
<tbody>
<tr>
<td>Vegetable</td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable</td>
<td>Spinach</td>
</tr>
</tbody>
</table>
Any ideas?
This is in Jade kinda hard to guess, because we don't really see how your indentations are really set in your local code, but here(your posted snippet) it seems like your indentations are not right.
You should try this: +Update (added another loop to get all same types under each body)
table
thead
th Type
th Name
- var lastType;
each o in objs
- if (o.type != lastType)
- lastType = o.type;
tbody(id='#{o.type}')
each t in objs
- if(t.type === lastType)
tr
td #{t.type}
td #{t.name}
Just shift the both tr tags into your tbody, like my code example above.
+Update This will produce this HTML code now:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit">
<tr>
<td>Fruit </td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit </td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable">
<tr>
<td>Vegetable </td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable </td>
<td>Spinach</td>
</tr>
</tbody>
</table>
table
thead
th Type
th Name
tbody#Fruit
tbody
tr
td Fruit
td Apple
tr
td Fruit
td Orange
tbody#Vegetable
tbody
tr
td Vegetable
td Carrot
tr
td Vegetable
td Spinach
You should go with pug basic formate to list the following process