Home > DeveloperSection > Forums > How to retrieve session object in jsf view
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    November-01-2014 12:09 AM

 ASP.Net Session  Session Variable 
Ratings:


 1 Reply(s)
 737  View(s)
Rate this:

I have a RequestController(@ManagedBean and @ViewScoped) it is view scoped because we are using some ajax calls.

I have a dataTable with result and each result with a button

<p:commandButton action="#{requestController.requestDetail()}" icon="ui-icon-search" title="Detalhes">

     <f:setPropertyActionListener target="#{requestController.backing.selectedRequestVO}" value="#{order}" />

</p:commandButton>


This method is receiving the selected object of my dataTable and is set on the session, it is working, the problem is that I don't know how to get this session object from my view.

public void requestDetail() throws IOException {
        FacesContext context = FacesContext.getCurrentInstance();
    context.getExternalContext().getSessionMap().put("requestDetail",backing.selectedRequestVO);context.getExternalContext().redirect(context.getExternalContext().getRequestContextPath() + "/views/request/detail.html");
    }

I need to access it from my view because this object has the request details.



Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    November-01-2014 12:13 AM

It's just available by the attribute name which you specified yourself.

#{requestDetail}

Note that this is not the correct approach. You should have another session scoped managed bean which you inject as @ManagedProperty in the view scoped managed bean and then set the request detail as its property.

@ManagedBean
@ViewScoped
public class RequestController {

    @ManagedProperty("#{requestDetail}")
    private RequestDetail requestDetail;

    public String requestDetail() {
        requestDetail.setSelectedRequestVO(backing.getSelectedRequestVO());
        return "/views/request/detail.html?faces-redirect=true";
    }     

    // ...
}

with

@ManagedBean
@SessionScoped
public class RequestDetail {

    private RequestVO selectedRequestVO;

    // ...
}

which you then access as follows

Don't want to miss updates? Please click the below button!

Follow MindStick