0

Below are the files I have.

manageStaff.xhtml

<h:dataTable var="c" value="#{newStaffMemberServiceBean.newStaffMemberDataBeanList}"
             styleClass="order-table"
             headerClass="order-table-header"
             rowClasses="order-table-odd-row,order-table-even-row"
             border="1" id="staffListDataTable" width="100%">

    <h:column>
        <f:facet name="header">
            Staff Member Name
    </f:facet>
        <h:form>
            <h:commandLink action="viewStaffMemberProfileData" value="#{c.firstName}">
                <f:setPropertyActionListener target="#{newStaffMemberServiceBean.userId}" value="XXXYYYZZZZ"/>
            </h:commandLink>
        </h:form>
    </h:column>
</h:dataTable>

viewStaffMemberProfileData.xhtml

 My Name is -<h:outputText value="#{newStaffMemberServiceBean.userId}" />-

NewStaffMemberServiceBean.java

@ManagedBean(name = "newStaffMemberServiceBean")
//@RequestScoped
@ViewScoped
//@SessionScoped
public class NewStaffMemberServiceBean {

    private String userId;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

In output what I get is in below format

Staff Member Name
++++++++++++++++++

Name 1
Name 2
Name 3
.
.
.
.

On Clicking Name 1, I get re-directed to viewStaffMemberProfileData.xhtml.

BUT problems are

  1. To get re-directed on viewStaffMemberProfileData.xhtml page, I have to click link (Name 1, Name 2, etc) twice :(

  2. When I get re-directed to viewStaffMemberProfileData.xhtml I only see output as

    My Name is --

    What I want is My Name is -XXXYYYZZZZ-.

Suggest me where I am going wrong.

NOTE

I have all beans in ViewScope.

Update 1

@prajeeshkumar

Getter setter are as below

    public List<NewStaffMemberDataBean> getNewStaffMemberDataBeanList() {
    return newStaffMemberDataBeanList;
    }

    public void setNewStaffMemberDataBeanList(List<NewStaffMemberDataBean> newStaffMemberDataBeanList) {
    this.newStaffMemberDataBeanList = newStaffMemberDataBeanList;
    }
Raidri
  • 17,258
  • 9
  • 62
  • 65
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

2 Answers2

2

The reason for this behavior is the view scope of the newStaffMemberServiceBean , its being destroyed and created again... so the value is being nullified... here an alternative solution:

haven't tried this one, But worth trying

change

<h:commandLink action="viewStaffMemberProfileData" value="#{c.firstName}">
     <f:setPropertyActionListener target="#{newStaffMemberServiceBean.userId}" value="XXXYYYZZZZ"/>
</h:commandLink>

into

<h:link value="#{c.firstName}" outcome="nameOfXhtmlGoesHere">
     <f:param name="id" value="XXXYYYZZZZ" />
</h:link>

and in viewStaffMemberProfileData.xhtml

add this before the <h:head>

<f:metadata>
    <f:viewParam name="id" value="#{newStaffMemberServiceBean.userId}" />
</f:metadata>

you can also add <f:event type="preRenderView" listener="#{newStaffMemberServiceBean.init}" /> to the f:metadata in order to do some init...

based on this BalusC great article - Communication in JSF 2.0

OR

you can turn the scope of newStaffMemberServiceBean into SessionScope...

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • this is working ***BUT*** I am getting `?id=XXXYYYZZZZ` in URL which is ***BAD*** :( Any OTHER solution? – Fahim Parkar Mar 12 '12 at 07:38
  • Also any idea why on first click same page is shown & on second click the page get re-directed to the page requested?? – Fahim Parkar Mar 12 '12 at 08:24
  • I think I will have to use `Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();` here. Your thoughts on it?? – Fahim Parkar Mar 12 '12 at 08:32
  • haven't worked with Flash , but... http://mkblog.exadel.com/2010/07/learning-jsf2-using-flash-scope/ looks like a good place to start – Daniel Mar 12 '12 at 08:38
0

If you have newStaffMemberServiceBean in view scope, then when you are going to a different page (view) will that bean be available in that scope ? I mean manageStaff.xhtml will have one instance and viewStaffMemberProfileData.xhtml will have another one. Your solution here will be using the session scope or using the h:link or h:outputLink

prajeesh kumar
  • 1,916
  • 1
  • 17
  • 17