You need to sign in to do that
Don't have an account?
引数を渡してメソッドを実行する方法について
お世話になります。
メソッドを実行するときに、引数を渡すにはどのようにすればよいのでしようか。
<apex:commandLink>と<apex:param>を組み合わせる方法ではうまくいかないでしょうか。
検索結果の画面から詳細画面へ切り替えるメソッドを実行する時に、IDを渡す仕組みとして
使おうとしています。
======================================
<apex:page controller="SampleMeisai" action="{!selectAllMeisai}">
<apex:form >
<apex:pageBlockSection>
<apex:outputLabel value="{!meisaiId}"/>
<apex:pageBlockTable value="{!meisai}" var="item" rowClasses="odd,even">
<apex:column headerValue="String1">
<apex:commandLink action="{!selectMeisai}" value="{!item.String1}">
<apex:param value="{!item.String1}" id="String1" />
</apex:commandLink>
</apex:column>
<apex:column headerValue="String2">
<apex:outputText value="{!item.String2"></apex:outputText>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:form>
</apex:page>
======================================
public class SampleMeisai{
public List<SampleMeisai__c> meisai { get; set; }
public String meisaiId { get; set; }
public PageReference selectAllMeisai() {
meisai = [SELECT String1__c, String2__c FROM SampleMeisai__c];
return null;
}
public PageReference selectMeisai() {
meisaiId = ApexPages.currentPage().getParameters().get('String1');
return null;
}
}
よろしくお願い致します。
apex:param でパラメータ名を指定する先は、id属性ではなくname属性です。以下のコードで試してみてください。
補足ですが、commandLinkとparamを組み合わせるのであれば、
ApexPages.currentPage().getParameters().get('String1');
のようにしなくとも、
のようにassignTo属性で、代入先の変数を明示的に指定することもできます。