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

发布于 2024-10-29 07:10:55 字数 2692 浏览 0 评论 0原文

我想在单击表行时弹出一个对话框,但它不起作用。(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;
}   

另请注意,在输出中我可以看到值,但是当我单击一行时,它会变色,但不会弹出对话框(而且我看起来可以单击多个行,即不应该是这样,因为我使用选择模式=“单”): 在此处输入图像描述

I want to make a dialog pop up when i click on a table row, but it doesnt work.(primefaces components p:dataTable and p:dialog) Also it looks like the selectioMode doesnt work correctly. Why is this happening?

The JSF page:

<!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>

Here the managed 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;
}   

Also notice that in the output i can see the values but when i click on a row it gets colored but no dialog pops up(Also i looks like i can click on more than one row, that is not supposed to be like that since i use selectionMode="single"):
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮倦 2024-11-05 07:10:55

你看过这个吗?

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

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

希望这会有所帮助。

Did you have a look at this?

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

You can use a button in the footer of the dataTable for dispatching an Action.
You have to set the dialog to visible by processing the Action.

Hope this helps a bit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文