我正在使用Jdeveloper 12c创建一个程序。该程序将使用用户生成的地址输入,然后在地图上进行标记。使用的地图是Jdeveloper的主题地图特性。我遇到的问题是按钮的actionListener。它应该启动LLConverter类的addLocation方法,该方法接受输入(在RichInputText中),将其转换为纬度和经度(通过许多转换,RTF->String(因此我可以使用GeoCoder转换为Lat和Long) -> float(用于主题地图),然后将这些值绘制到地图上。ActionListener #{AddButton.addLocation}
不能被识别
这是我的两个类:
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;
}
}
我的map的代码,这是一个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的名称,它的类是LLConverter,方法是addLocation。我已经尝试了重命名和创建bean的疯狂次数和不同的作用域(这里没有一个,但我已经尝试了视图和请求作用域)。
我只是不断得到相同的错误,"参考addLocation未找到。"
错误允许我在LLConverter类中自动生成适当的方法,但是当我将代码放入该方法中时,它又给了我错误。这让我相信它可能是类代码,而不是方法绑定。
任何想法或想法都非常感谢!当然,我肯定我遗漏了一些必要的信息,所以请提问!
谢谢
你的actionListener只能有一个ActionEvent作为参数(所以删除其他一切)。如果你想发送额外的参数,你可以使用下面的逻辑:
在页面上:
<af:button text="button" id="cb1"
actionListener="#{myBean.myActionListener}">
<f:attribute name="param" value="value"/>
</af:button>
在bean中:
public void myActionListener(ActionEvent actionEvent) {
String param = (String)actionEvent.getComponent().getAttributes().get("param");
}
或你当然可以使用你的绑定