我遇到了在commandLink中从actionListener
传递对象到支持bean的问题。我拥有的是bean MeasureBean
和xhtml
文件,它使用bean。
在xhtml中我有:
<p:selectOneListbox var="ch">
<f:selectItems value="#{MeasureBean.checkpoints}" var="cp" itemValue="#{cp}" />
<p:column>
<h:outputText value="#{ch.name}" />
</p:column>
<p:column>
<h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(ch)}">
<h:graphicImage library="#{ctx.theme}" name="images/delete.gif" />
<f:ajax event="click" />
</h:commandLink>
</p:column>
</p:selectOneListbox>
在bean中我有方法:
public void onCheckpointRemoved(Checkpoint viewCheckpoint) {
System.out.println(viewCheckpoint);
// TODO
}
问题是,无论我是否使用标签<f:ajax>
,bean中方法的参数viewCheckpoint始终为null。我需要将该参数传递给bean。它不必是整个对象,只允许传递检查点的id。我也尝试过,是:
<h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(cp)}">
(cp
代替ch
)。但没有区别。
请帮忙,
Mateusz
答案 0 :(得分:0)
您忘记设置<p:selectOneListBox>
的值。此外,您还必须创建一个转换器。
<p:selectOneListbox var="ch" value="#{MeasureBean.checkPointTest}" converter="checkPointConverter">
<f:selectItems value="#{MeasureBean.checkpoints}" var="cp" itemValue="#{cp}" />
<p:column>
<h:outputText value="#{ch.name}" />
</p:column>
<p:column>
<h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(ch)}">
<h:graphicImage library="#{ctx.theme}" name="images/delete.gif" />
<f:ajax event="click" />
</h:commandLink>
</p:column>
</p:selectOneListbox>
Checkpoint checkPointTest;
// getter/setter....
public void onCheckpointRemoved(Checkpoint viewCheckpoint) {
System.out.println(viewCheckpoint);
// TODO
}