I have a user drop down in my JSP page where I show the user list. In the drop down I need to show the user name and email as the label while value will be user id and user email address. So I need to concatenate the properties of my user instance to show the proper label and values.
What is the best possible approach to do this in the Spring MVC?
I can iterate over the list in my Spring Controller and concatenate the properties and then create a new list which will be displayed in the page. This is the way I can think of.
Any better ideas?
Add users list object to the model and use standard tag lib to build the html
<select id="users" name="users">
<c:forEach items="users" var="user">
<option value="${user.id}">${user.name} [${user.email}]</option>
</c:forEach>
</select>
Related
I'm trying to create a custom registration form in Keycloak that will create the user and assign them to a group depending on a team drop down selection. Here is an example of my problem:
I have multiple teams that will be using keycloak and each team will have their own group in keycloak mapping out all the roles that they need access to. One app that will be using keycloak authentication is Grafana. When a user goes to Grafana and tries to register for a new account via keycloak, it creates the user, but because the user isn't assigned to a group, they land at an error page in Grafana because they don't have any privilege.
I'm trying to limit the amount of manual work to assign hundreds of users to groups after they register. I don't have access to LDAP or Active Directroy.
Here is an example of what i've tried in my custom register.ftl template.
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('team',properties.kcFormGroupErrorClass!)}">
<div class="${properties.kcLabelWrapperClass!}">
<label for="groups" class="${properties.kcLabelClass!}">Team</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<select class="${properties.kcInputClass!}" id="groups" name="groups" value="${(register.formData['groups']!'')}">
<option value="group1">Group 1</option>
<option value="group2">Group 2</option>
<option value="group3">Group 3</option>
</select>
</div>
</div>
I was successfully able to add the group as a user attribute, and then thought I could execute a script after that uses the rest API to then assign the group, but I haven't had much luck with that either. I would like to stay away from assigning everyone to a default "view only" group because some groups don't need to be able to view all the apps that we will use.
If anyone has any ideas or could help point me in the right direction, please let me know. I have limited knowledge HTML & Javascript but know my way around Python.
The context
I am trying to create a link list portlet on a page in my Liferay 6.2 instance. To achieve this, I have put a new Dynamic Data List Display portlet on the page and made a Data Definition that contains a Link to Page (it used to be called Link to Layout before 6.2) field. I am trying to build a custom Display Template using Liferay's guide to display an HTML unordered list with the links, but I cannot find any information regarding how to handle Link to Page field properly.
The question
How can I create a Freemarker template that displays the Link to Page field so that the href attribute contains the smart url of the page and the link text is the localized name of the page?
The Display Template editor adds the following code to the Freemarker script when you click your field:
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">
Link to Page
</a>
This is a good hint to start displaying the links, just add the small details:
<#-- The record service to retrieve the list of records in this Dynamic Data List -->
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
<#-- The layout service that helps determine the name of the page -->
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutService")>
<#-- Get the records in the Dynamic Data List -->
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>
<ul>
<#if records?has_content>
<#list records as cur_record>
<li>
<#-- Use the snippet provided by the editor -->
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">
<#-- Get the name of the page with layoutService.getLayoutName() using a temporary JSON object -->
<#assign jsonObj = jsonFactoryUtil.createJSONObject(cur_record.getFieldValue("Link_to_Page1632"))>
${layoutService.getLayoutName(jsonObj.getLong("groupId"), jsonObj.getBoolean("privateLayout"), jsonObj.getLong("layoutId"), localeUtil.toLanguageId(locale))}
</a>
</li>
</#list>
</#if>
</ul>
I was wondering, which is the best way to add additional values to an url created by a form with a GET method... the url looks something like
http://testing.com/results?search_query=landscape&search_filter[]=mountain
I'll have on the results page additional filters and paging system, and I was wondering which is the best way of adding the values of those once chosen/selected to the url? So if clicked on next button it will add a &page=X to the url or/and a &sort_by=top_rate
You can use checkboxes:
<input type="checkbox" name="search_filter[]" value="mountain" />
<input type="checkbox" name="search_filter[]" value="landscape" />
or multiselect:
<select multiple="multiple" name="search_filter[]">
<option value="landscape">Landscape</option>
<option value="mountain">Mountain</option>
</select>
I'm not entirely sure I get the question, but I think the location object may be of help.
Try location.href and then changing it. The browser will change to that new url. So you could get the current, then add your stuff, setting that appended version back into location.href. I think this is what you want, as long as you want the user's browser to navigate to that page.
There is a modern method that allows you to just modify the address bar and title without refreshing/navigating away, using window.history.
http://www.w3.org/TR/html5-author/history.html#history-0
Specifically you might be interested in window.history.pushState. This will let their back buttons work too. :)
Hope this was more along the lines you were looking for!
You need to read your URL in the action script.
Check if the URL has any parameter.
If the URL has some parameters, then append at the end: &newPARAM=newVALUE (you can add as many as you wish).
If the URL has no parameters, then append to the end: ?newPARAM=newValue
Currently working with Zend Sub form in Zend framework to achieve Multi page form.
This is the example i'm using at the moment
http://framework.zend.com/manual/en/zend.form.advanced.html
Managed to get everything working nicely but I wanted to have a 'Back' button on the forms so when the users press on the “back” button the previous form will re display with entered data.
I'm wondering is there any tutorial on the net teaches this or is it easy to code this functionality?
Thank you so much. PS I Love stackoverflow community :)!
Its a structuring and naming thing.
I'm going to psuedo-code and talk you through this, let me know if you need me to type out a full example
Assumption:
MultiPageForm has many SubForms that represent pages.
when you add these subforms to the parent form you name them something intelligent.
so for example, if your form was at /register, use an optional url paramater */register/page/{that_intelligent_subform_name_from_before}* to build out a navigation
<ul>
<li>Step 1</li>
<li>Step 2</li>
<li>Step 3</li>
</ul>
then in your controller:
1. pull out the page param
2. fetch the subform with that name from the multipage form
3. prepopulate the subform
4. send the subform to the view
I'm creating a UX experience that will allow the user to add items to a collection by using a jQuery button, and some AJAX.
My problem is, when the user finishes adding items and filling out the rest of the form, they complete the form, which I want to carry up to the server in the form of a strongly typed class.
My question is, what is the best approach for adding a new item to a Model's collection using jQuery and Ajax? or is this at all possible?
Example:
<li>
<div id="shipment">
<%: Html.EditorFor(x => x.Shipment) %>
</div>
</li>
x.Shipment is actually a collection inside my Model.
I have buttons in the EditorFor that let the user add items to the shipment.
Then, when the user posts the form, I have the controller set up like so:
[HttpPost]
public ActionResult CompleteReceipt(Receipt receipt)
{
Context.Update(receipt);
return RedirectToAction("Index", "Home");
}
What is the best practice or way for using jQuery to add items to my Receipt Model's Shipment collection?
Checkout this excellent blog post from Steve Sanderson. It provides a nice overview of how to achieve what you are looking for and could be considered as best practice. Don't forget to read the follow-up which is about validation if you are interested in this aspect as it could be a bit challenging with dynamic forms.