我正在通过我的Visualforce页面以下代码,让用户选择就业网站发布职位:
<apex:page standardController="Position__c" extensions="PositionExtension">
<apex:form >
<apex:pageBlock title="Create New Position">
<apex:pageBlockButtons >
<apex:commandButton title="Save" value="Save" action="{!save}"/>
<apex:commandButton title="Edit" value="Edit" action="{!edit}"/>
<apex:commandButton title="Cancel" value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="3" title="Basic Information">
<apex:pageBlockSectionItem >
Position Title
<apex:inputField value="{!Position__c.name}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Record Type
<apex:inputField value="{!Position__c.recordtypeId}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Open Date
<apex:inputField value="{!Position__c.Open_Date__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Close Date
<apex:inputField value="{!Position__c.Close_Date__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Hire By
<apex:inputField value="{!Position__c.Hire_By__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Job Type
<apex:inputField value="{!Position__c.Type__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Location
<apex:inputField value="{!Position__c.Location__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Travel Required?
<apex:inputField value="{!Position__c.Travel_Required__c}" required="false"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Status
<apex:inputField value="{!Position__c.Status__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Functional Area
<apex:inputField value="{!Position__c.Functional_Area__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Job Level
<apex:inputField value="{!Position__c.Job_Level__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Job Description
<apex:inputField value="{!Position__c.Job_Description__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Responsibilities
<apex:inputField value="{!Position__c.Responsibilities__c}"
required="true"/>
</apex:pageBlockSectionItem>
<br></br>
<apex:pageBlockSectionItem >
Min Pay
<apex:inputField value="{!Position__c.Min_Pay__c}"
required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Max Pay
<apex:inputField value="{!Position__c.Max_Pay__c}"
required="true"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Education and Skills" columns="3">
<apex:pageBlockSectionItem >
Educational Requirements
<apex:inputField value="{!Position__c.Educational_Requirements__c}"
required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Skills Required
<apex:inputField value="{!Position__c.Skills_Required__c}" required="false"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Apex
<apex:inputField value="{!Position__c.Apex__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
C#
<apex:inputField value="{!Position__c.C_sharp__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Java
<apex:inputField value="{!Position__c.Java__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
JavaScript
<apex:inputField value="{!Position__c.JavaScript__c}"/>
</apex:pageBlockSectionItem>
<apex:selectList value="{!selected}" multiselect="true">
<apex:selectOptions value="{!websites}"/>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:Form>
</apex:page>
这是来自控制器的代码,我试图检索所选值并进行排序以确定网站是否被选中:
public class PositionExtension {
public Position__c pos{get; set;}
public List<Employment_Website__c> employ{get;set;}
Public List<Job_Posting__c> joblist = new List<Job_Posting__c>();
Public Set<String> selected{get;set;}
public PositionExtension (ApexPages.StandardController controller){
pos = (Position__c)Controller.getRecord();
}
//List<Job_Posting__c> postings = [SELECT Id, Employment_Website__c FROM Job_Posting__c WHERE Position__c = :pos.Id];
public List<Employment_Website__c> website{
get{return [SELECT Id, Name, web_address__c FROM Employment_Website__c];}
set{website = value;}
}
public List<SelectOption> getWebsites(){
List<SelectOption> options = new List<SelectOption>();
for (Employment_Website__c web : website){
options.add(new SelectOption(web.Id, web.name));
}
return options;
}
public Set<String> updateSelected(){
return selected;
}
public PageReference save(){
//List<Job_Posting__c> postings = [SELECT Id, Employment_Website__c FROM Job_Posting__c WHERE Position__c = :pos.Id];
upsert pos;
for(Employment_Website__c web : website){
system.debug(selected);
if(selected.contains(web.Id)){
Job_Posting__c posting = new Job_Posting__c();
posting.Employment_Website__c = web.Id;
posting.Position__c = pos.Id;
joblist.add(posting);
}
}
upsert joblist;
PageReference acctPage = new ApexPages.StandardController(pos).view();
acctPage.setRedirect(true);
return acctPage;
}
}
有关如何将所选值重新输入控制器以创建职位发布的任何建议?如果我应该发布更多我的Visualforce代码,请告诉我。谢谢!
答案 0 :(得分:0)
您需要转换所选的数据类型。
目前: 公共集选择{get; set;}
更新 公开列表已选择{get; set;}