Jsf 当按下p:commandButton时,需要将p:inputText的值传递给bean

Jsf 当按下p:commandButton时,需要将p:inputText的值传递给bean,jsf,Jsf,我有一个JSF-2.0对话框,其中有三个p:inputText字段,当按下p:commandButton时,我想让bean访问这些字段的内容。我尝试过使用f:attribute,但它要么将我放置的内容的确切文本传递到“value”中,要么如果我尝试以下操作,则得到null: <h:form id="form"> <p:dataTable var="config" value="#{configBean.configList}" selection="

我有一个JSF-2.0对话框,其中有三个p:inputText字段,当按下p:commandButton时,我想让bean访问这些字段的内容。我尝试过使用f:attribute,但它要么将我放置的内容的确切文本传递到“value”中,要么如果我尝试以下操作,则得到null:

<h:form id="form">  
            <p:dataTable var="config" value="#{configBean.configList}" selection="#{configBean.selectedConfigs}">
                <p:column selectionMode="multiple">               
                    <f:facet name="header">  
                            Delete?  
                    </f:facet>                      
                </p:column> 



            <p:column headerText="Name">
                <h:outputText value="#{config.name}" />  
            </p:column>  

            <p:column headerText="Key">
                <h:outputText value="#{config.key}" />  
            </p:column>  

            <p:column headerText="Value">
                <h:outputText value="#{config.value}" />  
            </p:column>  
        </p:dataTable>

        <p:commandButton value="Add Row" 
                         oncomplete="addRowDialog.show()"/>
        <p:commandButton value="Delete" 
                         action="#{configBean.deleteSelectedConfigs}"/>

        <p:dialog header="Add Row" widgetVar="addRowDialog"  id="dialog"
                  width="250" height="300" showEffect="explode" hideEffect="explode">  

            <h:outputLabel for="name2" value="Name:"/>
            <p:inputText id="name2" name="name2" required="true"/>

            <p:commandButton value="Submit" actionListener="#{configBean.addNewConfigProperty}" onclick="addRowDialog.hide()" update="config">              
            <f:attribute name="name1" value="#{requestScope.name2}"/>
            </p:commandButton>
        </p:dialog>                              
    </h:form>  

删除?

是否可以通过这种方式传递在inputText中找到的值?

使用
p:inputText
value
属性将其内容绑定到支持bean值:

<p:inputText id="name2" value="#{myBean.myTextField}" required="true"/>

如果要将inputText绑定到不同的数据类型,则需要一个。

这是我尝试的第一个方法,但该值在页面视图之间不断丢失,即使设置了@ViewScoped,这也是我尝试使用属性的原因,因此,当单击按钮时,所有数据都出现在ActionEvent中。@Ryland:如果切换到其他视图,@ViewScoped bean将被销毁,您的值将丢失(这是预期的行为)。如果要保留该值,必须使用@SessionScoped,或者使用存储在数据库中的值预先填充ViewScoped bean(如果这是您正在执行的操作)。该页面显示一个带有“添加行”命令按钮的表,然后启动一个p:对话框,在其中输入信息。p:对话框有一个按钮“Submit”,然后调用bean上的一个backing方法。如果我执行“value=”并将断点放在各个setter中,它会被命中,但数据不会存储在每次进行的“set”调用之间(返回null)。这就是为什么我转而尝试使用属性。
String myTextField;
// add getter and setter