0

I am struggling to get commandLink to work in a dataTable, I tried both h:commandLink and p:commandLink but they are both not working, they are either not executable or keep invoking the same page returning an empty table. I also tried request scope and session scope but none of them seems to work. This is my jsf page code

<h:form>
        <p:dataTable value="#{forSaleController.forSalePropList}" var="bk" >
            <p:column>
                <f:facet name="header">
                    <h:outputText value="ID"/>
                </f:facet>         
                <h:outputText value="#{bk.pid}" id="pId" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Type"/>
                </f:facet>
                <h:outputText value="#{bk.propertyType}"/>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Location"/>
                </f:facet>
                <h:outputText value="#{bk.location}"/>
            </p:column>
            <p:column>      
                <f:facet name="header">
                    <h:outputText value="Action"/>
                </f:facet>
                <p:commandLink process="@this" value="View Details" action="#{forSaleController.fsDetails(2)}"></p:commandLink>
            </p:column>
        </p:dataTable>
    </h:form>

And this is the code of my bean

 public String fsDetails(Long pId){    
    forsale = forSalePropEJB.searchForSale(pId);       
    returnDetails();       
    return "salePropertyDetails.xhtml";
}

And this is my code from EJB class

public ForSale searchForSale(Long pId){
    TypedQuery<ForSale> query = em.createNamedQuery("searchForSaleQuery",ForSale.class);
    query.setParameter("pId", pId);
    return query.getSingleResult();
}

I have been reading some solutions from other posts but it does not seem to be a solution for me! I would very appreciate it if someone can give me some idea on how to fix this, thank you so much

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • See https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value and https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes – Jasper de Vries Oct 21 '21 at 15:24
  • @JasperdeVries Heyy, thank you for the suggestion, I did see and try some of these solutions but it still produces the same error(not invoke the right thing) for me – Hoan Nguyen Oct 21 '21 at 15:48
  • .. and https://stackoverflow.com/questions/8459903/creating-master-detail-pages-for-entities-how-to-link-them-and-which-bean-scope – Jasper de Vries Oct 21 '21 at 16:07
  • @JasperdeVries I think I got things correct from that post, I just did a little test with my code, when I click the commandLink on the webPage, it actually goes to the method called getForSalePropList and I have no idea why its doing that – Hoan Nguyen Oct 21 '21 at 16:28

0 Answers0