0
votes

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 the value of what is found in the inputText this way?

1

1 Answers

2
votes

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.