1

我有 xhtml 页面,该页面在该数据网格内有数据网格我想通过使用按钮或链接按钮调用方法,我编写如下代码来做到这一点

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <title>TODO supply a title</title>        
</h:head>    
<h:body>
    <p:layout fullPage="true">
        <p:layoutUnit position="center">
            <p:graphicImage value="images/common/banner1.png" 
                            style="width: 100%;min-width: 1350px"/>                
            <h:form id="menu_bar_form">  
                <p:menubar style="font-size: 14px;min-width: 1340px;" >  
                    <p:menuitem style="width: 50px" disabled="true"/>
                    <p:menuitem value="HOME" url="home.xhtml"/>
                    <p:menuitem style="width: 100px" disabled="true"/>                       
                    <p:submenu label="PHONES">
                        <p:menuitem value="Apple" outcome="phones">
                            <f:param name="brand" value="Apple"/>
                        </p:menuitem>
                        <p:menuitem value="Motorola" outcome="phones">
                            <f:param name="brand" value="Motorola"/>
                        </p:menuitem>
                        <p:menuitem value="Nokia" outcome="phones">
                            <f:param name="brand" value="Nokia"/>
                        </p:menuitem>
                        <p:menuitem value="Samsung" outcome="phones">
                            <f:param name="brand" value="Samsung"/>
                        </p:menuitem>
                    </p:submenu>
                    <p:menuitem style="width: 100px" disabled="true"/>
                    <p:menuitem value="COMPARE"/>
                    <p:menuitem style="width: 100px" disabled="true"/>
                    <p:submenu label="ACCESSORIES">  
                       //ADD CONTENT 
                    </p:submenu>
                    <p:menuitem style="width: 100px" disabled="true"/>
                    <p:menuitem value="CONTACT"/>
                    <f:facet name="options">  
                        <h:panelGrid columns="2" style="font-size: 12px">
                            <p:autoComplete id="search_textBox" value="#{homeBean.searchItem}"   
                                            completeMethod="#{homeBean.search}"/>
                            <p:commandButton value="Search" icon="ui-icon-search" />
                        </h:panelGrid>
                    </f:facet> 
                </p:menubar>
            </h:form>
            <h:form id="page_content">
                <table cellspacing="2" style="font-size: 14px;
                       width: 100%;min-width: 1350px">
                    <thead>
                        <tr>
                            <th></th>
                            <th style="width: 1000px;text-align:center">
                               <p:dataGrid var="phone" value="#{phonesBean.phoneList}" columns="8"
                             rows="12" paginator="true"  
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
    rowsPerPageTemplate="9,12,15" style="text-align: center;">  
// ++++++++++++++++++++++++++++++++++++ Problem++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                   <p:panel header="#{phone.model}" style="width: 175px"  >  
                                       <h:panelGrid columns="1" style="width:100%">  
                                            <p:graphicImage value="#{phone.imageUrl}"/>
                                        </h:panelGrid>
                                       <p:commandButton value="click here" action="#{phonesBean.test()}"/>
                                    </p:panel>
//+++++++++++++++++++++++++++++++++++Problem+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                             </p:dataGrid>                                   
                            </th>
                            <th></th>
                        </tr>
                    </thead>
                </table>                                  
            </h:form>                
        </p:layoutUnit>  
    </p:layout>
</h:body>

我调试了代码,但测试方法不会调用。并且没有任何异常或错误。

4

1 回答 1

0

在不带括号的EL中写入方法名称并添加ajax="false"

<p:commandButton value="click here" action="#{phonesBean.test}" ajax="false"/>
于 2017-02-15T10:45:19.060 回答