为什么没有弹出这个对话框?(JSF2.0 + PRIMEFACES)

时间:2011-03-31 08:06:18

标签: java jsf java-ee jsf-2 primefaces

我想在单击一个表行时弹出一个对话框,但它不起作用。(primefaces组件p:dataTable和p:dialog)此外,它看起来像selectioMode无法正常工作。为什么会这样?

JSF页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm2">
<h:form enctype="multipart/form-data">              
    <p:dataTable var="garbage" value="#{resultsController.allGarbage}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" selection="#{resultsController.selectedGarbage}" selectionMode="single"
                      onRowSelectStart="fileDialog.show()">
            <p:column>
                <h:outputText value="#{garbage.filename}"/>
            </p:column>
        </p:dataTable>            
    </h:form>
    <p:dialog widgetVar="fileDialog">
        <h:outputText value="Dialog open"/>
    </p:dialog>   
</ui:define>
   </ui:composition>
</html>

这里是托管bean:

   @ManagedBean
   @ViewScoped
   public class ResultsController implements Serializable{
@EJB
private ISearchEJB searchEJB;

private Garbage garbage;

private List<Garbage> allGarbage;

private Garbage selectedGarbage;

public List<Garbage> getAllGarbage() {

    allGarbage = new ArrayList<Garbage>();
    for(Garbage g :searchEJB.findAllGarbage()) {
        allGarbage.add(g);
    }
    return allGarbage;
}   

public void setAllGarbage(List<Garbage> allGarbage) {
    this.allGarbage = allGarbage;
}


public Garbage getGarbage() {
    return garbage;
}

public void setGarbage(Garbage garbage) {
    this.garbage = garbage;
}   

public void onRowSelect(SelectEvent event){ 
    garbage = (Garbage)event.getObject(); 
}

public Garbage getSelectedGarbage() {
    return selectedGarbage;
}

public void setSelectedGarbage(Garbage selectedGarbage) {
    this.selectedGarbage = selectedGarbage;
}   

另请注意,在输出中我可以看到值,但是当我点击一行时它会变色但没有弹出对话框(另外我看起来我可以点击多行,这不应该像因为我使用selectionMode =“single”): enter image description here

1 个答案:

答案 0 :(得分:0)

你看过这个吗?

http://www.primefaces.org/showcase/ui/datatableRowSelectionSingle.jsf

您可以使用dataTable页脚中的按钮来调度Action。 您必须通过处理操作将对话框设置为可见。

希望这有点帮助。