Inserting into DB in JPA in play Framework - templates

I am finding difficult to display the template in play framework using groovy
#{list users, as:'user'}
<li>${user}</li>
#{/list}
#{list items:0..10, as:'i'}
${i}
#{/list}
How to combine the above 2 to display like this
My Name
Plays Name
Groovy Name

If I understand you correctly, this is pretty easy to achieve.
To do this in Groovy, using Play, You can simply do
#{list users, as:'user'}
<li>${user_index}. ${user}</li>
#{/list}
See the list tag for more details. http://www.playframework.org/documentation/1.2.2/tags#list
Obviously, you could have just done this with an OrderedList in HTML, using outside of the List tag, which by default in HTML will show a numbered list.
So, your code could simply be
<ol>
#{list users, as:'user'}
<li>${user}</li>
#{/list}
</ol>

No real idea of what your example output is meant to show, but I assume you have:
<ul>
#{list users, as:'user'}
<li>${user}</li>
#{/list}
</ul>
If you change it to <ol> instead of <ul>, you will get an ordered list with numbers:
<ol>
#{list users, as:'user'}
<li>${user}</li>
#{/list}
</ol>

Related

Django - How do I change the sort order of search results while still on the page?

I have a list of results from a user's search and I want the user to be able to re-order them
as they wish. It is simple enough to pre-sort the queryset on the backend, in views.py which is what every Google
search brings up on the topic. But I need to have this done by the user. On the frontend. This is
usually done with a dropdown with options allowing alphabetical sort A-Z or sort by date added or so on.
I can't find an answer with Google search or a single tutorial that covers it, yet I see it used almost everywhere.
Does the solution involve ajax? How would I use ajax to do it? Is there a py module that does this in Django?
I am rendering the search results something like this
{% for stor in stories %}
<div>
<span class="story_block stock_bg">
<a href="{{stor.get_absolute_url}}">
<div class="story_con_block">
<p class="s_t">{{stor.title}}</p>
<p>by <strong>{{stor.author.username}}</strong></p>
<p>{{stor.summary}}</p>
</div>
</a>
</span>
</div>
{% endfor %}
It can be done with javascript if you are rendering the list with javascript. as javascript can manipulate the DOM , so you can sort it with javascript code and add click event to these sorting functions

Creating a Velocity template for Dynamic Data List (Liferay 6.2)

I'm currently working with liferay 6.2 but i'm having problems to create a Display Template for a Dynamic data list. I'm trying to follow this guide:
https://dev.liferay.com/discover/portal/-/knowledge_base/6-2/make-it-pretty-creating-custom-displays#display-templates
But the FreeMarker example doesn't work. I'm trying to create a template in Velocity (since i have more knoledge than FreeMarker):
My code so far is:
<h1>Title</h1>
#set($DDLRecordLocalService = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService"))
#set ($records = $DDLRecordLocalService.getRecords("TitoloDeEmprego"))
#if(!$records.isEmpty())
<h1>$records.getFieldValue("TitoloDeEmprego")</h1>
#end
but i can't get anything from $records
First of all you have to allow your Freemarker/Velocity template to access serviceLocator variable. In order to do this, you need to put the following line in your portal-ext.properties:
# Freemarker template settings
freemarker.engine.restricted.variables=
I think this is the cause, but if you have any other problems, this is simple Freemarker DDL Display Template that works for me:
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>
<#if records?has_content>
<ul>
<#list records as cur_record>
<li>
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("someLinkFieldName", locale), cur_record.getFieldType("someLinkFieldName"))}">
<img src="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("someImageFieldName", locale), cur_record.getFieldType("someImageFieldName"))}" />
</a>
</li>
</#list>
</ul>
</#if>

jsp iterator over list to get specific id

