How to pass data between pages?

Asked

Viewed 701 times

0

I’m trying to pass some values between pages using Managedbeans, but it’s not working:

@ManagedBean
@SessionScoped
public class Chute {
    private Boolean chutar;
    //getters e setters...
}

On the first page XHTML I have some <p:commandButton/>:

Pag1.xhtml

<p:commandButton value="Chutar" action="#{Chute.setChutar(true)}" onstart="window.open('pag2.xhtml');"/>
<p:commandButton value="Passar" action="#{Chute.setChutar(false)}" onstart="window.open('pag2.xhtml');"/>

The second takes the data sent by the first:

pag2.xhtml

<p:panel rendered="#{Chute.chutar}">
    <p:outputLabel value="Chutou!"/>
</p:panel>
<p:panel rendered="#{Chute.chutar ? false : true}">
    <p:outputLabel value="Passou!"/>
</p:panel>

The problem is when one of the buttons is clicked, the pag2.xhtml appears blank.
How can I solve? There are other approaches?

  • Try to change onstart for oncomplete. The problem is that it is opening the new window before the action be completed.

  • @Wakim, it was the same. The Managedbean needs a builder?

  • If the page is empty, there may be an error in your XHTML file and JSF cannot render the page.

  • If I put rendered="true" or simply remove the attribute, the panel appears.

  • Just exchange the rendered for #{not Chute.chutar} or #{! Chute.chutar} that works.

  • Did you give any exceptions (in the log’s)? Type one NullPoiterException for the attribute chutar?

  • It’s all clear, no exceptions.

  • Like the panels of pag2.xhtml You know whose session it is? I mean, isn’t he getting an empty session? For there is nothing saying it is to catch the object on which the value was assigned in pag1.xhtml.

Show 3 more comments

1 answer

1

Try to change your commandButton for that reason:

<p:commandButton value="Chutar" ajax="true" oncomplete="window.open('pag2.xhtml');">
    <f:setPropertyActionListener target="#{Chute.chutar}" value="true />
</p:commandButton>

I need to test, but I don’t know if it is possible to call getters and setters methods directly as a button action.

  • Renato, it is possible yes, with a Method Expression it is possible to call a method, although it is a Setter. But the setPropertyActionListener is interesting.

  • Didn’t work..

Browser other questions tagged

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