p:dataList problem

UI Components for JSF
Post Reply
seas0ns
Posts: 6
Joined: 24 Jan 2011, 20:17

24 Jan 2011, 20:31

The command link won't execute the action
It works perfectly outside the dataList

Code: Select all

<div id="searchBar"><h:inputText
			value="#{searchBean.searchText}" style="width:220px"></h:inputText><p:commandButton
			id="searchBtn" value="Search" update="panel,display"
			actionListener="#{searchBean.searchFriends}"></p:commandButton></div>
		<div id="keywords"><h:outputText value="#{searchBean.keywords}"></h:outputText></div>
		<div class="datalist-noborder"><p:panel id="display">
			<div id="keywords"><h:outputText value="#{searchBean.keywords}"></h:outputText></div>
			<p:dataList value="#{searchBean.searchResult}" var="searchResult"
				itemType="none">
				<table style="margin-top: 30px">
					<tbody>
						<tr>
							<td><p:column>
								<p:commandLink action="#{searchBean.getFriend}">
									<h:graphicImage value="#{searchResult.resultPhotoPath}"
										style="width: 100px;"></h:graphicImage>
									<f:setPropertyActionListener value="#{searchResult}"
										target="#{searchBean.selectedUser}" />
								</p:commandLink>
							</p:column></td>
							<td style="width: 400px; text-align: left;"><h:outputText
								value="#{searchResult.resultFullName}" style="font-weight: bold" /></td>
						</tr>
					</tbody>
				</table>
			</p:dataList>
		</p:panel></div>

Code: Select all

package com.tomo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class SearchBean {
	public String keywords;
	public String searchText;
	public String searchSql;
	public String fullName;
	public SearchResult selectedUser;
	public List<SearchResult> searchResult;
	public int rows;
	
	public String getFriend() {
	return "Stranger";
	}
	
	public void NumberOfRows() throws Exception {
		PreparedStatement getRows = null;
		searchSql = "%" + searchText + "%";
		Class.forName("oracle.jdbc.driver.OracleDriver");
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
				.getExternalContext().getSession(true);
		Connection conn = DriverManager.getConnection(
				"jdbc:oracle:thin:@localhost:1521:xe", "tomo", "tomo123");
		// @machineName:port:SID, userid, password
		String sql = "Select Count(USERID) AS" + "ROWS"
				+ " FROM USERINFO Where FIRSTNAME LIKE ? AND USERID <> ?";
		getRows = conn.prepareStatement(sql);
		getRows.setString(1, searchSql.toLowerCase());
		getRows.setString(2, (String) session.getAttribute("userId"));

		try {
			ResultSet rs = getRows.executeQuery();
			if (rs.next()) {
				this.rows = rs.getInt(1);
			}

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	public void searchFriends() throws Exception {
		PreparedStatement getFriends = null;
		searchResult = new ArrayList<SearchResult>();
		this.NumberOfRows();
		this.keywords = "Results for keywords: " + searchText;
		searchSql = "%" + searchText + "%";
		Class.forName("oracle.jdbc.driver.OracleDriver");
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
				.getExternalContext().getSession(true);
		Connection conn = DriverManager.getConnection(
				"jdbc:oracle:thin:@localhost:1521:xe", "tomo", "tomo123");
		// @machineName:port:SID, userid, password
		String sql = "SELECT USERINFO.USERID, USERINFO.FIRSTNAME, USERINFO.LASTNAME, USERINFO.GENDER, PHOTO.PHOTOPATH FROM USERINFO INNER JOIN PHOTO ON USERINFO.PHOTOID = PHOTO.PHOTOID WHERE USERINFO.FIRSTNAME LIKE ? AND USERINFO.USERID <> ? ORDER BY USERINFO.FIRSTNAME";
		getFriends = conn.prepareStatement(sql);
		getFriends.setString(1, searchSql.toLowerCase());
		getFriends.setString(2, (String) session.getAttribute("userId"));
		try {
			ResultSet rs = getFriends.executeQuery();
			for (int i = 0; i < rows; i++)
				while (rs.next()) {
					fullName = rs.getString("firstName") + " "
							+ rs.getString("lastname");
					this.searchResult.add(new SearchResult(fullName, rs
							.getString("photoPath")));
				}

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	public SearchResult getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(SearchResult selectedUser) {
		this.selectedUser = selectedUser;
	}

	public String getSearchText() {
		return searchText;
	}

	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}

	public List<SearchResult> getSearchResult() {
		return searchResult;
	}

	public void setSearchResult(List<SearchResult> searchResult) {
		this.searchResult = searchResult;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
}
I am using:
Primefaces 2.2 RC1

seas0ns
Posts: 6
Joined: 24 Jan 2011, 20:17

25 Jan 2011, 11:08

Please give me some advice on what i can do!

moonblade.wolf
Posts: 48
Joined: 07 Dec 2010, 02:46

20 Jul 2011, 19:01

Got the exact same thing, and it's solved now.

bitec
Posts: 44
Joined: 20 Jan 2011, 21:34
Location: Russia

03 Oct 2011, 17:10

Very unclear bug, spent more than a couple of hours, struggling with it... Though have almost one year of experience with PF and now remember, I already faced this problem once :). I think it will be great, if Cagatay and team would find time for fixing this. For now I created the jira for this: http://code.google.com/p/primefaces/iss ... 1317654553 feel free to vote for it :)
JSF: Mojarra 2.1 | PrimeFaces 2.2.1 | Glassfish 3.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests