f:p:commandLink
中的setPropertyActionListener如何将target-Attribut的setter中的数据带到周围onclick-attribute的getter?
我想在ap:CommandLink(onclick =“window.open('http://www.somewebsite.de ...')”中为数据表的每一行构建一个超链接。所以“somewebsite”的Request-parameters改变了取决于实际行。 我有一个工作p:commandLink,因为我可以生成一个新的浏览器窗口但只有一个(常量![这就是问题/挑战])网站。 我也可以通过p:commandLink从EACH行访问所需的数据,这意味着我需要的超链接 - 请求参数所属的数据,但是我不能将它们组合在一起,因为我得到了一个Nullpointer-Exception。
看看标有//的地方//这里有问题
<p:dataTable value="#{columnsViewZwei.dataList1}" var="row"
resizableColumns="true"
styleClass="foo"
tableStyleClass="maggtabl2"
tableStyle="maggtabl2"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row">
<p:column headerText="Titel" sortBy="#{row.titel}" filterBy="#{row.titel}">
<h:outputText value="#{row.titel}" />
</p:column>
<p:column headerText="Typ" sortBy="#{row.typ}" filterBy="#{row.typ}">
<h:outputText value="#{row.typ}" />
</p:column>
<p:column headerText="Metadaten" style="width:64px;text-align: center">
<p:commandLink value="show" title="show metatdata" onclick="#{columnsViewZwei.testurl}" >
<f:setPropertyActionListener value="#{row}" target="#{columnsViewZwei.selectedSET}" />
</p:commandLink>
</p:column>
</p:dataTable>
package bbb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.xml.stream.XMLStreamException;
import bbb.InspireDS;
@ManagedBean
@ViewScoped
public class ColumnsViewZwei implements Serializable {
private String testurl = "";
private InspireDS selectedDataset;
public InspireDS getSelectedDataset() {
System.out.println("getSelectedDataset() ");
return this.selectedDataset;
}
public String selectedDataset() {
selectedDataset = getSelectedDataset();
this.testurl = "window.open('..Info.do?fileIdentifier="+selectedDataset.metadaten+"')";
return testurl;
}
public void setTesturl(String testurl){
this.testurl = "window.open('http://...Info.do?fileIdentifier="+selectedDataset.metadaten+"')";
}
public String getTesturl() {
//selectedDataset = getSelectedDataset();
// HERE SEEMS TO BE THE PROBLEM: NullPointerException probably for selectedDataset
//this.testurl = "window.open('..?fileIdentifier="+selectedDataset.metadaten+"')";
this.testurl = "window.open(' ...')"; // works, but constant hyperlink
return testurl;
}
// This from f:setPropertyActionListener value="#{row}" target="#{columnsViewZwei.selectedSET}
// brings the data I need, but it should be accessable in getTesturl()
public void setSelectedSET(InspireDS inspirDS) {
this.selectedDataset = inspirDS;
this.testurl = "window.open('...do?fileIdentifier="+selectedDataset.metadaten+"')";
}
private List<InspireDS> dataList1;
@ManagedProperty("#{inspireTabelleBean}")
private InspireTabelleBean insTabBean;
@PostConstruct
public void init() {
try {
if(insTabBean==null){System.out.println("s e r v i ce = = n u ll");}
dataList1 = insTabBean.fillListbyparse();
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setService(InspireTabelleBean service) {
this.insTabBean = service;
}
public List<InspireDS> getDataList1() {
return dataList1;
}
public void setInsTabBean(InspireTabelleBean service) {
this.insTabBean = service;
}
}
答案 0 :(得分:1)
我无法重现您的代码,我做了一个没有datatable
的简化版本。
而不是window.open
函数,我只是使用了target="_blank"
中的onclick
,如此this post中所述。
您所犯的错误是使用f:setPropertyActionListener
和faces-redirect=true
。 this post中解释了无法运作的原因。
ajax
(详情请见this post),false
必须为<h:form id="form_open_window" target="_blank">
<p:commandLink value="show" title="show metatdata" action="#{columnsViewZwei.goToUrl()}" ajax="false" >
<f:setPropertyActionListener value="metadata_parameter" target="#{columnsViewZwei.metadata}" />
</p:commandLink>
</h:form>
。
但是,当您想要通过js调用bean函数时,请查看remote command。
xhtml页面:
private String testurl = "index";
private String metadata;
public String getMetadata() {
return metadata;
}
public void setMetadata(String metadata) {
this.metadata = metadata;
}
public String goToUrl() {
System.out.println(metadata);
return testurl + "?faces-redirect=true&fileIdentifier=" + metadata;
}
Bean代码:
oncomplete
PS:如果您不希望偏离解决方案太多,请评估使用onclick
代替{{1}},但我没有尝试过。
我希望这很有用。
答案 1 :(得分:0)
感谢您的快速回答。我用过你的建议,但发生的事情不是我想要的。 (桌子扭曲等) 我为goToUrl(){...}输入了每个方法(getter和setter)System.out.println(...), 但我没有在控制台上看到任何打印输出。所以调用哪些代码是神秘的。
当我点击commandLink时,我得到了一个带有相同facelet的新窗口&#34; index.xhtml&#34;因为我从开始。我猜这是testurl =&#34; index&#34 ;;我的视图文件(facelet)的名称为&#34; index.xhtml&#34;。
我认为你提到其他帖子很好,所以我可以尝试理解你的论点。
我想我需要值=&#34;#{row}&#34;在f:setPropertyActionListener中访问当前行/数据集,因为在当前行/数据集中是构建调用/访问远程网站的URL所需的信息。
亲切的问候, 此致 tsitra
ooooooooooooooooo 日期:2014年12月22日 不使用Primefaces组件(控件)的可能解决方案是:
<p:dataTable value="#{columnsViewZwei.dataList1}" var="o9"
resizableColumns="true">
<p:column headerText="Titel" sortBy="#{o9.titel}" filterBy="#{o9.titel}">
<h:outputText value="#{o9.titel}" />
</p:column>
<p:column headerText="Typ" sortBy="#{o9.typ}" filterBy="#{o9.typ}">
<h:outputText value="#{o9.typ}" />
</p:column>
<p:column headerText="Metadaten">
<a href="https://geoportal.bafg.de/portal/Query/ShowCSWInfo.do?fileIdentifier=#{o9.identifier}" target="_blank">show</a>
</p:column>
</p:dataTable>
&#13;