tags:

views:

543

answers:

1

I have one parent page with a parentManagedBean (attached to Session Scope). On click of a button on this parent page, one popup comes which has a childManagedBean (attached to Request scope).

Now ChildManagedBean holds a reference to parentManaged bean through JSF's managed property facility. On this popup window, user selects some option which populates a large value object. I use the managed property of childManagedBean to set the values from this large object to that of parentManagedBean.

Problem is - The parent page shows a link, on click of which a popup comes, on selection of the popup, the popup disappears and set the values to the parentManaged bean. So far so good, but the newly set values need to appear on the parent page. This is where I am stuck. How to programmatically render the master page/render page when I am at the child managed bean? Is there a way I can get handle of the parent page and refresh it?

Note: I'm using JSF 1.1

EDIT-

After following the solution of "resubmit-ing the form" from javascript, I am seeing that the old form is getting resubmitting which overwrites all of my changed values.

EDIT-- What I find now is - if I issue a GET request, meaning, after the child window is closed, if I go to the main window and just press enter on the address again (which issues an GET request I believe), the newer values - updated values are coming back. So the point here is - how to issue a get request using javascript or is there any better way of doing this through JSF ?

+2  A: 

I had some similar case, and I triggered a refresh of the parent page with javascript.

Child

When the user clicked "save" in the popup, the action is submitted to the child with POST, which updates the parent bean, and then redisplay the child page with some javascript:

window.opener.doRefresh();
window.close();

This gave the illusion that when the user click on "save", the popup is closed directly. You can maybe use a similar trick in your case.

Parent

function doRefresh()
{
    if(document.forms[0].onsubmit)
    {
        document.forms[0].submit();
    }
}

function openChild()
{
     window.open("path_to_child.jsf","_blank","");
     return false;
}

If I remember well, I couldn't use location.reload to refresh the page. Either because reload may resubmit an old form, or because it issues a GET request which JSF doesn't like that much. So I was submitting the form programmaticaly. This essentially achieves the same.

This solution was not a masterpiece of elegance, but well, it worked for me :)

ewernli
Be careful with `document.forms[0]`. Rather prefer `document.formname` since a document can have more than one form.
BalusC
Thank you so much for your reply.I tried the solution as explained by you. Unfortunately, I am seeing that document.forms['name'].submit() is actually submitting the old form, so whatever values I updated from the child page and getting overwritten. Is there any other technique?
Shamik
Try then with `window.location.reload`, I think it makes a GET request. Otherwise you could try with a 2nd form (with no control inside) meant only for the refresh. When the 2nd form is POSTed, no data are sent, so it should not override the updated data. But that's really hackish and I don't even know if it works.
ewernli
I tried with the reload before.. but did not work. Reload actually asks whether we want to submit the data again .. since its a POST request, so IE understands that its not re-entrant. I will try the second way that you mentioned. But yes you are right, I am not getting a good feeling about it and sounds like a hack.
Shamik
@ewernli, Finally it worked with the empty form hack. It was a good experience for me though it looks like hack.. I am slowly started to thinking that JSF 1.1 without any custom component library like Richfaces or so, is very hard to create a complex UI.
Shamik
@Shamik Glad to hear that it worked :) I like the component-based model of JSF, but it's indeed sometimes a bit complicated. Especially the lack of support of GET and the fact that we can't easily implement redirect-after-post pattern (but I haven't been using JSF recently, maybe it improved)
ewernli
GET support is certainly improved in JSF 2.0. JSF 1.1 is already almost 6 years old again. Thus heavily outdated. Using RichFaces and consorts will indeed greatly ease all the work since it ships with almost any component you'd like to use in an average webapp.
BalusC