2
votes

I am trying to convert my JSF Application in which all managed beans are session scoped and i am converting them to request scoped and manually maintaining data using unique session ids as request parameters to write and read data from httpsession.

I am using primefaces datatables in my page and on selection of a row i am calling a listener function in my backing bean with p:ajax.

<p:ajax event="rowSelectRadio" listener="#{userB.onUnitSelect}" >
</p:ajax>

I have my sessionID with which i am acccessing my data in a hidden field in the form

<h:inputHidden id="SID" value="#{userB.sessionID}" />

I am trying to pass the above value when the above ajax event is fired. I tried the below two ways and im unable to access my SID value

<p:ajax event="rowSelectRadio" listener="#{userB.onUnitSelect}" >
    <f:param name="SID" value="#{userB.sessionID}" />
</p:ajax>

and

<p:ajax event="rowSelectRadio" listener="#{userB.onUnitSelect}" >
<f:setPropertyActionListener target="#{userB.sessionID}" value="1234" />
</p:ajax>

The ajax call is inside the primefaces datatable tags

<p:dataTable></p:dataTable>
1
Why don't you just put sessionID in a view scoped bean? Or, better, why don't you simply inject the session scoped bean in the request scoped bean? See also stackoverflow.com/q/7031885BalusC

1 Answers

3
votes

This is my first answer at stackoverflow. I know this is old question, but I want want share how I fixed this situation.

<f:attribute name="sid" value="#{userB.sessionID}" />
<p:ajax event="rowSelectRadio" listener="#{userB.onUnitSelect}" />

and in your onUnitSelect method

public void onUnitSelect(SelectEvent event) {

    String sid = (String) event.getComponent().getAttributes().get("sid");

   /* your logic */
}