Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 在同一xhtml上保存和更新在primefaces中不起作用_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 在同一xhtml上保存和更新在primefaces中不起作用

Jsf 2 在同一xhtml上保存和更新在primefaces中不起作用,jsf-2,primefaces,Jsf 2,Primefaces,嗨,我使用primefaces尝试了以下功能。 在我的xhtml中,我有一个输入字段,它接受输入并保存到数据库中。保存完成后,我将保存的数据显示在primefaces的数据表中。 到现在为止一切正常。现在我向datatable添加了单个选择。当用户单击行时,我用所选数据更新相同的输入列。 为此,我使用以下代码 <h:form id="form"> <p:growl id="messages" /> <p:panel id="panel" header

嗨,我使用primefaces尝试了以下功能。 在我的xhtml中,我有一个输入字段,它接受输入并保存到数据库中。保存完成后,我将保存的数据显示在primefaces的数据表中。 到现在为止一切正常。现在我向datatable添加了单个选择。当用户单击行时,我用所选数据更新相同的输入列。 为此,我使用以下代码

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>

我的Bean代码是:

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
@managedBean
@viewScoped
@component 
public class CurrencyBean implements Serializable{

    private static final long serialVersionUID = 1L;

    @Autowired
    private CurrencyMaster currencyMaster;

    private List<CurrencyMaster> currencyList;

    public CurrencyMaster getCurrencyMaster() {
        return currencyMaster;
    }

    public void setCurrencyMaster(CurrencyMaster currencyMaster) {
        this.currencyMaster = currencyMaster;
    }           
    public void saveCurrency(){
        try{
            currencyService.saveCurrency(currencyMaster);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @PostConstruct
    public void currencyList(){
        setCurrencyList(currencyService.getCurrencyList());
    }
    public void onRowSelect(SelectEvent event) {}            
    public void onRowUnselect(UnselectEvent event) {}
}
@managedBean
@视域
@组成部分
公共类CurrencyBean实现了可序列化{
私有静态最终长serialVersionUID=1L;
@自动连线
私人货币管理人货币管理人;
私人名单;
公共CurrencyMaster getCurrencyMaster(){
返回货币管理器;
}
公共无效设置CurrencyMaster(CurrencyMaster CurrencyMaster){
this.currencyMaster=currencyMaster;
}           
公共无效存储货币(){
试一试{
currencyService.saveCurrency(currencyMaster);
}捕获(例外e){
e、 printStackTrace();
}
}
@施工后
公共无效货币列表(){
setCurrencyList(currencyService.getCurrencyList());
}
ROWSELECT(SelectEvent事件){}
公共无效onRowUnselect(UnselectEvent事件){}
}
因此,当我单击currencytable行时,输入字段将正确填充并更新操作

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
问题是,当我直接将数据输入到输入列时,我的globalMaster属性将为null

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
出现以下错误:

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
尝试使用空实体创建saveOrUpdate事件

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
我更改了bean的作用域,但没有找到解决方案

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>
我为上述异常找到了更多解决方案,但我的问题是新值未设置为currencymaster

<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>

我在这方面是否有任何错误。请指导我。

查看范围是从哪个包开始的?注释也是大写的。您也在使用spring吗?谢谢您的回复。javax.faces.bean.ViewScoped、javax.annotation.ManagedBean,我也使用了spring。将托管bean的导入包更改为this
javax.faces.bean.ManagedBean
很抱歉,我将javax.annotation.ManagedBean更改为javax.faces.bean.ManagedBean,但不起作用
<h:form id="form">
    <p:growl id="messages" />
    <p:panel id="panel" header="Currency">
        <h:panelGrid columns="2" id="currencyGrid">
            <p:outputLabel value="Currency :"/>
            <p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
        </h:panelGrid>
        <p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
                         update="currencytable">
        </p:commandButton>

        <p:dataTable id="currencytable" var="cur" 
                     value="#{currencyBean.currencyList}" widgetVar="dlg"
                     selection="#{currencyBean.currencyMaster}" 
                     selectionMode="single" rowKey="#{cur.currId}">
            <p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
                    update=":form:currencyGrid" />
            <p:column headerText="ID" style="font-size:12px;">
                <h:outputText value="#{cur.currId}" />
            </p:column>
            <p:column headerText="Description" style="font-size:12px;">
                <h:outputText value="#{cur.currDesc}" />
            </p:column>
    </p:dataTable>
</h:form>