方法中不存在变量

时间:2022-09-25 23:55:34

I am trying to pick up the value of a visual text input and validate if it exists in the database, the problem is that it throws me the following error "Variable does not exist: searchDir"

我试图获取可视文本输入的值并验证它是否存在于数据库中,问题是它抛出以下错误“变量不存在:searchDir”

I leave my code (summarized):

我留下我的代码(摘要):

Controller extension:

public class Direccion {

  public string searchDir{get; set;}
  public ApexPages.StandardController controller {get; set;}

  public Direccion(ApexPages.StandardController controller) {
    this.controller = controller;
  }

  @RemoteAction
  public static void verificarDireccion() {
    Account[] registros = [ SELECT FiscalAddress__c, BillingAddress__c, ShippingAddress__c
                            FROM Account
                            WHERE Account.FiscalAddress__c =: searchDir
                            OR Account.BillingAddress__c =: searchDir
                            OR Account.ShippingAddress__c =: searchDir
                          ];
    if(registros.size() > 0) {

    }else{

    }
  }
}

Visualforce:

<apex:page standardController="Account" extensions="Direccion" id="page">

<apex:inputText id="FiscalAdress" value="{!searchDir}"/>

1 个解决方案

#1


3  

searchDir is an instance variable. It is bound to a specific instance of the class Direccion - here, the controller extension.

searchDir是一个实例变量。它绑定到类Direccion的特定实例 - 这里是控制器扩展。

static methods, such as @RemoteAction JavaScript remoting actions, aren't bound to a specific instance and have no access to the instance variables of the Visualforce page's controller. As such, all state must be passed to the remote action as parameters.

静态方法(如@RemoteAction JavaScript远程处理操作)未绑定到特定实例,并且无法访问Visualforce页面控制器的实例变量。因此,必须将所有状态作为参数传递给远程操作。

You need to modify the signature of your @RemoteAction method to

您需要将@RemoteAction方法的签名修改为

public static void verificarDireccion(String searchDir) {

and alter your Visualforce page's call to the method correspondingly, to pass the current value of this state variable directly to the method.

并相应地更改Visualforce页面对方法的调用,将此状态变量的当前值直接传递给方法。

#1


3  

searchDir is an instance variable. It is bound to a specific instance of the class Direccion - here, the controller extension.

searchDir是一个实例变量。它绑定到类Direccion的特定实例 - 这里是控制器扩展。

static methods, such as @RemoteAction JavaScript remoting actions, aren't bound to a specific instance and have no access to the instance variables of the Visualforce page's controller. As such, all state must be passed to the remote action as parameters.

静态方法(如@RemoteAction JavaScript远程处理操作)未绑定到特定实例,并且无法访问Visualforce页面控制器的实例变量。因此,必须将所有状态作为参数传递给远程操作。

You need to modify the signature of your @RemoteAction method to

您需要将@RemoteAction方法的签名修改为

public static void verificarDireccion(String searchDir) {

and alter your Visualforce page's call to the method correspondingly, to pass the current value of this state variable directly to the method.

并相应地更改Visualforce页面对方法的调用,将此状态变量的当前值直接传递给方法。