1

我的 JSF 页面和(可能)支持 bean 有一些问题。我有自己的模板,我用一些页面填充内容区域。我有带有命令按钮的搜索页面,我想从数据库(JPA)中获取数据,然后填充数据表。看看我的 searchpeople.xhtml:

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form id="sampleform">  
            <p:accordionPanel activeIndex="-1" id="accordingpanle">  
                <p:tab title="User options" >   
                    <p:growl id="growl" showDetail="true" showSummary="true"/> 
                    <p:commandButton id="searchbutton" action="#{mb_person.search}" value="Szukaj" update="personsearchresulttable" />
                </p:tab>
            </p:accordionPanel>

            <p:dataTable id="personsearchresulttable" var="person" value="#{mb_person.people}" widgetVar="personTable" style="margin-top: 10px" >  
                <p:column headerText="Id" style="width:10%">
                    <h:outputText value="#{person.id}" />  
                </p:column>
                <p:column headerText="Name" style="width:20%">  
                    <h:outputText value="#{person.name}" />  
                </p:column>  
                <p:column headerText="Surname" style="width:20%">  
                    <h:outputText value="#{person.surname}" />  
                </p:column>  
                <p:column headerText="Company">  
                    <h:outputText value="#{person.companyName}" />  
                </p:column> 
                <p:column style="width:4%" headerText="Open">  
                    <h:link outcome="persondetails" value="Open">
                        <!--<f:param name="personid" value="#{person.id}"/>-->
                        <f:param name="personid" value="10076"/>
                    </h:link>
                </p:column>  
            </p:dataTable>  
        </h:form>  
    </ui:define>
</ui:composition>

还有我的 EJB 注入的 backingbean。

@ManagedBean(name="mb_person")
public class MB_Person implements Serializable{

    @EJB
    private PersonFacade personFacade;
    private List<PersonAndCompany> people = new ArrayList<PersonAndCompany>();

    public MB_Person() {
    }

    public List<PersonAndCompany> getPeople() {
        return people;
    }

    public void setPeople(List<PersonAndCompany> people) {
        this.people = people;
    }

    public void search() {
        int[] range = {0,5};
        setPeople(personFacade.findPersonWithMoreThanXProjects(20));
        setPeople(personFacade.findPersonAndCompanyName(range));

        for(PersonAndCompany p:people){
            System.out.println(p.getName());
        }
    }
    public String goToPersonDatailPage(int id){
        return "persondetails.jsf?personid="+id;
    }
}

我尝试了小测试并打印出方法搜索中的所有数据,我收到了很好的结果。有人可以帮助我如何使用 ajax 更新 dataTable?在这种形式中,我遇到了一个异常 ,无法找到从“sampleform:accordingpanle:searchbutton”引用的标识符为“personsearchresulttable”的组件。

4

1 回答 1

2

NamingContainer相对于父组件搜索相对客户端 ID 。<p:accordionPanel>本身就是NamingContainer一个. 因此,相对客户端 IDpersonsearchresulttable将在<p:accordionPanel>. 但是,它实际上在面板之外,在<h:form>.

您需要将相对客户端 ID 更改为绝对客户端 ID。

update=":sampleform:personsearchresulttable"

也可以看看:

于 2012-11-23T15:13:38.547 回答