Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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
Java 使用对话框编辑datatable行_Java_Jsf_Primefaces_Datatable_Dialog - Fatal编程技术网

Java 使用对话框编辑datatable行

Java 使用对话框编辑datatable行,java,jsf,primefaces,datatable,dialog,Java,Jsf,Primefaces,Datatable,Dialog,我使用的是Primefaces 3.5、Jsf 2,我有一个datatable,现在我实现了一个类似Primefaces showcase(singlerowselection)的对话框,它工作正常,但我想编辑对话框中的行。此外,我希望inputtext中填充来自datatable单元格的数据,以便您可以轻松地编辑它!(就像行编辑器那样,只是在对话框中) 不是这样的: 水印可以工作,但它不是选项,因为如果要编辑它,文本将消失。 应该是这样的: 那么,有人能告诉我如何显示和编辑单元格数据吗 这是x

我使用的是Primefaces 3.5、Jsf 2,我有一个datatable,现在我实现了一个类似Primefaces showcase(singlerowselection)的对话框,它工作正常,但我想编辑对话框中的行。此外,我希望inputtext中填充来自datatable单元格的数据,以便您可以轻松地编辑它!(就像行编辑器那样,只是在对话框中) 不是这样的: 水印可以工作,但它不是选项,因为如果要编辑它,文本将消失。 应该是这样的:

那么,有人能告诉我如何显示和编辑单元格数据吗

这是xhtml(对话框不在数据表中):

提前谢谢


<h:form id="form">   
                        <p:dataTable  id="table" var="item" value="#{ManagedBean.list()}" 


                    <f:facet name="footer">  

                                    <p:commandButton id="showUpdateButton" value="#{msgForms['actions.Edit']}" 
                                                     update=":update_form" 
                                                     icon="ui-icon-pencil"  
                                                     style="margin: 0%"
                                                     ajax="true" 
                                                     immediate="true" 
                                                     oncomplete="PF('DialogUpdate').show()"
                                                     />                                                                                                         
                                       </f:facet>  


                        </p:dataTable>

                         <h:form id="form">  


<p:dialog id="dialog_update"
                              modal="true"
                              header="${msgForms['titles.update']}" 
                              widgetVar="DialogUpdate" resizable="false"  
                              showEffect="clip" hideEffect="fold"                              
                              >  
                        <h:form id="update_form">
                            <h:panelGrid columns="3" id="panel"> 
        <!--FIELDS-->  
                            <h:outputLabel for="nombre" value="#{msgForms['fields.nombre']}:" /> 
                            <p:inputText id="nombre"  
                                         value="#{ManagedBean.selectedItem.nombre}" 
                                         required="true"
                                         requiredMessage="#{msgForms['field.required']}"
                                         >   
                                <p:ajax event="keyup" update="nombreMsg" global="false"/>  
                            </p:inputText>  

                            </h:panelGrid>   

                            <!--/FIELDS-->
                            <!-- BUTTONS ACTIONS-->  
                            <p:commandButton id="updateButtonDg" 
                                             value="#{msgForms['actions.update']}" 
                                             icon="ui-icon-pencil"    
                                             actionListener="#{ManagedBean.update()}"
                                             update=":form:"
                                             style="margin: 0%"  
                                             ajax="true"
                                             onclick="DialogUpdate.hide();" 
                                             > 
                            </p:commandButton>
                            <!-- /BUTTONS ACTIONS-->
                        </h:form>
                    </p:dialog>  




    the MANAGED BEAN..       

                    @Named("ManagedBean")

@RequestScoped
public class ManagedBean  { 
    //Spring Item Service is injected... 
    @Inject
    IItemService itemService;  //if not required because if you use dependencies injection to connect with de database
    private List<Item> filteredItems; //only if you use the  attribute: filteredValue="#{ManagedBean.filteredItems}" in the dataTable 
    private List<Item> items; 



                    public void update() {  
                    //here you save the changes in the data base
                    this.itemService().updateItem(this.selectedItem); 



    }
public void onEdit() throws  Exception {
    PreparedStatement ps = null;
    Connection con = null;
    int i = 0;
    try {
        Server ser = new Server();

        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
                .newInstance();
        con = DriverManager
                .getConnection("jdbc:sqlserver://...");
        String sql = "UPDATE VAI_Serverlist SET [Data Center Location]= ?,...  WHERE Identification='"
                + ser.identification + "'";

        ps = con.prepareStatement(sql);
        ps.setString(1, ser.dataCenterLocation);
        ...
        i = ps.executeUpdate();
    } catch (SQLException e) {
        System.out.println(i);
        e.printStackTrace();
    } finally {
        try {
            con.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
<h:form id="form">   
                        <p:dataTable  id="table" var="item" value="#{ManagedBean.list()}" 


                    <f:facet name="footer">  

                                    <p:commandButton id="showUpdateButton" value="#{msgForms['actions.Edit']}" 
                                                     update=":update_form" 
                                                     icon="ui-icon-pencil"  
                                                     style="margin: 0%"
                                                     ajax="true" 
                                                     immediate="true" 
                                                     oncomplete="PF('DialogUpdate').show()"
                                                     />                                                                                                         
                                       </f:facet>  


                        </p:dataTable>

                         <h:form id="form">  


<p:dialog id="dialog_update"
                              modal="true"
                              header="${msgForms['titles.update']}" 
                              widgetVar="DialogUpdate" resizable="false"  
                              showEffect="clip" hideEffect="fold"                              
                              >  
                        <h:form id="update_form">
                            <h:panelGrid columns="3" id="panel"> 
        <!--FIELDS-->  
                            <h:outputLabel for="nombre" value="#{msgForms['fields.nombre']}:" /> 
                            <p:inputText id="nombre"  
                                         value="#{ManagedBean.selectedItem.nombre}" 
                                         required="true"
                                         requiredMessage="#{msgForms['field.required']}"
                                         >   
                                <p:ajax event="keyup" update="nombreMsg" global="false"/>  
                            </p:inputText>  

                            </h:panelGrid>   

                            <!--/FIELDS-->
                            <!-- BUTTONS ACTIONS-->  
                            <p:commandButton id="updateButtonDg" 
                                             value="#{msgForms['actions.update']}" 
                                             icon="ui-icon-pencil"    
                                             actionListener="#{ManagedBean.update()}"
                                             update=":form:"
                                             style="margin: 0%"  
                                             ajax="true"
                                             onclick="DialogUpdate.hide();" 
                                             > 
                            </p:commandButton>
                            <!-- /BUTTONS ACTIONS-->
                        </h:form>
                    </p:dialog>  




    the MANAGED BEAN..       

                    @Named("ManagedBean")

@RequestScoped
public class ManagedBean  { 
    //Spring Item Service is injected... 
    @Inject
    IItemService itemService;  //if not required because if you use dependencies injection to connect with de database
    private List<Item> filteredItems; //only if you use the  attribute: filteredValue="#{ManagedBean.filteredItems}" in the dataTable 
    private List<Item> items; 



                    public void update() {  
                    //here you save the changes in the data base
                    this.itemService().updateItem(this.selectedItem); 



    }