I am looking for a CLEAN example that explains how pagination is done using thymeleaf and spring boot.
There are a lot of examples out there, but they are not complete.
I am actually looking for an example that implements pagination blocks as well. For example, if the total pages is 150, I would like the pages to show in blocks as in << 1 - 2 - 3 - 4 - 5... >>, when you click the arrows, the next block of pages would show as << 6 - 7 - 8 - 9 - 10... >>
Thank you
I found a simple solution using Java math methods: Math.max and Math.min as follows:
int current = page.getNumber() + 3;
int begin = Math.max(1, current - 5);
int end = Math.min(begin + 6, page.getTotalPages());
I then passed these variables to thymeleaf #numbers.sequence as in:
<li class="page-item"
th:each="i : ${#numbers.sequence(beginIndex, endIndex)} ">
<a th:href="#{/jobs(p=${i})}" th:text="${i}" class="nav-link"
th:classappend="${currentPage}==${i}?'activepagenumber':''"></a>
</li>
Adding onto Issmeil B. answer, just in case if you want to calculate the start and end index on the page, you can call the static class in the Math class. Eg
<div class="paginate-pagination"
th:with="current=${page.number + 3},
beginIndex=${T(java.lang.Math).max(0,current-5)},
endIndex=${T(java.lang.Math).min(begin + 6 , page.totalPages-1)}">
....
</div>
Related
Following is the HTML:
<div class="ajaxcourseindentfix">
<h3>CPSC 353 - Introduction to Computer Security (3) </h3>
<hr>Security goals, security systems, access controls, networks and security, integrity, cryptography fundamentals, authentication. Attacks: software, network, website; management considerations, security standards in government and industry; security issues in requirements, architecture, design, implementation, testing, operation, maintenance, acquisition, and services.
<br>
<br>Prerequisite: CPSC 253U
<span style="display: none !important"> </span> or CPSC 254
<span style="display: none !important"> </span> and CPSC 351
<span style="display: none !important"> </span>
, declared major/minor in CPSC, CPEN, or CPEI
<br>
</div>
I need to fetch the following text from this HTML:
From Line 6 - or
From Line 7 - and
, declared major/minor in CPSC, CPEN, or CPEI
I am able to get the href [Course number: CPSC 254 etc...] with the following XPath:
# This xpath gives me all the tags followed by h3 and then I iterate through them in my script.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::*
Update
And, then the text with the following XPath:
# This xpath gives me all the text after the h3 tag.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::text()
I need to have these course name/prerequisite in the same way they are at URL 1.
In this approach I am getting all the HREF first, then all text. Is there a better way to achieve this? I don't want to iterate over 2 XPaths to get the HREF first, then Text and after that club them to form the prerequisite string.
1 http://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=99648&show
Try to use below code to get required output:
div = soup.select("div.ajaxcourseindentfix")[0]
" ".join([word for word in div.stripped_strings]).split("Prerequisite: ")[-1]
The output is
'CPSC 253U or CPSC 254 and CPSC 351 , declared major/minor in CPSC, CPEN, or CPEI'
I have a Ionic-1 app in which there's a large list that displays images (I use collection-repeat for this).
For now, I ship the images with the app. But the list evolves with time so my app gets the list from a server, then checks if there are new items, and use remote urls for new images.
The list is getting bigger (more tha 300 items), so managing this is quite heavy on the app. Moreover, shipping the images with the app is going to become impossible, because the .apk or .ipa are getting too big.
So I would like to use a better way to manage my images and also a better way to display them dynamically.
Is that possible to call the server images in my collection-repeat and to make it smooth and performant? Is that possible, that once an image has been called, it's saved in the local memory (maybe localStorage) so that the next time the list displayed it's faster ? If yes, how to do this ?
Is that the best way to manage a dynamical list? I would like to hear the best practice for this, for the best UX.
Here's my bit of code:
<div class="boardselection firstScreen" ng-if="transitionFinished">
<ion-item collection-repeat="item in prodataSelect | orderBy:data.sort | filter: data.selectBrand.brand:true | filter: data.selectName.name | filter: generalSearchFunc | filterObj:['brand','modelStrict']" item-width="25%" item-height="35%" item-render-buffer="16">
<a class="optionfuninit item-content" data-proid="{{item.id}}" on-tap="whatToDo(item.id,$event);" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<div class="listviewTrophy" ng-if="isWinning(item.id)">
<i class="icon ion-trophy"></i>
</div>
<i class="icon ion-female" ng-show="item.gender == 'female'"></i>
<!-- <p class="flex-caption" fittext fittext-min="10" fittext-max="15" ng-bind="item.modelStrict" >
{{item.modelStrict}}
</p> -->
<div class="listviewtexts flex-caption" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<span class="listviewtextsmodel">{{item.modelStrict}}</span>
</div>
<div class="imagebox">
<img class="imageoptionsmodel " ng-src="{{imagesUrls[item.imageName]}}"/>
</div>
</a>
</ion-item>
you can use ionic-cache-src (https://github.com/BenBBear/ionic-cache-src)
it will work like :
or
you can use $ImageCacheFactory to save it in cache,
docs here.
Hello I'm wondering why this setting is not working in my TYPO3 6.1
I'm trying to remove typo3's automatic comments like
<!-- header end-->
<!--###main zerogrid### end --></div>
<!--###body2### end --></div>
<!--###body1### end --></div>
<div class="body3"><!--###body3### begin -->
<div class="main zerogrid"><!--###main zerogrid### begin -->
and so on.
FYI, I wrote config.disablePrefixComment=1 in the main TS template setup.
I read typo3 latest reference docs but it's only a simple boolean setting.
Here the TS setup:
config.disablePrefixComment = 1
config.no_cache = 1
config.baseURL = http://xxxx.yyyy.net
# Main TEMPLATE cObject for the BODY
temp.mainTemplate = TEMPLATE
temp.mainTemplate {
# Feeding the content from the Auto-parser to the TEMPLATE cObject:
template =< plugin.tx_automaketemplate_pi1
# Select only the content between the <body>-tags
workOnSubpart = DOCUMENT_BODY
subparts.content < styles.content.get
}
# Main TEMPLATE cObject for the HEAD
temp.headTemplate = TEMPLATE
temp.headTemplate {
# Feeding the content from the Auto-parser to the TEMPLATE cObject:
template =< plugin.tx_automaketemplate_pi1
# Select only the content between the <head>-tags
workOnSubpart = DOCUMENT_HEADER
}
page = PAGE
page.typeNum = 0
page.10 < temp.mainTemplate
# Copying the content from TEMPLATE for <head>-section:
page.headerData.100 < temp.headTemplate
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.value= page1
page.bodyTagCObject.wrap = <body id="|">
plugin.tx_automaketemplate_pi1 {
content = FILE
content.file = fileadmin/templates/zp/index.html
elements {
BODY.all = 1
BODY.all.subpartMarker = DOCUMENT_BODY
HEAD.all = 1
HEAD.all.subpartMarker = DOCUMENT_HEADER
HEAD.rmTagSections = title
TD.all = 1
TABLE.all = 1
TR.all = 1
DIV.all = 1
}
relPathPrefix = fileadmin/templates/zp/
relPathPrefix.A = ./
}
Where am I doing wrong?
Browse with the template analysis your ts. Maybe it gets overwritten somehow?
This setting will only affect comments that are touched by TYPO3 CMS. If you do not replace the blocks, nothing will happen and those comments stay.
The comments are inserted by automaketemplate and have nothing to do with TYPO3 CMS. TYPO3 CMS just sees the parsed template file with all comments and will remove the comments of the replace blocks.
Untouched blocks remain untouched.
Not exactly sure how to search for this issue I have with VBScript, so please forgive if this is a duplicate.
I have a function that prints pagination on a page that takes 2 parameters, totalpgs and active. My issue is that the active page only applies the style on the link when the variable pg is NOT set. I'm pretty sure this is a logic issue but I've been staring at this for 7 days now.
Here is the function:
'======= Print Pagination links
function print_pagination (totalpgs,active)
p = "<div class=""row"">"
p = p & "<div class=""pagination pagination-right"">"
p = p & "<ul>"
for x = 1 to totalpgs
if x = active then
li = "<li class=""active"">" '<- Set class for current page
else
li = "<li>" '<- else regular link
end if
p = p & li & "<a href='?pg="& x &"'>"& x &"</a></li>"
next
p = p & "</ul></div></div>"
print_pagination = p
end function
Here is the code on the page:
pg = request.querystring("pg")
if pg = "" then
pg = 1
end if
<%=print_pagination(totalpages,pg) %>
Here is the desired result:
I want the current <li> to contain a class called active.
This is what's happening:
The active class never gets applied to the <li> tag. When the url contains the get variable of pg, no active class is assigned. When it does not, then it's applied to the first link.
Change your line that does the comparison to this:
if cstr(x) = cstr(active) then
I am completely stumped on this one.
I have the following code:
puts block.at_xpath("*/img")["width"].to_i
but when I change it to
width = block.at_xpath("*/img")["width"].to_i
I get this error:
NokogiriTUT.rb:70:in `blockProcessor': undefined method `[]' for nil:NilClass (NoMethodError)
When I have the puts in there it returns the expected value.
Update:
def blockProcessor(block)
header = block.xpath('td[#class="default"]/*/span[#class="comhead"]')
array = header.text.split
if array[0] != nil #checks to make sure we aren't at the top of the parent list
### Date and Time ###
if array[2] == 'hours' || array[2] == 'minutes'
date = Time.now
else
days = (array[1].to_i * 24 * 60 * 60)
date = Time.now - days
end
##Get Comment##
comment = block.at_xpath('*/span[#class="comment"]')
hash = comment.text.hash
#puts hash
##Manage Parent Here##
width = block.at_xpath("*/img")["width"].to_i
prevlevel = #parent_array[#parent_array.length-1][1]
if width == 0 #has parents
parentURL = header.xpath('a[#href][3]').to_s
parentURL = parentURL[17..23]
parentURL = "http://news.ycombinator.com/item?id=#{parentURL}"
parentdoc = Nokogiri::HTML(open(parentURL))
a = parentdoc.at_xpath("//html/body/center/table/tr[3]/td/table/tr")
nodeparent = blockProcessor(a)
#parent_array = []
node = [hash, width, nodeparent] #id, level, parent
#parent_array.push node
elsif width > prevlevel
nodeparent = #parent_array[#parent_array.length-1][0]
node = [hash, width, nodeparent]
#parent_array.push node
elsif width == prevlevel
nodeparent = #parent_array[#parent_array.length-1][2]
node = [hash, width, nodeparent]
#parent_array.push node
elsif width < prevlevel
until prevlevel == w do
#parent_array.pop
prevlevel = #parent_array[#parent_array.length-1][1]
end
nodeparent = #parent_array[#parent_array.length-1][2]
node = [hash, width, nodeparent]
#parent_array.push node
end
puts "Author: #{array[0]} with hash #{hash} with parent: #{nodeparent}"
##Handles Any Parents of Existing Comments ##
return hash
end
end
end
Here is the block that it is acting on.
<tr>
<td><img src="http://ycombinator.com/images/s.gif" height="1" width="0"></td>
<td valign="top"><center>
<a id="up_3004849" href="vote?for=3004849&dir=up&whence=%2f%78%3f%66%6e%69%64%3d%34%6b%56%68%71%6f%52%4d%38%44"><img src="http://ycombinator.com/images/grayarrow.gif" border="0" vspace="3" hspace="2"></a><span id="down_3004849"></span>
</center></td>
<td class="default">
<div style="margin-top:2px; margin-bottom:-10px; "><span class="comhead">patio11 12 days ago | link | parent | on: Ask HN: What % of your job interviewees pass FizzB...</span></div>
<br><span class="comment"><font color="#000000">Every time FizzBuzz problems come up among engineers, people race to solve them and post their answers, then compete to see who can write increasingly more nifty answers for a question which does not seek niftiness at all.<p>I'm all for intellectual gamesmanship, but these are our professional equivalent of a doctor being asked to identify the difference between blood and water. You can do it. <i>We know</i>. Demonstrating that you can do it is not the point of the exercise. We do it to have a cheap-to-administer test to exclude people-who-cannot-actually-program-despite-previous-job-titles from the expensive portions of the hiring process.</p></font></span><p><font size="1"><u>reply</u></font></p>
</td>
</tr>
Your basic problem is that you don't understand XPath. (You are in good company there; XPath is quite confusing.) Your selectors simply don't match what you think they match. In particular, the one that blows up
*/img
should be
//img
or something like that.
Now, because the xpath selector doesn't match anything, the value of this Ruby statement
block.at_xpath("*/img")
is nil. And nil doesn't support [], so when you try to call ["width"] on it, Ruby complains with a undefined method [] for nil:NilClass error.
And as for why it only blows up when you assign it to a variable... yeah, that's not actually what's happening. You probably changed something else too.
And now, please allow me to make some other hopefully constructive code criticisms:
Your question was apparently designed to make it difficult to answer. In the future, please isolate the code in question, don't just paste in your whole homework assignment (or whatever this screen scraper is for).
It would be extra great if you made it into a single runnable Ruby file that we can execute verbatim on our computers, e.g.:
.
require "nokogiri"
doc = Nokogiri.parse <<-HTML
<tr>
<td><img src="http://ycombinator.com/images/s.gif" height="1" width="0"></td>
<td valign="top"><center>
<a id="up_3004849" href="vote?for=3004849&dir=up&whence=%2f%78%3f%66%6e%69%64%3d%34%6b%56%68%71%6f%52%4d%38%44"><img src="http://ycombinator.com/images/grayarrow.gif" border="0" vspace="3" hspace="2"></a><span id="down_3004849"></span>
</center></td>
<td class="default">
<div style="margin-top:2px; margin-bottom:-10px; ">
<span class="comhead">
patio11 12 days ago | link | parent | on: Ask HN: What % of your job interviewees pass FizzB...
</span>
</div>
<br><span class="comment"><font color="#000000">Every time FizzBuzz problems come up among engineers, people race to solve them and post their answers, then compete to see who can write increasingly more nifty answers for a question which does not seek niftiness at all.<p>I'm all for intellectual gamesmanship, but these are our professional equivalent of a doctor being asked to identify the difference between blood and water. You can do it. <i>We know</i>. Demonstrating that you can do it is not the point of the exercise. We do it to have a cheap-to-administer test to exclude people-who-cannot-actually-program-despite-previous-job-titles from the expensive portions of the hiring process.</p></font></span><p><font size="1"><u>reply</u></font></p>
</td>
</tr>
HTML
width = doc.at_xpath("*/img")["width"].to_i
That way we can debug with our computers, not just with our minds.
You're writing Ruby now, not Java, so conform to Ruby's spacing and naming conventions: file names are snake_case, indentation is 2 spaces, no tabs, etc. It really is difficult to read code that's formatted wrong -- where "wrong" means "non-standard."
Everywhere you have one of those descriptive comments (### Date and Time ###) is an opportunity to extract a method (def date_and_time(array)) and make your code cleaner and easier to debug.