I am trying to add a search box to a Visual force page that renders a table. The page worked fine before adding the search. And now it works fine so long as I don't enter a search term.
When I leave the search box blank and press the "Search" button I get:
Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList
If I enter a term and press "search" I get:
System.QueryException: Didn't understand relationship 'res' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Error is in expression '{!getReservations}' in component in page reservation_list: Class.ReservationListController.getReservations: line 20, column 1 Class.ReservationListController.getReservations: line 20, column 1
The problem seems to be that I don't know how to tell the page to expect a list to be returned. I can't seem to declare the variables or return types properly?
I'm ignorant enough that I don't know what I am missing. The line number it refers to is the line in the controller that populates the list: res = database.query(queryString);
When I check the debug statements the list is populated correctly and like I said the list displays fine on initial page load, just not from the search button.
I don't know if it is the length or what, but no matter what I do I can't seem to paste the entire VF page into the editor and get it to show up. The two excerpts contain the problematic areas though.
My VF Page Excerpt:
<apex:pageBlock title="Search" >
<apex:inputText value="{!searchString}" id="theSearchString" maxlength="100" size="110" />
<apex:CommandButton Id="btnSearch" action="{!getReservations}" rerender="ReservationsBlock" value="Search" /></apex:pageBlock>
<apex:pageBlock id="ReservationsBlock" title="Current Reservations">
<apex:pageBlockTable value="{! reservations }" var="res">
<apex:column headerValue="Reservation Name" value="{! res.Name }" />
My Controller:
public class ReservationListController {
private String profileId;
private String queryString;
private String userId;
public String searchString {get; set; }
public List<Reservation__c> getReservations() {
profileId = userinfo.getProfileId();
userId = userinfo.getUserId();
if(searchString == null) {searchString = '';}
if(searchString.length() == 0){
queryString = 'SELECT id, Name, copy_del1__c, UserIdCreatedBy__c, Copy_del1__r.Book__r.Author_Name__c, Copy_del1__r.Book__r.Name, Copy_del1__r.Book__r.Id '+'FROM Reservation__c ';
}
else{
queryString = 'SELECT id, Name, copy_del1__c, UserIdCreatedBy__c, Copy_del1__r.Book__r.Author_Name__c, Copy_del1__r.Book__r.Name, Copy_del1__r.Book__r.Id '+'FROM Reservation__c Where res.Copy_del1__r.Book__r.Name Like :' + searchString;
}
List<Reservation__c> res = new List<Reservation__c>();
System.debug(queryString);
res = database.query(queryString);
System.debug(res);
//searchString = '';
return(res);
}
}