开发者

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

I have a JSF-2.0 dialog which has three p:inputText fields who's contents I want to make accessible to a bean when the p:commandButton is pressed. I have tried using f:attribute but that either passes the exact text of what I place into 'value' OR I get null if I try something like:

<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>  

is it possible to pass t开发者_StackOverflowhe value of what is found in the inputText this way?


Use the value attribute of p:inputText to bind it's content to a backing bean value:

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

And in your bean:

String myTextField;
// add getter and setter

If you want to bind the inputText to a different datatype you need a converter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