3

I have two search criteria, one is for Account lookup it has to search in custom object based on the lookup selected value and other one is a text box which needs to enter the name. The user needs to search either using lookup value or text box value.I have one issue when i select the value form lookup and click the button it shows the values but the lookup field remains empty.I need to display the value after search in the lookup field.I had already asked this question for another issues.

Public class sample_search
{
public List<sample_unit>Unt_sale{get;set;}
public string partyNo{get;set;}
public Boolean run{get;set;}
public Id AccountId;
public Account cont {get;set;}
public sample_search()
{
Unt_sale=new List<sample_unit>();
run=false;
}
public PageReference runQuery()
{
run=true;
try {
    cont=[select id, Name,ParentId  from Account where id=:cont.ParentId limit 1];   
}
catch(QueryException qe){
   // ApexPages.addMessage(ApexPages.Message(ApexPages.Severity.ERROR, qe.getMessage()));   
}
string queryunit='select id,name,subject__c,detail__c,Account__r.Id  from Units__c where name=:partyNo OR Account__r.ID =:AccountId';
process_unit(Database.query(queryunit));  
}
private void process_unit(List<Units__c> unitsale)
{
Unt_sale.clear();
for(Units__c cu:unitsale)
{
Unt_sale.add(new sample_unit(cu));
}
}
//wrapper class for sample_unit
public with sharing class sample_unit
{
public Units__c unit{get;set;}
public sample_unit(Units__c unt)
{
unit=unt;
}
} 
}

<apex:page controller="sample_search" >
<apex:pageBlock>
<apex:inputField value="{!cont.ParentId}">
 <apex:inputText value="{!partyNo}"  id="accinfo1" />
 <apex:commandButton value="Go" action="{!runQuery}">
 </apex:pageBlock>
 <apex:pageBlock rendered="{!run}">
   <apex:repeat value="{!Unt_sale}" var="us">
   <apex:outputField value="{!us.unit.Name}"/>
   <apex:outputField value="{!us.unit.subject__c}"/>
   <apex:outputField value="{!us.unit.detail__c}"/>
   </apex:repeat>   
 </apex:pageBlock>
</apex:page>
3

I do not see a reRender attribute in your apex:commandButton, which takes an Id as a parameter, and specifies which portion of the page to (aptly) rerender. Your command button also needs to be wrapped in a apex:form tag in order to function.

I would try something like:

<apex:page controller="sample_search" >
    <apex:form>
            <apex:pageBlock>
                <apex:inputField value="{!cont.ParentId}">
                <apex:inputText value="{!partyNo}"  id="accinfo1" />
                <apex:commandButton value="Go" action="{!runQuery}" reRender="reRenderThisPls">
        </apex:pageBlock>
    </apex:form>
        <apex:pageBlock id="reRenderThisPls" rendered="{!run}">
            <apex:repeat value="{!Unt_sale}" var="us">
                <apex:outputField value="{!us.unit.Name}"/>
                <apex:outputField value="{!us.unit.subject__c}"/>
                <apex:outputField value="{!us.unit.detail__c}"/>
            </apex:repeat>   
       </apex:pageBlock>
    </apex:page>
  • thanks for replay but i want once page reference and t get the lookup value then only i will perform the validation part just like that.if(ship_partyNo=='' && AccountId=='' ){ run=false;ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please enter the value Name or PartyNo'));. }.guide me how can i achieve this part. – Udaya Dec 23 '13 at 3:54
  • Hi Udaya, I would do this logic in the controller, and set the run boolean in the runquery method. So instead of setting it true when runquery() is called, check to see if ship_partyNO && accountId are null, and then just call Unt_Sale.adderror("Error Message here"). – Mark Masterson Dec 23 '13 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.