其他分享
首页 > 其他分享> > Visualforce 表单

Visualforce 表单

作者:互联网

1.示例代码:

<apex:page standardController="Account">
    <h1>Edit Account</h1>
    <apex:form>
        <apex:inputField value="{! Account.Name }"/>
        <apex:commandButton action="{! save }" value="Save" />
    </apex:form>
</apex:page>

代码解析:

预览结果:

2.添加字段标签和平台样式

<apex:page standardController="Account">
    <apex:form>
    <apex:pageBlock title="Edit Account">
        <apex:pageBlockSection>
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{! Account.Name }"/>
                <apex:inputField value="{! Account.Phone }"/>
                <apex:inputField value="{! Account.Industry }"/>
                <apex:inputField value="{! Account.AnnualRevenue }"/>
            </apex:pageBlockSection>
        </apex:pageBlockSection>
        <apex:pageBlockButtons>
            <apex:commandButton action="{! save }" value="Save" />
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

代码解析:

  <apex:inputField> 可用于捕获任何标准或自定义对象字段的用户输入,并尊重字段定义中设置的任意元数据,例如该字段是必需的还是唯一的,或者当前用户是否拥有查看或编辑权限。

预览结果:

3.显示表单错误和消息

<apex:page standardController="Account">
    <apex:form>
    <apex:pageBlock title="Edit Account">
        <apex:pageMessages/>
        <apex:pageBlockSection>
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{! Account.Name }"/>
                <apex:inputField value="{! Account.Phone }"/>
                <apex:inputField value="{! Account.Industry }"/>
                <apex:inputField value="{! Account.AnnualRevenue }"/>
            </apex:pageBlockSection>
        </apex:pageBlockSection>
        <apex:pageBlockButtons>
            <apex:commandButton action="{! save }" value="Save" />
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

4.编辑相关记录

<apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!Account.contacts}" var="contact">
            <apex:column>
                <apex:outputLink
                    value="{! URLFOR($Action.Contact.Edit, contact.Id) }">
                    Edit
                </apex:outputLink>
                 
                <apex:outputLink
                    value="{! URLFOR($Action.Contact.Delete, contact.Id) }">
                    Del
                </apex:outputLink>
            </apex:column>
            <apex:column value="{!contact.Name}"/>
            <apex:column value="{!contact.Title}"/>
            <apex:column value="{!contact.Phone}"/>
        </apex:pageBlockTable>
</apex:pageBlock>

预览结果:

Resources

标签:控制器,预览,表单,标准,字段,Visualforce,页面
来源: https://www.cnblogs.com/kousaimiao/p/16243775.html