1

I have a very simple search page that I want to display the data in the two column but I'm unable to do unless if I have apex:pageblockTable is that possible to do without pageblocktable?

Visualforce page:

<apex:page controller="RetUrlSearchController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection title="Criteria">
      <apex:outputLabel value="Enter Name Snippet"/>
      <apex:inputText value="{!nameQuery}"/>
      <apex:commandButton action="{!executeSearch}" value="Search"/>
   </apex:pageBlockSection>

   <apex:pageBlockTable value="{!accounts}" var="acc">
      <apex:column headerValue="Name">
         <apex:outputLink value="/{!acc.id}/e?retURL={!URLENCODE('/apex/RetUrlSearchPage?query='+nameQuery)}">{!acc.Name}</apex:outputLink>
      </apex:column>
      <apex:column value="{!acc.BillingStreet}"/>
   </apex:pageBlockTable>
 </apex:pageBlock>
  </apex:form>
</apex:page>

Controller:

public class RetUrlSearchController 
{
 public String nameQuery {get; set;}
 public List<Account> accounts {get; set;}

 public PageReference executeSearch()
 {
  String queryStr='%' + nameQuery + '%';
  accounts=[select id, Name, BillingStreet 
            from Account 
            where name like :queryStr];

  return null;
 }

 public RetUrlSearchController()
 {
  // if query appears in URL, execute it
  String urlQuery=ApexPages.currentPage().getParameters().get('query');

  if ( (null!=urlQuery) && (0!=urlQuery.length()) )
  {
   nameQuery=urlQuery;
   executeSearch();
  }
 }
}

Here is what I want the format to be:

<apex:pageBlockSection title="General Information" columns="2">
        <apex:outputField value="{!accounts.Id}"/>
        <apex:outputField value="{!accounts.Name}"/>
        <apex:outputField value="{!accounts.BillingStreet}"/>

        .......... 
</apex:pageBlockSection> 

the error i'm getting if i use that in above format:

Error: Could not resolve the entity from value binding '{!accounts.id}'.

3
  • So what's wrong with using columns="2"?
    – Adrian Larson
    Jul 16, 2016 at 0:24
  • its not rendering, if i use the <apex:pageBlockSection title="General Information" columns="2"> let me update my question with the error message i'm getting
    – Nick
    Jul 16, 2016 at 0:33
  • all what i have seen the sample code is used apex:pageBlockTable but in my case i do not want to use apex:pageBlockTable
    – Nick
    Jul 16, 2016 at 0:42

1 Answer 1

5

Just like with pageBlockTable, you need to iterate over the collection. When you do:

<apex:pageBlockTable value="{!accounts}" var="acc">
    ...
</apex:pageBlockTable>

You create a local variable inside of that tag named acc. The accounts property is just a list and doesn't have any properties like id. The acc records have those properties, so to create that reference you can instead do an apex:repeat.

<apex:pageBlockSection>
    <apex:repeat value="{!accounts}" var="acc">
        <apex:pageBlockSection>
            <apex:outputLink value="{!URLFOR($Action.Account.Edit, acc.id, [retURL=URLENCODE('/apex/RetUrlSearchPage?query='+nameQuery)}">
                {!acc.Name}
            </apex:outputLink>
        </apex:pageBlockSection>
        <apex:pageBlockSection>
            <apex:outputField value="{!acc.BillingStreet}" />
        </apex:pageBlockSection>
    </apex:repeat>
</apex:pageBlockSection>
1
  • awesome as always :) 1+
    – Nick
    Jul 16, 2016 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .