Open <p:dialog> from bean by RequestContext#execute()

ぃ、小莉子 提交于 2019-12-11 12:07:26

问题


I have this form with a panel grid and a dialog:

<h:form id="regiForm">
    <p:panelGrid>
        <p:row style="height:30%">           
            <p:column>
                <h:outputText/> 
            </p:column>     
            <p:column>
                <p:commandButton style="width:350px" type="submit" actionListener="#
                {regiBean.showDialog}" id="ajax" value="#{msg['regi_button']}" update="regiForm"   process="@this"/>
            </p:column>  
            <p:column>
            </p:column>  
        </p:row>  
    </p:panelGrid>
    <p:dialog id="dialog" header="#{msg['regi_dialog_header']}" widgetVar="myDialog"  position="center center" >  
        <h:outputText value="#{msg['regi_dialog']}" />  
    </p:dialog>
</h:form>

I would like to open the dialog from inside the action listener:

public void showDialog() {
    RequestContext.getCurrentInstance().execute("dialog.show()");
    RequestContext.getCurrentInstance().execute("myDialog.show()");
}

However, the dialog is not shown. How is this caused and how can I solve it?

I'm using JSF 2.1 and PrimeFaces 3.5.


回答1:


The first statement with the command

RequestContext.getCurrentInstance().execute("dialog.show()");

won't work because dialog refers to the XHTML ID of the p:dialog component. This will cause an javascript error. And that could be the reason why the second command

RequestContext.getCurrentInstance().execute("myDialog.show()");

won't get executed. Also I would add ; to the end of each Javascript command (but this is just my personal style)



来源:https://stackoverflow.com/questions/20073580/open-pdialog-from-bean-by-requestcontextexecute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!