Dialog some after opening

Asked

Viewed 986 times

0

I’m using a dialog of the first faces:

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

2 answers

1

This is because p:link turns the tag <a> and in HTML when this tag does not receive any link is considered to be the link of the current page.

example

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

will direct to own page, to solve this put a hashtag on the link

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

'Cause I don’t know if that would work:

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

Try and give feedback. :)

  • outcome="#" made a mistake. href="#" did not give error, but froze the page. I put the modal as false and stopped freezing, but it is not interesting for me to leave without this property. I think the problem now involves the modal. Is there any workaround?

  • I believe that the Wakim solution will be the correct alternative if you want to use p:link

1


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

If the intention is just to have the link as aesthetic, not to navigate, just give a return false; after all the processing onclick, this way 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 a <a> just by aesthetic, it would be better to use a <span> and stylize to look like a <a>.

  • The only problem is that it is also freezing the page if the modal is activated.

  • There is an error in the browser or server console?

  • Nothing on either one.

  • @Patrick, I did a test with this code and saw no problem. The action of Bean is executed? What did you mean how frozen? Modal is not closed after action?

  • You can’t do anything on the screen, as if it were a screen printscreen. The bean action is not performed because I can’t even click the button.

  • @Patrick, then there is another problem in your code. I suggest creating another question, close with a mcve with your code View and its Managed Bean that reproduces the problem, because it may clash with the main objective of this question.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.