Error: Reference not found. Binding an ActionListener method to a button in <af:button>

Error: Reference not found. Binding an ActionListener method to a button in <af:button>

我正在使用 Jdeveloper 12c 创建一个程序。该程序将使用用户生成的地址输入,然后将其标记在地图上。使用的地图是Jdeveloper 的专题地图功能。我遇到的问题是按钮的 actionListener。它应该启动 LLConverter class 的 addLocation 方法,该方法接受输入(在 RichInputText 中),将其转换为纬度和经度(通过大量转换,RTF-->String(所以我可以使用 GeoCoder转换为纬度和经度)--> float(用于专题地图),然后将这些值绘制到地图上。ActionListener #{AddButton.addLocation} 未被识别

这是我的两个 classes:

 public class LLConverter {

private static final String GEO_CODE_SERVER = "http://maps.googleapis.com/maps/api/geocode/json?";
private static RichInputText addressBind;

private List<LocationDetail> mapDetail = new ArrayList<LocationDetail>();

public LLConverter() {
        // Add Default location to map
        LocationDetail location = new LocationDetail();

        location.setLongitude((float) 105.0781);
        location.setLatitude((float) 40.5592);
        mapDetail.add(location);

        location = new LocationDetail();

        location.setLongitude((float) 91.5333);
        location.setLatitude((float) 41.6667);
        mapDetail.add(location);

        System.out.println("List is-" + mapDetail);
    }    
public void addLocation(ActionEvent actionEvent, String addressBind)throws IOException, BadLocationException{


        RTFEditorKit rtfParser = new RTFEditorKit();
        Document document = rtfParser.createDefaultDocument();
        ByteArrayInputStream bytearrayinputstream=new ByteArrayInputStream(addressBind.getBytes());
        rtfParser.read(bytearrayinputstream,document,0);
        String code = document.getText(0, document.getLength());

        String response = getLocation(code);

        String[] result = parseLocation(response);

        float[] numbers = new float[result.length];
            for (int i = 0; i < result.length; ++i) {
                float number = Float.parseFloat(result[i]);
                float rounded = (int) Math.round(number * 1000) / 1000f;
                numbers[i] = rounded;
            }
        float lat = numbers[0];
        float lon = numbers[1];

        LocationDetail location = new LocationDetail();
        location = new LocationDetail();
        location.setLongitude(lat);
        location.setLatitude(lon);
        mapDetail.add(location);



    System.out.println("List is-" + mapDetail);

}

public void setAddressBind(RichInputText addressBind) {
    this.addressBind = addressBind;
}

public RichInputText getAddressBind() {
    return addressBind;
}
private static String getLocation(String code)
{
    String address = buildUrl(code);

    String content = null;

    try
    {
        URL url = new URL(address);

        InputStream stream = url.openStream();

        try
        {
            int available = stream.available();

            byte[] bytes = new byte[available];

            stream.read(bytes);

            content = new String(bytes);
        }
        finally
        {
            stream.close();
        }

        return (String) content.toString();
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}

private static String buildUrl(String code)
{
    StringBuilder builder = new StringBuilder();

    builder.append(GEO_CODE_SERVER);

    builder.append("address=");
    builder.append(code.replaceAll(" ", "+"));
    builder.append("&sensor=false");

    return builder.toString();
}

private static String[] parseLocation(String response)
{
    // Look for location using brute force.
    // There are much nicer ways to do this, e.g. with Google's JSON library: Gson
    //     https://sites.google.com/site/gson/gson-user-guide

    String[] lines = response.split("\n");

    String lat = null;
    String lng = null;

    for (int i = 0; i < lines.length; i++)
    {
        if ("\"location\" : {".equals(lines[i].trim()))
        {
            lat = getOrdinate(lines[i+1]);
            lng = getOrdinate(lines[i+2]);
            break;
        }
    }

    return new String[] {lat, lng};
}

private static String getOrdinate(String s)
{
    String[] split = s.trim().split(" ");

    if (split.length < 1)
    {
        return null;
    }

    String ord = split[split.length - 1];

    if (ord.endsWith(","))
    {
        ord = ord.substring(0, ord.length() - 1);
    }

    // Check that the result is a valid double
    Double.parseDouble(ord);

    return ord;
}

public void setMapDetail(List mapDetail) {
this.mapDetail = mapDetail;
}

public List getMapDetail() {
return mapDetail;
}    

public class LocationDetail {
private String location;
private float latitude; // Latitude of location
private float longitude; // Longitude of Location

    public LocationDetail() {
        super();
    }

public void setLatitude(float latitude) {
        this.latitude = latitude;
    }

    public float getLatitude() {
        return latitude;
    }

    public void setLongitude(float longitude) {
        this.longitude = longitude;
    }

    public float getLongitude() {
        return longitude;
    }          
}

还有我的地图代码,它是一个 jsf 页面。

<af:document title="Map.jsf" id="d1">
    <af:form id="f1">
        <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx" id="pt1"
                         >
            <f:facet name="center">
                <dvt:thematicMap basemap="usa" id="tm1" >
                    <?audit suppress oracle.adf.dvt.acc-compreqsummary?>
                    <dvt:areaLayer layer="counties" id="al1" />
                    <dvt:pointDataLayer id="dl1" value="#{viewScope.LLConverter.mapDetail}" var="row">
                        <dvt:pointLocation id="pl1"  type="pointXY" pointY="#{row.longitude}" 
                        pointX="#{row.latitude}">
                            </dvt:pointLocation>
                    </dvt:pointDataLayer>
                </dvt:thematicMap>
            </f:facet>
            <f:facet name="header"/>
            <f:facet name="end"/>
            <f:facet name="start">
                <af:inputText label="Address" id="it2" binding="#{viewScope.LLConverter.addressBind}">
                </af:inputText>
                <af:button text= "GetLocation" id="b1"
                           actionListener="#{AddButton.addLocation}"/>
            </f:facet>
            <f:facet name="branding"/>
            <f:facet name="copyright"/>
            <f:facet name="status"/>
        </af:pageTemplate>
    </af:form>
</af:document>

Addbutton是我给bean起的名字,class是LLConverter,method是addLocation。我试过多次重命名和创建 bean 以及不同的范围(这里没有,但我试过查看和请求范围)。

我一直收到同样的错误,"Reference addLocation not found."

该错误允许我将适当的方法自动生成到 LLConverter class,但是当我将我的代码放入该方法时,它再次给我错误。这让我相信它可能是 class 代码,而不是方法绑定。

非常感谢任何想法或想法!当然,我确定我错过了一些必要的信息,所以请问!

谢谢

您的 actionListener 只能有一个 ActionEvent 作为参数(因此删除所有其他内容)。 如果要发送额外的参数,可以使用如下逻辑:

在页面上:

<af:button text="button" id="cb1"
                  actionListener="#{myBean.myActionListener}">
  <f:attribute name="param" value="value"/>
</af:button>

豆中:

public void myActionListener(ActionEvent actionEvent) {
  String param = (String)actionEvent.getComponent().getAttributes().get("param");
}

你当然可以使用你的绑定。