I have a HTML table which initially displays all records in the DB. I have just added a JQuery Datepicker component, and now I want to be able to retrieve records based on date. I have no problem extracting the date from the Datepicker component, but I do have a problem updating the existing HTML table. My code is pretty standard.
<sql:query var="retrieveSecurity" dataSource="jdbc/SecurityApp">SELECT * FROM security</sql:query>
<tbody>
<c:forEach var="row" items="${retrieveSecurity.rows}">
<tr>
<td>${row.security_id}</td>
<td>${row.description}</td>
<td class="center">${row.bid_price}</td>
<td class="center">${row.bid_percent_change}</td>
<td>${row.comment}</td>
</tr>
</c:forEach>
</tbody>
What I basically want to do is to have another SQL query, something like this...
<sql:query var="retrieveSecurity" dataSource="jdbc/SecurityApp">SELECT * FROM security where trade_date = "MYVALUE"
</sql:query>
I then want to be able to update the the tbody tag to point to this new SQL query, and call it instead. The columns won't change, so it should be the same table, just with filtered data. Not sure if what I am asking is the easiest/best solution, just looking for something that will work quickly for a prototype.
Hope this makes sense.
Related
I want to use hx-swap-oob to replace a table row of the existing page "out of band".
in browser:
<table>
<tr id="offer_1">....</tr>
<tr id="offer_2">....</tr> (old)
<tr id="offer_3">....</tr>
</table>
From Server to client:
<table hx-swap-oob="outerHTML:#offer_2" hx-select="#offer_2">
<tr id="offer_2"> .... </tr> (new)
</table>
But up to now this is the result:
<table>
<tr id="offer_1">....</tr>
<table hx-swap-oob="outerHTML:#offer_2" hx-select="#offer_2">
<tr id="offer_2"> .... </tr> (new)
</table>
<tr id="offer_3">....</tr>
</table>
I guess hx-select does not get evaluated when htmx get this snippet from the server.
How can I swap a row out-of-band?
Take a look at the new extension multi-swap.
https://htmx.org/extensions/multi-swap/
It allows swapping multiple elements marked with the id attribute.
For each element it is possible to choose which swap method should be used.
This does work:
<tr hx-swap-oob="true" id="offer_2"> .... </tr> (new)
But it has a drawback:
You need to modify the method which creates this row. Depending on your context, you might already have a method for this. Why modify this method, just because the result of this method should get used out-of-band?
If you use Django, this snippet could get used to add the hx-swap-oob attribute after the HTML got created:
def add_oob_attribute(html):
"""
I would like to avoid this ugly hack
https://github.com/bigskysoftware/htmx/issues/423
"""
assert isinstance(html, SafeString)
new, count = re.subn(r'(<\S+)', r'\1 hx-swap-oob="true"', html, count=1)
if not count == 1:
raise ValueError(f'Could not add hx-swap-oob: {html}')
return mark_safe(new)
I created an issue to find a better solution in the future:
https://github.com/bigskysoftware/htmx/issues/423
<table>
<tr>
<td/>
<td/>
<td/>
</tr>
<tr>
<td/>
<td/>
<td/>
</tr>
.....
</table>
This the table structure I have and I want to provide multi select feature on this table. User should be able to select multiple TR elements - very similar to tag.
But I cannot use because I want to add multiple span elements in each td in the above structure.
I thought of having an event capture on TR. But I am totally at loss as to how to proceed. Any suggestions?
Some of the other things I tried include adding a DIV directly inside TR - but that is incorrect. And adding a div inside the TD is of no use to me in this case.
Try SlickGrid. It pretty much gives you that out of the box. It uses div instead of table, though.
https://github.com/mleibman/SlickGrid
so im having a little problem with my code. I used jdbc to make a query to our SQL database in our DAO like so:
List<Map<String,Object>> results = namedjdbcTemplate.queryForList(FINDALL, namedParameters);
Which is then passed up from the service to the controller where it is added to our model:
List<Map<String,Object>> locations = cmsAttributeService.getAttributeList(id);
model.addAttribute("locationlist", locations);
I then need to display all the entries in our jsp. Currently i do so like this:
<c:forEach items="${locationlist}" var="list">
<tr>
<td>
<c:out value="${list }"></c:out>
</td>
</tr>
</c:forEach>
My problem is the formatting it returns, for example:
{=UCMDB2.Project.name}
How do i get it to return just 'UCMDB2.Project.name' dropping the {= }? Ive tried all sorts of other calls like using list.value, list.key, all of which either break it entirely or blank the results out. Im fairly sure it should be something simple that im just missing. Anyone got any clues?
Changed it to List <String> and it worked.
Automate an application through selenium where id changes dynamically.how can i handle this.Pls help me..
HTML code is:-
<table border="0" cellpadding="0" cellspacing="0" width="1000px">
<tbody><tr id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_trSelectedQuote_0">
<td align="center" valign="middle" width="12%">
<input id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_chkCompare_0" name="ctl00$ctl00$MainContent$CarQuoteMainContent$rpQuotes$ctl00$chkCompare" type="checkbox">
</td>
In both the cases ( and ), I assume that the first part of the ID is unique. So you can use something like this.
//tr[contains(#id,'ctl00_')] and for input field //input[contains(#id,'ctl00_')].
Those don't look like dynamic IDs, but rather non-content-specific row IDs for elements in a list.
If that's the case, you can't immediately ascertain 'This row element is displaying data for MyCarQuotes.com' from this information alone as there's nothing in the HTML shown to base that query on.
If there's something in the rows you can use to 'identify' the content (eg a company name) - and you have a specific 'thing' you want to interact with - you could encapsulate the lookup and do something like
CheckboxForQuoteFromCompany("MyCarQuotes.com").Click();
If you're able to post more of the HTML (at least a full row), and more importantly the intention of your test, we may be able to be of more help.
I'm using Struts2 iterator to setup a list of checkbox in a table. I want to have 10 checkbox per row, so I'm doing the following:
<table>
<tr>
<s:iterator value="securityMasterFields" status="fieldNameStatus" var="fieldName">
<s:if test="#fieldNameStatus.index % 10 ==0">
</tr><tr>
</s:if>
<td>
<s:checkbox name="fieldsToShow" fieldValue="%{fieldName}" value="%{fieldName}"/>
</td>
</s:iterator>
</tr>
</table>
It never goes through the if, so I'm assuming the mod is not been calculated correctly. How do I do it?
thanks
Well, I had to add some parentheses and it worked correctly. The loop was working, it was just that it wasn't going through the if.
<s:if test="(#fieldNameStatus.index % 8 )==0"></tr><tr></s:if>
It looks good to me. Two thoughts:
1) try printing the result of the test in s:property tag
2) It looks like you will have empty table rows... Are you looking at the generated html or just the output, because if it is just the output then unless you have some CSS giving you some table padding and borders, without an empty 'td' element the row might collapse and make it appear as if nothing is being added. So do make sure you print the empty 'td' elements too!