2016-10-04 72 views
0

我试图调用一个应该返回一个XML文件的URL。 我想显示这个XML文件。 现在我不知道如何拨打电话来获取返回文件。 我用<p:commandButton process="@this" action="http://..." value="Test" />试了一下,但我得到2个警告。Primefaces调用URL并获取数据

警告文件:找不到一个MIME类型,在你的web.xml 时的警告的ressource添加一个MIME类型的映射:无法找到或操作。

回答

0

试试这个:

action=#{yourBean.yourAction} 

里面你的bean:

public void yourAction() { 

FacesContext fc = FacesContext.getCurrentInstance(); 
fc.getExternalContext().redirect("http://..."); 
fc.responseComplete(); 

} 

我不知道,如果是必要的,但你也可能想在p:commandButton

+0

我tryied这个了。我不想重定向。我想显示XML中的内容 – TheNewby

+0

当您尝试此操作时,出现了什么问题? – Nikola

+0

作为JSF页面的一部分显示?在应用程序的单独页面上显示“plain”xml?或者它是应用程序之外的资源,因为“http:// ...”会提示? – Nikola

0

您设置ajax=false需要使用restfull客户端来获取你的xml并解析它。

这是你的ActionListener的内容会从你的按钮被称为:

Client client = ClientBuilder.newClient(new ClientConfig().register(LoggingFilter.class)); 
WebTarget webTarget = client.target("http://localhost:8080/JerseyDemos/rest").path("employees"); 

Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_XML); 
Response response = invocationBuilder.get(); 

Employees employees = response.readEntity(Employees.class); 
List<Employee> listOfEmployees = employees.getEmployeeList(); 

(从http://howtodoinjava.com/jersey/jersey-restful-client-examples/#get-list

+0

我试过了,但是它从起始页返回了我的整个HTML,而不是来自我所调用的URL的XML – TheNewby