+ Start a Discussion
Swamy PSwamy P 

PageblockTable values by dynamic soql query..

Hi,

    I have one text box and one button,by giving name and click on button then automatically thus name related records are into  PageBlockTable.Iam retrieving records by Dynamic soql i.e,Database.query('select id,name from '+sobj+'where name like: ' +name); but i want to display these name based records  in pageblocktable.It's for different objects,once check it.

if i give <apex:column value="{!a.name}">,it also shows an error ..so any one helpme out...

HafaelDiasHafaelDias

Hi,

 


Could you please show your code or the error message? It would help!!

 

Btw, First, check if you are using this structure:

 

Visualforce page: 

 

<apex:pageBlock>

<apex:pageBlockTable value="{! Your list here }" var="a">

<apex:column value="{!a.Object field}"/>

 

And do forget about the Get method.

 

Adam HowarthAdam Howarth

Hey,

 

You can use dynamic components. So creating the controls in the controller and applying the fields to the controls you need.

 

A basic example is below:

 

=====================
Visualforce page
============================

<apex:page standardcontroller="YourController" extensions="DynamicComponentExample">
    <apex:form >
           <apex:dynamicComponent componentValue="{!pageBlock}"/>
    </apex:form>
</apex:page>


Controller:
=============

public Component.Apex.PageBlock getpageBlock(){

List<sObject> mainList = Database.Query('select id,name from '+sobj+'where name like: ' +name);
Component.Apex.PageBlock pb=new Component.Apex.PageBlock(); Component.Apex.PageBlockTable ptable=new Component.Apex.PageBlockTable(); ptable.value= mainList;
ptable.var = 'item'

Component.Apex.Column nameCol = new Component.Apex.Column();
nameCol.value= '{!item.name}';
ptable.childComponents.add(nameCol);


return pb;
}

 

 

Something along these lines should work. Its hard to give a complete answer without more code.

 

Cheers