-2

I use primefaces version 6.2 in combination with jsf and trinidaad. In the project I have a table with each row containing a button to redirect this page to another page based on selected row. jsf and trindad commandLink and commandButton does the job but primefaces commandLink and command button doesn't.

What I have already done:

  1. Changed the type of button to type="button"
  2. Added immediate="true"
  3. I used actionListener="#{coolingBean.view(row)}" instead of action="#{coolingBean.view}".

Anyone know why and what should I change?

<p:column id="viewButtonColumn" exportable="false" style="text-align: center" >
            <tr:commandLink textAndAccessKey="&amp;view " id="viewButton" action="#{coolingBean.view}" styleClass="commandLinkMediumSmallFont" onclick="PF('bui').show()">
                <tr:image source="/imgs/view.png" styleClass="commandLinkImageWithText"/>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </tr:commandLink>
</p:column>

<p:column id="viewButtonColumn1" exportable="false" style="text-align: center" >
            <h:commandLink  textAndAccessKey="&amp;view " id="viewButton1" action="#{coolingBean.view}" styleClass="ui-priority-primary" onclick="PF('bui').show()">
                <i class="fa fa-search" ></i>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </h:commandLink>
</p:column>

<p:column id="viewButtonColumn2" exportable="false" style="text-align: center" >
            <p:commandLink value="View" id="commandLinkView" action="#{coolingBean.view}" styleClass="ui-priority-primary" onclick="PF('bui').show()">
                <i class="fa fa-search" ></i>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </p:commandLink>
</p:column>

<p:column id="viewButtonColumn3" exportable="false" style="text-align: center" >
            <p:commandButton id="viewButton2" value="View" action="#{coolingBean.view}" icon="fa fa-search" immediate="true" type="button" onclick="PF('bui').show()">
               <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
               <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </p:commandButton>
</p:column>

Inside managed Bean

public String view(Row selectedRow) {
    if(criteria == null)
      criteria = new criteriaBean();

    criteria.setNummer(selectedRow.getNummber());
    searchBean.selectedId = selectedRow.getId();


 //FacesContext.getCurrentInstance().getExternalContext().dispatch("view.jsp");
    return view();
  }

  public String view(){

    return"view';
  }
Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
itro
  • 7,006
  • 27
  • 78
  • 121
  • So it works if you don't use trinidad in the page or the project? Or if you do something like this without a `p:datatable` and `{coolingBean.view` is called? Just the redirect not working? Amd why the `type='button'`? – Kukeltje Jan 21 '19 at 10:45
  • No it doesn't work at all. if i just use trinidad it works if i use primeface it doesn't work. I want remove trinidad from my page and just using primefaces but primefaces button and command link doesn't work. I just used type='button' to see if it makes diffrence. – itro Jan 21 '19 at 13:07
  • `type="button" is wrong, see the PF docs or stackoverflow. Better to create a real [mcve] without trinidad that fails. And remove the trinidad tag then since tags are for where the problem is and not what you use (and certainly not for what does work) – Kukeltje Jan 21 '19 at 16:11
  • I have removed trinidad totally from my page but still primeface doesn't work. Let me make myself clear. Originaly this project has been built up on trinidad. i have decided to change to primeface due to death of trinidad. this is the reason why i have to stick with trinidad in the project and slightly get rid of it. – itro Jan 22 '19 at 07:19
  • That part was already clear. I'am just helping you narrow down the problem. Does an `h:commandButton` work? And there were more questions im my comment. Please do **AND** change the code accordingly into an [mcve] – Kukeltje Jan 22 '19 at 08:05

1 Answers1

-1

This one actually helped me.

Basically adding one of the following did the trick for me:

  • Adding ajax="false" into the commandButton
  • Appending ?faces-redirect=true to the url ( e.g. return "view?faces-redirect=true';)
Stampler
  • 59
  • 5
  • Doesn't really *solve* the original question - rather, it circumvents the problem. In this particular case your solution works - but what happens when you actually need ajax? As suggested by @Kukeltje, your original question needs to be complemented with more code, because a number of things can cause the `commandButton` to not fire. – Adam Waldenberg Jan 30 '19 at 06:48