ICEFaces page refresh - icefaces

I have a page where a user enters data and hits a "save" button.
The data gets saved to the db, and I want the page to refrsh itself to reflect the new data in the db.
I am using a managed bean, how do i get the page to refresh on its own?

There are two options which come to my mind:
Make use of JSF navigation rules
Use the rendered attributes
ad 1)
Define a page to which you'll navigate to after hitting "save".
For doing that, your action for actually saving the data to DB will go into the method defined as an actionListener or, if you want to make your next page depending on the outcome of the saving process, as action.
Navigation rules will be defined in faces-config.xml
If no navigation rule matches a given action, the current page will be redisplayed (although from the experience i made this refresh is different to a common HTML refresh).
ad 2)
If you've some lists or a data table on the same page set to a model in your bean, changes will automatically be displayed except you're using the immediate keyword set to true on your save button.
Additionally you might consider a panel with a content of your choice which has the rendered property set to a boolean in your bean, which will be triggered within the saving process and therefore let the content be displayed only after hitting save.

You can make use of the AJAX push feature of IceFaces. This initializes a re-render of the client.
The recommended (and easiest) way is to use the SessionRender API in your managed bean:
SessionRenderer.addCurrentSession("myGroup");
SessionRenderer.render("myGroup");
Consult the Icefaces developers guide for more information.

It depends on how you do it.
When you click the button, the JSF life-cycle is kicked off, if you kick off the save to the database within the button's action, whatever values you update in your manage bean should be reflected in the page automagically. The JSF lifecycle does this for you automatically and icefaces can do it using the AJAX bridge so you won't be required to do a page reload.
If you're doing work asynchronously, you'll need to use the Push API icefaces provides you. To kick off the life-cycle from the server end.

Related

Calling pop up from different pages .jsf

Does anyone know how I can get the same pop up via a button located on different pages (.JSF)?
That is, there is a button "add file" which then opens a pop up with a form where the user adds information about the file. As the pop up is always the same I was thinking of using declarative components. However, I do not understand how.
You can create a taskflow which will contain your page with upload form, and then reuse it on other pages as af:region. Check out this great post with an example how to do it.
I might think about three different ways to achieve this:
1) As #Pregrad said, you can create a Bounded Task Flow and expose this BTF as region (or dynamic region) in every page you need it as a popUp window (recommended if you are using transactions)
2) You can create page templates, put the af:popUp in them and apply the template for each page (recommended if you already have templates, and you need the popUp for each page on your application)
3) You can put the af:popUp component on each page you need it, and then call it programmatically. This approach may be would give you more control on the popUp behaviour but would require you to handle it manually.
The approach you should use does really depend on your needs.

Internal state in backbonejs application

I am creating an application and trying to figure out best way to deal with navigation in it. User can choose different view settings (which content to show and options to filter it). Part of settings is stored in backend in user preferences model. Another part is stored in url and managed by router. But there is more settings I want to keep. The reason: I want to be able to refresh content therefore I need to keep settings somewhere, not update content on user actions and forget how I came to this state. My question is: what is the best place for such settings? Collection object? View object? My own controller?
P.S. to make it more clear, I'm working on rss reader application. And I want, for example, to show last week posts from certain feeds which are starred etc.
Save it in the URL. Thats the only place you can really rely on. If you need more then routes use query parameter like in a classic web application and use them in the view.

Why no Zend_Layout helper or codebehind? And best way to

I was just wondering why no code-behind or helpers were made to work with layouts? I have stuff I want to display in my layouts without having to set it up in a placeholder for every single controller.
I was also wanted to know what is the best way to persist a display-once "success-message" across many pages. For example, a user fills out a form and when it is submitted correctly they are redirected to another page. I want the user to see a success message on that other page. Is there some sort of provision in Zend Framework that makes this easier?
Well for the messages you can use the Flash Messenger helper
As far as setting up the place holders you could use a base controller and set these up in the init method overriding on descendents when necessary.

Setting active page when Zend_Navigation is cached?

Update - Please see update below.
I'm attempting to improve the performance of our ZF based CMS, and am trying out caching the Zend_Navigation object I create with the menu structure. Caching the object means I can't set the current page to active, or I'll have a copy of the menu in the cache for every page.
To allow caching of the structure, regardless of current page, I've moved highlighting of the current page in the menu to jQuery, which is working well. Then I noticed that the Breadcrumb_Helper (which uses the same Zend_Navigation object as the menu) wasn't displaying anything - obviously because I haven't got a page set to active.
Given I know the id of the page, is there a way to get inside the Zend_Navigation object to set that particular one to active?
Ideally I'd like to do something like:
$nav->findOneBy("id", $currentPageId)->setActive(true);
But there doesn't seem to be a way to access the pages in the object like this. Looking at the code, using findOneBy to get the current page, then removePage to remove it, then setting the collected one to active, and using addPage to put the collected, updated one back in might be an option, but rather convoluted.
The other option is just to cache the array I use to construct the Zend_Navigation object, which would be easier to set the current page to active, after getting the base array from the cache.
(I should point out that all the pages in the cms just have urls like /privacy, /about-us, and are routed to a default frontend module, controller and action, so there is no controllrt/action in the url to allow ZF to work out where it is.)
Update:
Ahem.... Seems like the code I suggested did actually work, and can actually be done slightly more simply using the magic finder methods...:
$nav->findOneById($currentPageId)->setActive(true);
As noted above, this does indeed work:
$nav->findOneById($currentPageId)->setActive(true);

Pattern for Spring-MVC stateful interaction

Today I was doing this thing with Spring:
Have a page with a form and a chance to choose one item related to the form.
If you push "Choose item" the app will save somehow what you typed in the form, go to another page, let you choose the thing.
When you are back to the form it's filled with what you wrote before going to the other page, plus the item chosen.
Seems easy, but you have to take into account that for some stupid reason the user could open the page where you choose the item (maybe because of a bookmark, or because he pressed the back button 10 times to play). You know what I mean. I tried many ways, mainly based on HttpSession... I don't like any of those. None of them seems elegant. I was even thinking of using a hidden form in the other page, but given that it is not unique to this "flow" (I mean you can go to the item choose page from others as well), I will have to worry about conflicts and so on.
So what would be the preferred way for you? Suggestions?
Go around the problem instead of solving it. You can use a modal javascript div popup where the user can pick the item she wants. The contents of this div can be loaded via ajax (separate Spring MVC controller called with Http GET). Once the selection has been made, you close the popup (hide the div) and copy the value into the original form. Done.
No need to store the state anywhere.
I suggest Spring Web Flow.
Spring Web Flow compliments the Spring MVC.
Here is link to Spring Web Flow Demo