簡體   English   中英

按下 p:commandButton 時需要將 p:inputText 的值傳遞給 bean

[英]Need to pass value of p:inputText to a bean when p:commandButton is pressed

我有一個 JSF-2.0 對話框,其中包含三個 p:inputText 字段,當按下 p:commandButton 時,我希望 bean 可以訪問這些字段的內容。 我曾嘗試使用 f:attribute ,但要么將我放置的確切文本傳遞給“值”,要么如果我嘗試類似的操作,我會得到 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:inputTextvalue屬性將其內容綁定到支持 bean 值:

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

在你的 bean 中:

String myTextField;
// add getter and setter

如果要將 inputText 綁定到不同的數據類型,則需要一個轉換器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM