0
votes

I have a little critical scenario.

Consider 3 pages. Page1, Page2, Page3.

From Page1. One parameter come in QueryString named 'note'. It is having two values 'CreateNote' or 'UpdateNote'. On bases of those values, I am hide and show few contents on Page2.

Till here no problem.

Now from Page2 I need to navigate to Page3. On Page3 a back button. I tried to set note attribute on Back but still that's not setting these information and hence on Page2 null pointer accessption arise.


A few code as below

Page1 URL like

http://localhost:9095/Oscer/pages/UpdateNote.jsf?modified=NO&note=UpdateNote&docid=206&callFrom=prescribe

On Page2

It's handle using scriptlets like...

Set note object on backingbean constructor call.

<%
    String note = request.getParameter("note");
    if(note == null || note.equals("")){
        note = (String)request.getAttribute("note");
    }
    request.setAttribute("note",note);
%>

On Page3

Tried to handle on BackButton like,

if(note == null){
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Map<String,String> requestObj = facesContext.getExternalContext().getRequestParameterMap();
            if(requestObj != null){
                note = requestObj.get("note"); //Either of CreateNote or UpdateNote
            }
        }

        request.setAttribute("note", note);

Now when we navigate from Page3 to Page2 back though I set request.setAttribute("note", note); It gives NULL pointer exception cause of note on Page2 not set yet :(

I can't understand how to navigate in case like query string handeled jsp page??

2

2 Answers

0
votes

I did it... :)

What I did is...

While going from Page1 to Page2 on one of the backingBean let say sampleBackingBean set one variable. Initialize it's value by getting note from request Scope in default constructor of SampleBackingBean.

And on jsp Page2 Whatever show and hide content is there rendered using {sampleBackingBean.note}

Now everything is working fine... :)

0
votes

Instead of keeping the note attribute in request scope, you can keep it in Session scope while navigation from Page1 to Page2. On Page2 retrieve this attribute from session rather than query string (or request scope). So on Page3, even if back button is pressed, you code should work fine.