0

我想添加在 vf 页面文本框中给出的两个数字。我想通过单击第一页中的按钮(添加按钮)在另一个 vf 页面中打印结果。

请帮我这样做....

谢谢,

4

2 回答 2

0

我认为您可能想尝试在两个页面上使用相同的控制器。这样,您不必传递所有数据,假设您需要维护的不仅仅是几个字段,作为 url 参数,或者如果您不需要,则必须将数据存储在某个地方。

如果两个页面都使用同一个控制器,并且当您使用 PageReference 重定向用户时,请确保将重定向值设置为false,否则 Salesforce 会将其视为新请求并使用控制器的新实例启动页面。

下面的示例代码允许用户在字段中键入一些文本,然后当单击打印视图时,它会使用相同的信息呈现 PDF。没有数据保存到数据库。

控制器

public with sharing class MyController {

public string MyData {get;set;}

public MyController() {
    MyData = '';    
}

public PageReference printView() {
    PageReference oPageRef = Page.MyPage2;
    oPageRef.setRedirect(false);

    return oPageRef;
}
}

第 1 页:

<apex:page controller="MyController">
<apex:sectionheader title="Test" subtitle="My Page"/>

<apex:form id="formData">
    <apex:pageBlock title="My Data">
        <apex:pageBlockButtons >
            <apex:commandButton value="Printable View" action="{!printView}" />
        </apex:pageBlockButtons>

        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="My Data"/>
                <apex:inputTextArea value="{!MyData}" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

第2页:

<apex:page controller="MyController"
renderAs="pdf">

{!MyData}
</apex:page>
于 2012-07-11T23:07:59.923 回答
0

您可以通过路由到 Visualforce 中的下一页并传递要显示为参数的值来执行此操作。Apex中这样的东西应该可以工作:

PageReference gotoPage()
{
   PageReference pr = Page.YourSecondVFPage;
   pr.getParameters().put('secondnumber', '' + this.secondNumber);
   pr.setRedirect(true);
   return pr;
}

然后在 Visualforce 中:

<apex:commandButton value="Go!" action="{!gotoPage}"/>
于 2012-07-11T16:23:50.583 回答