0

我是 JSF 的新手。我在 JSF primefaces 中使用行可编辑数据表。在行可编辑数据表输入文本列中,它有两个 ajax 调用。一个是模糊,另一个是 Commandbuuton。我想从支持 bean 的这个输入文本列中获取值。

这是我的代码:

<h:form id="frm1">
<p:dataTable var="fert" value="#{fertilizerEntryBean.fertList}" id="fertList" editable="true"  scrollable="true" scrollWidth="900" scrollHeight="250" >

                            <p:ajax event="rowEdit" listener="#{fertilizerEntryBean.onEdit}" update=":frm1:messages :frm1:ha_amount" />  
                            <p:ajax event="rowEditCancel" listener="#{fertilizerEntryBean.onCancel}" update=":frm1:messages :frm1:ha_amount" />  
                            <p:column headerText="...." width="15">
                                <p:rowEditor />  
                            </p:column>
<p:column headerText="Receiver Plot No." width="150">
                                <p:cellEditor>  
                                    <f:facet name="output"><h:outputText value="#{fert.receiverPlot}" /></f:facet>  
                                    <f:facet name="input">
                                        <p:inputText id="receiverPlot" value="#{fert.receiverPlot}" size="15">
                                            <p:ajax event="blur" listener="#{fertilizerEntryBean.loadReceiverDetails(fert)}" update="receiverCode,receiverName"/>
                                        </p:inputText>&nbsp;
                                        <p:commandButton icon="ui-icon-search" style="height: 25px;position: absolute;" onclick="receiver_dialog.show();"/>
                                    </f:facet>  
                                </p:cellEditor>  
                            </p:column>
</p:datatable>
</h:form>
<h:form id="receiverForm">
            <p:dialog widgetVar="receiver_dialog" id="receiver_dialog">
                <p:dataTable id="receiver_table" value="#{fertilizerEntryBean.mediumFertModel}" selection="#{fertilizerEntryBean.selectedList}" selectionMode="single" var="fert" rows="10" liveScroll="true"  paginator="true" paginatorPosition="bottom" 
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  rowsPerPageTemplate="5,10,20">
                    <p:ajax event="rowSelect" listener="#{fertilizerEntryBean.onRowSelect}" update=':frm1:fertList:receiverPlot'/>
                    <p:column id="state_id_column" headerText="Receiver Code">
                        <h:outputText value="#{fert.receiverPlot}"/>
                    </p:column>
                </p:dataTable>
                <p:commandButton style="alignment-adjust: central;" value='OK' onclick="receiver_dialog.hide();"/>
            </p:dialog>
        </h:form>

还有我的豆类:

public class FertilizerEntryBean implements Serializable{
private List<FertModel> fertList=null;
private FertDataModel mediumFertModel;
private FertModel selectedList;
public List<FertModel> getFertList() {
    return fertList;
}

public void setFertList(List<FertModel> fertList) {
    this.fertList = fertList;
}
public FertDataModel getMediumFertModel() {
    getReceiverCode();
    return mediumFertModel;
}

public void setMediumFertModel(FertDataModel mediumFertModel) {
    this.mediumFertModel = mediumFertModel;
}

public FertModel getSelectedList() {
    return selectedList;
}

public void setSelectedList(FertModel selectedList) {
    this.selectedList = selectedList;
}
public List<FertModel> getReceiverCode(){
Session session=HibernateUtil.getSessionFactory().openSession();
try{
    List<DosVendormaster> vendorList=session.createCriteria(DosVendormaster.class).add(Restrictions.eq("vendortype", "CGRV")).add(Restrictions.eq("block", "X")).list();
    if(vendorList.size()>0){
        for (Iterator<DosVendormaster> it = vendorList.iterator(); it.hasNext();) {
            DosVendormaster dosVendormaster = it.next();
            fertList.add(new FertModel(dosVendormaster.getSapVendorcode()));
        }
        mediumFertModel=new FertDataModel(fertList);
    }
}catch(Exception ex){
    ex.printStackTrace();
}finally{
    session.close();
}
return fertList;
}

public void onRowSelect(SelectEvent event) {
    FacesMessage msg = new FacesMessage(" Selected", ((FertModel)        event.getObject()).getReceiverPlot());
    FacesContext.getCurrentInstance().addMessage(null, msg);
    FertModel fert=new FertModel();
    fert.setReceiverPlot(((FertModel) event.getObject()).getReceiverPlot());
}
}
4

1 回答 1

1

你可以试试这个:FacesContext.getCurrentInstance().getViewRoot().findComponent(id)其中 id 类似于frm1:fert:(rowIndex):receiverPlot. 这就是您可以找到组件并为该组件使用 getValue 的方式。您可以通过将rowIndexVar属性设置为数据表来获取 rowIndex

于 2013-09-18T13:01:30.503 回答