Listing and Displaying of Users and Organization in Liferay 7 - liferay

I am trying to List all the users and organizations present in the db in liferay(7.1.2 ga3) on a JSP page.
I know i have to use UserLocalServiceUtil.getUsers() and OrganizationLocalServiceUtil.getOrganizations() inside render method to get the list of users and organizations.
then i have to use renderUrl(which i don't know how to use) in jsp to display the lists.
I can retrieve the list of organizations and print them in console but for users nothing is getting printed in console.
Can some one please tell how to retrieve the list of users, and then what to write in jsp file to display them(users and organizations).
Not asking for code just a small example or steps or some document for this process.
I'll add my code below to show how i am trying.
#Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException
{
// for users (not getting printed in console)
List<User> getUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
renderRequest.setAttribute("users", getUsers);
_log.info("Users:" + getUsers);
// for organizations
List<Organization> getOrganizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
renderRequest.setAttribute("organizations", getOrganizations);
_log.info("Organizations:" + getOrganizations);
super.render(renderRequest, renderResponse);
}

i'll add how i tried and it's working as expected.
In my render method:
// for retrieving users from "user_" table in db
List<User> getUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
renderRequest.setAttribute("users", getUsers);
// for retrieving organizations from "organization_" table in db
List<Organization> getOrganizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
renderRequest.setAttribute("organizations", getOrganizations);
my listUser.jsp
<tbody>
<c:forEach var = "listUsers" items = "${users}">
<tr>
<td> <c:out value = "${listUsers.firstName}"/> </td>
<td> <c:out value = "${listUsers.middleName}"/> </td>
<td> <c:out value = "${listUsers.lastName}"/> </td>
<td> <c:out value = "${listUsers.emailAddress}"/> </td>
<td> <c:out value = "${listUsers.screenName}"/> </td>
<td>
<c:forEach var = "listContacts" items = "${contacts}">
<c:out value = "${listContacts.birthday}"/>
</c:forEach>
</td>
</tr>
</c:forEach>
</tbody>
my listOrganization.jsp
<tbody>
<c:forEach var = "listOrganizations" items = "${organizations}">
<tr>
<td> <c:out value = "${listOrganizations.name}"/> </td>
<!-- For Comparing countryid in organization_ table and countryid in country table in db to display country name present in country table-->
<td>
<c:forEach var = "compareCountries" items = "${countries}" >
<c:if test = "${listOrganizations.countryId eq compareCountries.countryId}">
<c:out value = "${compareCountries.name}"/>
</c:if>
</c:forEach>
</td>
</tr>
</c:forEach>
</tbody>

Related

JSF selectBooleanCheckbox always checked

Good afternoon in my timezone.
<ui:repeat id="situacoes-edit-list" var="situacao" varStatus="loop" value="#{cc.attrs.managedBean.situacoesEditDTO}">
<tr id="sitEdit#{situacao.situacaoId}" class="situations">
<td colspan = "2">#{situacao.situacaoNome}</td>
</tr>
<ui:repeat id="justificacoes-list" var="justificacao" varStatus="innerLoop" value="#{situacao.justificacoes}">
<tr id="jusEdit#{justificacao.justificacaoId}" class="justifications">
<td>
<h:selectBooleanCheckbox binding="#{chkJust}" id="chk-just-#{chkJust.clientId}" value="#{justificacao.selected}" />
</td>
<td>#{justificacao.selected}</td>
</tr>
</ui:repeat>
</ui:repeat>
In the Bean the the get and set methods are the follow:
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
The resulting HTML
<tr id="jusEdit6" class="justifications">
<td><input id="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:0:chk-just-j_id3" type="checkbox" name="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:0:chk-just-j_id3" checked="checked" />
</td>
<td>false</td>
</tr>
<tr id="jusEdit2" class="justifications">
<td><input id="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:1:chk-just-j_id3" type="checkbox" name="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:1:chk-just-j_id3" checked="checked" />
</td>
<td>true</td>
</tr>
As you see the <td>#{justificacao.selected}</td> returns the correct value but the value="#{justificacao.selected}" does not produce the correct behaviour.
Why is this happening ?
I am using Mojarra 2.0.1
Thanks in advance
Best regards

Pass Id to ActionMethod

I have a Delete button inside my table and I m trying to delete the selected Row.
The problem is that I always get in the post method a null ID
<div>
<table class="table">
<thead>
<tr>
<th>Role Name</th>
<th>Action</th>
</tr>
</thead>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#using (Html.BeginForm("Delete","Role", new { id = item.Id },FormMethod.Post))
{
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
</div>
}
</td>
</tr>
}
</table>
In My Controller
// POST: Jobs/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult Delete(int id)
{
IdentityRole role = _context.Roles.Find(id);
_context.Roles.Remove(role);
_context.SaveChanges();
return RedirectToAction("Index");
}
Any time I click on the button the id is null
From your comments, the html generated in <form> tags is
action="/Role/Delete/b1bc13ca-a855-48b0-90e2-9e5fc081ac86"
meaning that the Id property of your model is typeof Guid. Change the POST method signature to
public ActionResult Delete(Guid id)

JSF UIData doesn't render a UIColumn children

I try understand how JSF UIData () works programaticaly in JSF. I have following code:
UIInput input = new UIInput();
UIInput input2 = new UIInput();
UIOutput header = new UIOutput();
header.setValue("Header");
UIColumn column = new UIColumn();
column.setHeader(header);
column.getChildren().add(input);
column.getChildren().add(input2);
UIData table = new UIData();
table.getChildren().add(column);
this code render html like:
<table>
<thead>
<tr>
<th scope="col">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
where is my two inputs?? i expect something like:
.....
<tbody>
<tr>
<td>
<input type="text" />
</td>
</tr>
<tr>
<td>
<input type="text" />
</td>
</tr>
</tbody>
......
i know what i do wrong. I have to set a collection of UIData for rows of table. When i set
UIData table = new UIData();
ArrayList list = new ArrayList();
list.add("A");
list.add("B");
table.setValue(list);
than i get two rows with my inputs

