0

I am unable to resolve this null value. I have 2 pages in JSF. Page one has a datatable and the second page has configure. So I need when a user select a particular row in page one should be directed to page two. The value of selected row should be available on the second (which is has null) page and I don't want to use SessionScope in my managed bean. Here is my first page

 <h:form id="form1">
                        <p:dataTable rowKey="#{item.id}"  paginator="true" 
                                     rows="8"  emptyMessage="No users !" 
                                     editable="true"  widgetVar="idGrid"
                                     id="idGrid" value="#{bk.allusers}" var="item" >
                              <p:column sortBy="#{item.id}"  style="width: 10%;" >
                                <f:facet name="header">
                                    <h:outputText value="Ref Num"/>
                                </f:facet>
                                <h:outputText value="#{item.id}"/>
                            </p:column>
                            <p:column style="width: 30%;" filterBy="#{item.user_name}" styleClass="ct" >
                                <f:facet name="header">
                                    <h:outputText value="User Name"/>
                                </f:facet>
                                <h:outputText value="#{item.user_name} "/> 
                            </p:column>

                           <p:column headerText="Configure User" style="width: 30%;" styleClass="ct">  
                                <p:commandButton icon="ui-icon-plus"  id="config_user" value="Configure(s)" action="#{bk.edit}">
                                    <f:setPropertyActionListener target="#{bk.selected_user}" value="#{item}" />
                                </p:commandButton>
                            </p:column> 

                        </p:dataTable>


                    </h:form>

and here is my second page

<p:panelGrid>
    <h:outputLabel value="User Name"/>
    <h:outputLabel #{bk.selected_user.user_name}/><!--this is now blank on second page-->

</p:panelGrid>

and my managed bean

@ManagedBean(name = "bk")
@ViewScoped
public class UserManagedBean implements Serializable{ {


private User selected_user=new User();//getter setteer
public List<User> getAllUsers()
{

  return UserDAO.getUSers();//from db
}

public String edit()
{
        return "/SecondPage?faces-redirect=true";
}

************Model Class***********

User {
private String name,user_name;//getter setter
long id;//getter setter
}
  • ViewScoped is bound to the view you should use SessionScope – Simon Martinelli Mar 23 '20 at 10:02
  • @SimonMartinelli is it a must I use SeccionScope –  Mar 23 '20 at 10:03
  • View Scope only works for the same page. But you could create a page that shows the table and if one selects a row display the detail. – Simon Martinelli Mar 23 '20 at 10:05
  • @SimonMartinelli the reason am using ViewScoped is because my Object of List is not getting destroy after i leave and navigate to another page and come back to the same page again –  Mar 23 '20 at 10:07
  • That can be done with SessionScope – Simon Martinelli Mar 23 '20 at 10:08
  • @SimonMartinelli how can I prevent cache of object in session based bean. I need when I leave that page the object is completely destroyed.That the reason am forced to use ViewScope –  Mar 23 '20 at 10:11
  • @BalusC so instead of p:commandButton I use CommandLink? –  Mar 23 '20 at 10:13
  • I think [@ConversationScoped](https://stackoverflow.com/questions/7788430/how-does-jsf-2-conversationscope-work) is the right Scope for you – fuggerjaki61 Mar 23 '20 at 10:27
  • And in Apache DeltaSpike there are intermediate scopes, intermediate between view and session. E.g. viewAccessScoped... Seriously useful! – Kukeltje Mar 23 '20 at 11:26
  • @BalusC I cant relate that link to my problem,kindly assist me on that completely stuck –  Mar 23 '20 at 11:40

0 Answers0