0
votes

My page has a search button to bring rates the address entered. After the research I want to be held to enable the print button.

                <p:commandButton value="#{msg['btn-search']}"
                    styleClass="btn btn-primary" onclick="codeAddress()" />
                <p:remoteCommand actionListener="#{searchBean.addMarker()}"
                    name="consultaValor"
                    update="bandeira1, bandeira2,bandeira1Value, bandeira2Value,origemInfo,addressInfo"/>
                <p:commandButton id="print" value="Imprimir" styleClass="btn btn-primary" rendered="#{searchBean.print.booleanValue()}" >
                    <p:printer target="information" />
                </p:commandButton>

I tried to use the rendered attribute that receives a boolean of my searchBean but did not work can anyone help me?

private Boolean print = false;

public Boolean getPrint() {
    return print;
}

public void setPrint(Boolean print) {
    this.print = print;
}
public void addMarker() {
    Marker marker = new Marker(new LatLng(lat, lng),address);
    emptyModel.addOverlay(marker);           
    result = true;
    String wktFilter = "POINT("+getLng()+" "+getLat()+")";

    findByWKT(wktFilter);

    print = true;

}

The addMarker method is called by the search button then it went true to the boolean print but does not work.

1
1. you don't need booleanValue(), 2. onclick on a commandButton makes for some suprises. 3. So you're saying that codeAddress will call consultaValor? Are you sure the actionListener and the new render phase get to see the same bean (breakpoint the bean's constructor to find out)? - mabi
Didn't you forget an update="... print" on the p:remoteCommand? - rion18
Agree with above comments. Besides I think you need to either use "disabled" instead of "rendered" on the button, or wrap the button in i.e. an outputPanel and update this component instead. Problem is that you can't update a component with ajax that is not in the componenttree. - Jaqen H'ghar

1 Answers

2
votes

Your backing bean is basically fine, you just need to modify your front end page.

Just like @mabi, @rion18 and @Jaqen H'ghar said, you should:

  1. Remove booleanValue()
  2. Call remoteCommand with a onclick of a commandButton.
  3. Add update="print" on the p:remoteCommand.
  4. Use disabled instead of rendered.(which I use display here.)

So your front end will looks like:

<p:commandButton value="btn-search" styleClass="btn btn-primary" />
<p:commandButton value="remote" onclick="consultaValor()"/>
<p:remoteCommand actionListener="#{searchBean.addMarker()}"
                         name="consultaValor" 
                         update="print"/>
<p:commandButton id="print" value="Imprimir" styleClass="btn btn-primary" style="display:#{searchBean.print?'inline':'none'}" >

</p:commandButton>

Please note that

  1. I removed something in your code because I didn't know what do they mean in your code (like bandeira1,bandeira2,bandeira1Value,bandeira2Value,origemInfo,addressInfo...), you should add them back if you use the code I post here.
  2. I added a p:commandButton so that the p:remoteCommand is called. Make sure the remoteCommand is called if you want to remove the button I added.