JSF SelectOneMenu selected item

I can't get the selected item from a SelectOneMenu. I supply an ArrayList to the menu and want the user to select one of it. I put the menu into a form, so I have a commandButton which I intended to use to perform the selection. This implementation gives me this error : Cannot convert user3 of type class java.lang.String to class java.util.ArrayList when I select from the menu "user3", so it actually performs the selection correctly. The error refers to this line
<h:selectOneMenu value="#{user.myUsers}"
Here is the part of my xhtml which generates the selectOneMenu.
<h:panelGrid columns="3">
<h:form>
<h:selectOneMenu value="#{user.myUsers}">
<f:selectItems value="#{user.myUsers }"/>
</h:selectOneMenu>
<h:commandButton value="#{msgs.remove_user}" action="#{user.select }" ></h:commandButton>
</h:form>
<h:outputText value="#{ user.select}"></h:outputText>
</h:panelGrid>
And here is my UserBean:
#ManagedBean(name="user")
#SessionScoped
public class UserBean implements Serializable {
private String selected;
public ArrayList<String> getMyUsers()throws Exception
{
ArrayList<String> ret;
MySQLConnection conn = new MySQLConnection();
try{
ret = conn.getMyUsers(name);
}finally
{
conn.closeConnection();
}
return ret;
}
public String getSelect() throws Exception
{
if (this.selected==null) return this.getMyUsers().get(0);
return this.selected;
}
public void setSelect(String s)
{
this.selected = s;
}
}
Your arraylist is mapped to
<f:selectItems value="#{user.myUsers}"/>,
and after selection you are trying to put the selected value to the same list:
<h:selectOneMenu value="#{user.myUsers}">
You should have some object (or string in your case) in your managed bean linked with your view and fill it by selected item of myUsers. For example:
private String selectedUser; // + appropriate getter and setter
and <h:selectOneMenu> should look like:
<h:selectOneMenu value="#{user.selectedUser}">
selected item sould be stored in selectedUser to the end of jsf lifecycle
<table class="tableClass" id="productDescriptionTable">
<thead>
<tr class="trPDClass">
<th class="thPDClass"></th>
<th class="thPDClass">Feature</th>
<th class="thPDClass">SubFeature</th>
`enter code here`<th class="thPDClass">Type</th>
<th class="thPDClass">Sub-Feature Value</th>
`enter code here`<th class="thPDClass">Is Active</th>
<th class="thPDClass">Deleted</th>
</tr>
</thead>
<tbody>
<tr class="trPDClass">
<td class="tdPDClass" style="width: 30;" ><input type="checkbox" /></td>
<td class="tdPDClass"><input type="text" id="0PDfeature" name="PDfeature" /></td>
<td class="tdPDClass"><input type="text" id="0PDsubFeature" name="PDsubFeature" /></td>
<td class="tdPDClass"><input type="text" id="0PDtype" name="PDtype" /></td>
<td class="tdPDClass">
<div id="0PDsubFeatureValueDiv" name="PDsubFeatureValueDiv"></div>
</td>
<td class="tdPDClass">
<table class="radioClass">
<tr>
<td width="24%"><input type="radio" name="PDisActive" id="PDisActiveY" value="Y" /></td>
<td width="40%">Yes</td>
<td width="20%"><input type="radio" name="PDisActive" id="PDisActiveN" value="N" /></td>
<td width="16%">No</td>
</tr>
</table>
</td>
<td class="tdPDClass">
<table class="radioClass">
<tr>
<td width="24%"><input type="radio" name="PDdeleted" id="0PDdeletedY" value="Y" /></td>
<td width="40%">Yes</td>
<td width="20%"><input type="radio" name="PDdeleted" id="0PDdeletedN" value="N" /></td>
<td width="16%">No</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>

People search in SharePoint using partial names

My employer is switching their internal portal over to SharePoint. One of the highly used features of the previous portal was a 'people search' that allowed partial names. SharePoint 2007 defaults to keyword searches which only match against the exact word(s) given as search terms. It can do full-text searches but you have to provide the property name, e.g. "FirstName:tom" (without the quotes of course). That works for a programmatic solution but not for end users.
Is there a way in SharePoint 2007 to let users search for people using partial names?
I found this solution that works well enough for us.
Add a ContentEditor web part to the target page and go to the HTML editor button. Add the following HTML code. It creates two input fields (firstname/lastname) and then creates a query with the search terms included as property searches which will invoke the full-text search.
Note: you need to replace the search result page with the appropriate location for your configuration.
<script language="javascript">
//function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
if (e.keyCode == 13 || e.keyCode==10)
{
e.returnValue=false;
DoWildPeopleSearch();
return false;
}
else
return true;
}
//escape apostrophes in search strings
function escapestr(str)
{
return str.replace("'","%22");
}
//search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname = escapestr(document.all["lastname"].value);
var url;
//search on last name
if(firstname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" + lastname;
window.location=url;
return;
}
//search on first name
if(lastname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" + firstname;
window.location=url;
return;
}
//first and last
url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname + "%20FirstName%3A" + firstname;
window.location=url;
return;
}
</script>
<table cellpadding="2" cellspacing="0" border="0" width="100%" ID="Table3">
<tr>
<td width="80" nowrap>
First Name:
</td>
<td width="100%">
<input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Last Name:
</td>
<td>
<input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" onclick="DoWildPeopleSearch()" value="Search">
</td>
</tr>
</table>

Resources