简体   繁体   中英

Trying to create a lookup input that sends the value back to the controller when the submit button is pressed in different form

I would like the selected prog.Name value to be passed back to the controller and available in the fetchScheduleList function. Currently prog always comes back as null.

VF Page

<div class = "wrapper">
        <div class = "programDropdown">
    <apex:form >
    <apex:pageBlock title="Program">
<apex:pageBlockSection columns="1">
    <apex:inputField value="{!prog.Name}" label="Search Programs"/>

     </apex:pageBlockSection>
</apex:pageBlock>
    </apex:form>
    
    </div>
        <div class = "leftForm">
            <apex:form >
            <apex:panelGrid columns="5" id="dates1">
                <b>Start Date: </b><apex:inputfield value="{!startWeek.Week__c}"/>
                <b>End Date: </b><apex:inputfield value="{!endWeek.Week__c}"/>
                <apex:commandButton value="Submit" rerender="test" action="{!fetchScheduleList}"/>
            
            </apex:panelGrid>
            <apex:outputPanel id="test">  
                <apex:repeat value="{!sched}" var="s" id="scheds">
                    <apex:pageBlock title="{!s.Name} {!s.Week__c} ({!s.ID})">
                        {!s.Name}: {!s.Week__c}
                    </apex:pageBlock>
                </apex:repeat>
            </apex:outputPanel>
            </apex:form>
        </div>
 

Apex Controller

public class WeeklyComparisonController {    
public Schedules__c startWeek {get;set;}    
public Schedules__c endWeek {get;set;}    
public List<Schedules__c> sched {get;set;}    
public Programs__c prog {get;set;}    
public WeeklyComparisonController(ApexPages.StandardController sc){        
sched = new List<Schedules__c>();        
startWeek = new Schedules__c(Week__c = date.today().toStartofWeek().AddDays(-6));    }    
public void fetchScheduleList() {        
System.debug('prog ' + prog);   
sched = [SELECT Id, Name, Week__c FROM Schedules__c                 
WHERE DealProgram__c = :prog.name                 
AND Week__c >= :date.valueOf(startWeek.Week__c)              
];    
}
} 

在 apex 中获取一个 String 变量,为其提供 getter 和 setter,并使用它来存储程序名称。

public String progName {get;set;} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM