Dialog disappears after being opened

0

I'm using a primefaces dialog:

<h:form>
    <p:dialog widgetVar="dialog" modal="true" resizable="false">
        <p:outputLabel value="Mensagem qualquer."/>
        <p:commandButton value="Botão 1" action="#{chama um método no ManagedBean}"/>
        <p:commandButton value="Botão 2" action="#{chama um método no ManagedBean}"/>
    </p:dialog>
    <p:link value="Abrir caixa de diálogo." onclick="PF('dialog').show()"/>
<h:form>

I was watching as I hovered over the <p:link/> the page address appears in the footer as if it were a redirect.

Why does this happen? There is no URL. How can I resolve?

    
asked by anonymous 15.11.2014 / 23:10

2 answers

1

When you write a <p:link> , the generated markup is a link to the page itself.

If the intention is to only have the link as esthetic, not to navigate, just give return false; after all processing that does in onclick , in that way it will block the default behavior that is to navigate.

The result would be:

<p:link value="Abrir caixa de diálogo." onclick="PF('dialog').show(); return false;"/>

If you want to use% cos_de% only for aesthetics, it would be better to use <a> and stylize it to look like <span> .

    
15.11.2014 / 23:29
1

This happens because the p: link turns the tag <a> and in HTML when this tag does not receive any link if it considers that the link is the one of the current page.

example

<a href="">clique aqui</a> 

go to the page itself, to solve this put a hashtag in the link

// no seu caso
<a href="#" onclick="PF('dialog').show()">Abrir caixa de diálogo.</a> 

Why do not I know if this would work:

<p:link outcome="#" value="Abrir caixa de diálogo." onclick="PF('dialog').show()"/>
Try and give feedback. :)

    
15.11.2014 / 23:21