【问题标题】:View operation in salesforce using apex and visualforce使用 apex 和 visualforce 在 salesforce 中查看操作
【发布时间】:2018-02-07 20:18:49
【问题描述】:

下面是我的 VF 和控制器类的代码 保存和取消方法工作正常,但我的搜索方法工作不正常。当我单击查看按钮保存对象后,它说输入字段名称而不是显示对象列表。 VF 代码

<apex:page controller="c5">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!a.Name}"/>
            <apex:inputField value="{!a.First_Name__c}"/>
            <apex:inputField value="{!a.Last_Name__c}"/>
            <apex:inputField value="{!a.Email__c}"/>
            <apex:inputField value="{!a.Contact_Number__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
        <apex:commandButton value="save" action="{!save}"/>
        <apex:commandButton value="cancel" action="{!cancel}"/>
        <apex:commandButton value="view" action="{!search}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

控制器类

public class c5
{

    public PageReference cancel() 
    {
        PageReference pageRef = new PageReference('/apex/Reg');
        pageRef.setRedirect(true);
        return pageRef;

    }

    List<Register__c> b = new List<Register__c>();
    Register__c a = new Register__c();

    public Register__c geta(){
    return a;
    }

    public PageReference save(){
    insert a;
    return null;
    }

    public List<Register__c> getb(){
    return b;
    }
    public PageReference search(){
    b = (List<Register__c>)[select Name, First_Name__c, Last_Name__c, Email__c, Contact_Number__c  from Register__c];
    return null;
    }

}

【问题讨论】:

    标签: salesforce visualforce apex


    【解决方案1】:

    您将搜索结果分配给属性b,但您没有在 VisualForce 页面中显示/使用此属性。

    试试这样的:

    <apex:page controller="c5">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!a.Name}"/>
                <apex:inputField value="{!a.First_Name__c}"/>
                <apex:inputField value="{!a.Last_Name__c}"/>
                <apex:inputField value="{!a.Email__c}"/>
                <apex:inputField value="{!a.Contact_Number__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="save" action="{!save}"/>
                <apex:commandButton value="cancel" action="{!cancel}"/>
                <apex:commandButton value="view" action="{!search}" rerender="bData"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" id="bData">
                <apex:dataTable value="{!b}" var="theSObject" rendered="{!NOT(ISBLANK(b))}">
                    <apex:column value="{!theSobject.Name}"/>
                </apex:dataTable
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    </apex:page>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多