0

I'm trying to use a h:commandLink which is dynamically added to each row of a table. When the link "view details" is clicked, the user should be redirected to the page "View.xhtml" where the user will be able to see additional details. However, what's happening is that when the link is clicked it seems to be just refreshing the page and removing the previous list results. I've read around quite a bit and tried a bunch of different things to no avail.

Additionally, the link works perfectly fine when hardcoded and placed outside of the table.

List.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
    <title>List of Properties For Rent</title>
</h:head>
<h:body>
    <h1>List of Properties For Rent</h1>
    <hr/>
    <h:dataTable value="#{propertiesForRentController.propertiesForRentList}" var="RL" border="1">
        <h:column>
            <f:facet name="header">
                <h:outputText value="ID"/>
            </f:facet>
            <h:outputText value="#{RL.id}"/>
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="Type"/>
            </f:facet>
            <h:outputText value="#{RL.propertyType}"/>
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="Location"/>
            </f:facet>
            <h:outputText value="#{RL.address}"/>
        </h:column>
        
        <h:column>
            <f:facet name="header">
                <h:outputText value="Action"/>
            </f:facet>
            <h:form>
                <h:commandLink action="#{propertiesForRentController.showDetailsPropertiesForRent(RL)}" value="View Details" />
            </h:form>
        </h:column>     
    </h:dataTable>
    
    <p>Total Properties For Rent: #{fn:length(propertiesForRentController.propertiesForRentList)}</p>
    
    <hr/>
    <a href="index.xhtml">Main page</a> | 
</h:body>
</html>

PropertiesForRentController:

package Default;

import java.io.Serializable;
import java.util.*;
import javax.inject.Named;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;

@ManagedBean
@Named(value = "propertiesForRentController")
@SessionScoped
public class PropertiesForRentController implements Serializable
{

    @EJB
    private PropertiesForRentEJB propertiesForRentEJB;
    private PropertiesForRent propertiesForRentSelected = new PropertiesForRent();
    private PropertiesForRent propertiesForRent = new PropertiesForRent();
    private PropertiesForRent propertiesForRent2 = new PropertiesForRent();
    private List<PropertiesForRent> propertiesForRentList = new ArrayList<PropertiesForRent>();
    
    public String showDetailsPropertiesForRent(PropertiesForRent propertiesForRent) 
    {
        this.propertiesForRent2 = propertiesForRent;
        return "/propertiesForRent/View.xhtml";
    }
    
    public String doCreatePropertiesForRent() 
    {
        propertiesForRent = propertiesForRentEJB.createPropertyForRent(propertiesForRent);
        propertiesForRentList = propertiesForRentEJB.findPropertiesForRent();
        return "/propertiesForRent/List.xhtml";
    } 
    
    public String doListPropertiesForRent() 
    {
        propertiesForRentList = propertiesForRentEJB.findPropertiesForRent();
        return "/propertiesForRent/List.xhtml";
    }
    
    public String doDeletePropertiesForRent(Long ID)
    {
        this.propertiesForRentSelected = propertiesForRentEJB.findPropertiesForRentByID(ID);
        propertiesForRentEJB.deletePropertiesForRentByID(ID);
        return "/propertiesForRent/List.xhtml";
    }

    public PropertiesForRent getPropertiesForRent()
    {
        return propertiesForRent;
    }

    public void setPropertiesForRent(PropertiesForRent propertiesForRent)
    {
        this.propertiesForRent = propertiesForRent;
    }

    public List<PropertiesForRent> getPropertiesForRentList()
    {
        return propertiesForRentList;
    }

    public void setPropertiesForRentList(List<PropertiesForRent> propertiesForRentList)
    {
        this.propertiesForRentList = propertiesForRentList;
    }
}
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
Silky
  • 13
  • 4

0 Answers0