I have below code to iterate over the list to get the radio button populate:
<s:iterator value="custData.custList" id="custNameDetail">
<li>
<s:radio name="custname" list="#{'':custName}" ></s:radio><s:property value="DescriptioMess"/>
</li>
</s:iterator>
Its working perfectly but I want to disable the first radio button. How can I iterate through list to get the specific ids and disable the first radio button?
I am getting below as the output while running the above code for all elements:
<input type="radio" name= "custname" id="custname" checked="checked" value>
I think the problem lies here. I should get the different ids for all and then only I can add disabled="disabled" for the first id.
Please let me know if you guys have come across this issue and you have any suggestions.
Thanks for all your help.
Wasn't working with JSPs for few years but isn't the syntax for variables ${variable}? Like ="${someStruct.id}"?
Posting your Java code may help to put specific answer...
What you can do is add a status variable that will give you information about the loop iteration you are on.
So you can do something like this
<s:iterator value="custData.custList" id="custNameDetail" status="loopStatus">
<li>
<s:if test="#loopStatus.first == true"> //make it disabled
<s:radio name="custname" list="#{'':custName}" ></s:radio><s:property value="DescriptioMess"/>
</s:if>
<s:else>
<s:radio name="custname" list="#{'':custName}" ></s:radio><s:property value="DescriptioMess"/>
</s:else>
</li>
</s:iterator>
See here for more information.

Have separate template for each tab without having separate URL - Django

I'm trying to develop a reporting system using Django. I have to display reports about various categories of data.I have put each category as a tab-tab1,tab2, etc. Is it possible to have different template for each tab without having to change the url.
I have tried template inheritance but that requires have separate url for each tab.
My concern is that if the number of tabs grow, then the number of urls will also increase.
Any suggestions please?
Thanks in Advance.
Why is it a problem for the number of URLs to increase?
Presumably you don't need separate URLconf entries for each tab, you can just capture the tab name in the URL and send it on to the view:
url(r'^reports/(?P<tab_name>\w+)/$', views.reports, name='reports')
...
def reports(request, tab_name):
... do something depending on tab_name ...
You can just use {% include %} tag and include different templates.
And I think it's better to have unique URL for each tab, it least with hashtag.
You can use a library like jquery tabs to create the tabs, then load each template individually either through include as suggested by #DrTyrsa or by a custom template tag (which would be my personal preference).
Here is an example (from the excellent bootstrap framework from twitter):
<ul class="tabs">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="pill-content">
<div class="active" id="home">...</div>
<div id="profile">...</div>
<div id="messages">...</div>
<div id="settings">...</div>
</div>
<script>
$(function () {
$('.tabs').tabs()
})
</script>

How to write this Regex

HTML:
<dt>
<a href="#profile-experience" >Past</a>
</dt>
<dd>
<ul class="past">
<li>
President, CEO & Founder <span class="at">at</span> China Connection
</li>
<li>
Professional Speaker and Trainer <span class="at">at</span> Edgemont Enterprises
</li>
<li>
Nurse & Clinic Manager <span class="at">at</span> <span>USAF</span>
</li>
</ul>
</dd>​​​​​
I want match the <li> node.
I write the Regex:
<dt>.+?Past+?</dt>\s+?<dd>\s+?<ul class=""past"">\s+?(?:<li>\s*?([\W\w]+?)+?\s*?</li>)+\s+?</ul>
In fact they do not work.
No not parse HTML using a regex like it's just a big pile of text. Using a DOM parser is a proper way.
Don't use regular expressions to parse HTML...
Don't use a regular expression to match an html document. It is better to parse it as a DOM tree using a simple state machine instead.
I'm assuming you're trying to get html list items. Since you're not specifying what language you use here's a little pseudo code to get you going:
Pseudo code:
while (iterating through the text)
if (<li> matched)
find position to </li>
put the substring between <li> to </li> to a variable
There are of course numerous third-party libraries that do this sort of thing. Depending on your development environment, you might have a function that does this already (e.g. javascript).
Which language do you use?
If you use Python, you should try lxml: http://lxml.de. With lxml, you can search for the node with tag ul and class "past". You then retrieve its children, which are li, and get text of those nodes.
If you are trying to extract from or manipulate this HTML, xPath, xsl, or CSS selectors in jQuery might be easier and more maintainable than a regex. What exactly is your goal and in what framework are you operating?
please learn to use jQuery for this sort of thing