Jsf h:dataTable中的h:commandButton
我使用的是JSF数据表。表中的一列是命令按钮 单击此按钮时,我需要使用表达式语言传递一些参数(如所选行的值)。这个参数需要传递给JSF托管bean,后者可以在这些参数上执行方法 我使用了下面的代码片段,但是我在JSFbean上得到的值总是空的Jsf h:dataTable中的h:commandButton,jsf,datatable,Jsf,Datatable,我使用的是JSF数据表。表中的一列是命令按钮 单击此按钮时,我需要使用表达式语言传递一些参数(如所选行的值)。这个参数需要传递给JSF托管bean,后者可以在这些参数上执行方法 我使用了下面的代码片段,但是我在JSFbean上得到的值总是空的 <h:column> <f:facet name="header"> <h:outputText value="Follow"/> </f:facet> <h:
<h:column>
<f:facet name="header">
<h:outputText value="Follow"/>
</f:facet>
<h:commandButton id="FollwDoc" action="#{usermanager.followDoctor}" value="Follow" />
<h:inputHidden id="id1" value="#{doc.doctorid}" />
</h:column>
如何使用commandbutton将值传递给JSF托管bean?用于获取当前行的action方法
@ManagedBean
@ViewScoped
public class Usermanager {
private List<Doctor> doctors;
private DataModel<Doctor> doctorModel;
@PostConstruct
public void init() {
doctors = getItSomehow();
doctorModel = new ListDataModel<Doctor>(doctors);
}
public void followDoctor() {
Doctor selectedDoctor = doctorModel.getRowData();
// ...
}
// ...
}
使用以下按钮:
<h:commandButton action="#{usermanager.followDoctor}" value="Follow">
<f:setPropertyActionListener target="#{usermanager.doctorId}" value="#{doc.doctorId}" />
</h:commandButton>
相关的:
- -包含使用
的CRUD示例DataModel
<h:dataTable value="#{usermanager.doctorModel}" var="doc">
public class Usermanager {
private Long doctorId;
public void followDoctor() {
Doctor selectedDoctor = getItSomehowBy(doctorId);
// ...
}
// ...
}
<h:commandButton action="#{usermanager.followDoctor}" value="Follow">
<f:setPropertyActionListener target="#{usermanager.doctorId}" value="#{doc.doctorId}" />
</h:commandButton>