function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jnakamurajnakamura 

POSTによる画面間の値の受け渡しについて

お世話になります。

 

複数画面間で、POSTで値の受け渡しを行うにはどのように実装すればいいのでしょうか?

 

複数画面で値を受け渡す場合は、1つのコントローラを共有するだけで出来ると思ったのですが、

それだけだと何か足りないのでしょうか?

 

-------------------------------------------------------------
※遷移元
<apex:page id="sample" controller="Sample">
    <apex:form >
        <apex:inputtext value="{!string1}"/>
        <apex:inputtext value="{!string2}"/>
        <apex:commandButton value="次画面へ" action="{!goNext}" />
    </apex:form>
</apex:page>

-------------------------------------------------------------
※クラス
public class Sample {

    public String string1 { get; set; }
    public String string2 { get; set; }

    public PageReference goNext() {
        PageReference page = new PageReference('画面遷移先URL');
        return page;
    }
}

-------------------------------------------------------------
※遷移先
<apex:page id="sample2" controller="Sample">
    <apex:form >
        <apex:outputtext value="{!string1}"/>
        <apex:outputtext value="{!string2}"/>
    </apex:form>
</apex:page>

 

よろしくお願いいたします。

Best Answer chosen by Admin (Salesforce Developers) 
snoninsnonin

'画面遷移先URL'として、サーバー名まで含んだ絶対URLを指定されていないでしょうか。

 

return new PageReference('/apex/sample2');

のように相対URLで指定する、もしくは

return Page.sample2;

のようにPage.<visualforceページ名>で指定してみてください。

 

(補足) ご提示されたサンプルでは、pageを変数名として利用されていますので、そのままではPage.<visualforceページ名>との指定がうまく動かないと思います。VFページでは、pageを変数名としてご利用されない方が無難かと思います。

 

All Answers

snoninsnonin

'画面遷移先URL'として、サーバー名まで含んだ絶対URLを指定されていないでしょうか。

 

return new PageReference('/apex/sample2');

のように相対URLで指定する、もしくは

return Page.sample2;

のようにPage.<visualforceページ名>で指定してみてください。

 

(補足) ご提示されたサンプルでは、pageを変数名として利用されていますので、そのままではPage.<visualforceページ名>との指定がうまく動かないと思います。VFページでは、pageを変数名としてご利用されない方が無難かと思います。

 

This was selected as the best answer
jnakamurajnakamura

回答ありがとうございます。

教えていただいた方法でできました!

 

 Page.<visualforceページ名>と指定するだけでできるようになりました。

 

ありがとうございます。