p:tree selection set by bean not tracked in jsf site - ajax

When I use a normal p:tree like
<p:dialog>
<p:form>
<p:tree value="aGetterMethod" selection="getAndSetMethods"/>
</p:form>
</p:dialog>
And I select a parent node (so all children are also selected), and submit the form so save the changes to the backing bean, everything is fine (all selections are saved)
But when I reopen the dialog and try to unselect one child, it removes every selection made previously in this root. I figured out that the implicit set selections fur the children are not recognized as"selected" and therefore it tries to remove a nonnexistant selection which results in no selection.
Does anyone else fight with this issue?
I just want to get and set the selected nodes correctly when getting and selecting them.

Related

Force re-evaluation of rendered property on JSF component

In my application, I have a phaselistener that can conditionally hide a component by setting UIComponent.setRendered(false) .
On that page, I have ajax tabs, with tab one able to influence the display of the other. So, I go to a tab, change something, come back, but there I find that the component still remembers it's unrendered state.
I guess not doing ajax for my tab navigation would solve this, but is there any other way that I can somehow force the component tree to be build up as if it was the first time?

Primefaces nested p:dialog DOM node duplicates

I have a list element detail form opening inside a p:dialog. This p:dialog in turn shows another list. From this list, I can open any of its element's details inside a nested p:dialog.
The problem is: every time I open a dialog, a new set of ids for the elements in the nested dialog is generated, with the same value.
What I end up with in my DOM when I try to select a particular id from the nested dialog, such as $('#manageIssue\\:newEventComment');, is an array of elements with the same id.
I have determined there is one copy per each time I open a dialog, plus another one which is there from the beginning.
The nested dialog DOM nodes are not being destroyed when the nested dialog is closed, and a fresh set with overlapping ids is being generated every time a dialog is opened.
This question is related to primefaces update attribute not working on modal dialog opened from modal dialog.
(I solved the original problem by removing the prependId attribute from the form, but this one remained.)
Because this problem is a little difficult to reproduce, I have built a MCVE. All the stuff (backing beans, views, pom.xml, etc.) adds up to ~500 lines of code, so I have shared it on a github repo: https://github.com/elcodedocle/testt
The question here boils down to:
How can I make this MCVE work (i.e. add events with comments to an issue from a list of issues of a commission from a list of commissions), without this line:
https://github.com/elcodedocle/testt/blob/fbfeb7fca474c66c202c92e469ca185c6bf569c2/src/main/webapp/views/widgets/issue_detail_edit.xhtml#L21
?
This problem is caused by nested <p:dialog>.
<p:dialog id="commissionDetail">
...
<p:dialog id="issueDetail">
...
</p:dialog>
</p:dialog>
This is not allowed. The technical reason is, the HTML DOM element representing the dialog is by JavaScript relocated to the very end of <body> in order to ensure best cross browser compatibility as to calculating the z-index and offset. Then, when you ajax-update the dialog, the existing dialog couldn't be found in its original parent element in the DOM, so simply a new one is added to DOM (which then get relocated to end of body again, etc).
You really need to restructure your templates so you ultimately end up like
<p:dialog id="commissionDetail">
...
</p:dialog>
<p:dialog id="issueDetail">
...
</p:dialog>

extjs Save component view state before removing it from parent component

Let me explain the my scenario. I am using ExtJS5. I have got a view component (let us name is viewOne) contain two combo boxes, button search and some action button, on click of search button the grid is populated. This viewOne is in a parent view component (viewParent). I need to load a second view (viewTwo) on selecting some grid row and clicking some action button a new view is loaded (viewTwo) in the parentView. When I come back from viewTwo to viewOne I need old values of combo boxes to re perform the search.
Currently I am storing the values of combo boxes in a store and set then when the after view render and call search. We have discarded card layout for this implementation.
I wanted to know how this can be done via Ext.state , I cannot find any example on the same that is close solution to my problem. Any other way of doing this ?
State seems reasonable for that. First of all you must set StateProvider (by calling Ext.state.Manager.setProvider) to instance of class which extends Ext.state.Provider.
Then state should work for you. Only thing that you must remember is to set stateful property to true and set stateId of the component.
Usually you don't need to save state by yourself. All built-in stateful components have defined state events. When such state event occur (eg. expand on panel) then state is saved automatically. You can customize state events by calling addStateEvents in initComponent.
To provide custom component state you should override applyState and getState methods. When you combine it with addStateEvents you have all what you need.
Example: http://jsfiddle.net/48jw81da/16/

To check the record change on close button with immediate set to true

I have a JSF - xhtml page with New, Save, Delete , Print , Close command buttons.
We have applied few validations on the input controls and those are working well on delete and save. For close button we have set "immediate=true" to disallow validation which are also working fine.
But we also want to notify user if he changes the value in any of the input control and then chooses to close the form, that "he has left with some unsaved changes" , since the close button has been set for immediate true, it does not recognizes the changes in the values also valuechangeListerner not works on close if immediate = true is set for it.
Like to know the approach to be taken in this case....
Thanks
With immediate="true" on the button, the action is indeed invoked during apply request values phase and all the remaining phases are skipped. That's also the sole point of this attribute: process (decode, validate, update and invoke) the component immediately during apply request values phase.
All inputs which do not have immediate="true" are ignored anyway. Only inputs which do have immediate="true" are also processed, but this happens also during apply request values phase. Why should the remaining phases be invoked if everything has already taken place in the apply request values phase?
In the Debug JSF lifecycle article you can find the following summary which should enlighten when to (not) use the immediate"true"
Please refer Trying to understand immediate="true" skipping inputs when it shouldn't

How to design this page in razor world

In MVC-3/Razor, I need to create a page which will have five set of controls. Each set will have a drop-down and a text box. User will select an option from drop-down and then provide some feedback on text box.
When the view is shown very first time, I only have to enable controls in first set. Whereas all controls in 4 other sets should be disabled. Once user perform action in first set of controls (select optino from drop-down and enter in text box), the second set should become enable now, whereas other set of controls should still be disbaled. The data shown in this second drop-down is dependent upon what user has selected in first drop-down. Once user complete action in this second set, the data in third drop-down will depend upon whatever user selected in first and second drop-down etc.
I am a web-form aspx developer and not sure what will be the best way of designing this in MVC-razor world (because there is not view state etc).
Step 1)
What needs to be clarified is what will cause the other “sets” to be enabled?
Is it after the user has selected an item in the dropdown
OR
Is it after they have entered some text in the textbox?
What also needs to be clarified is if you have a dropdown AND a textbox are they both enabled at the same time or is the textbox only enabled after you’ve selected an item in the dropdown?
Once you’ve got that figured out, move on to the next step.
Step 2)
Do the users need to visually see the 4 sets from the beginning (disabling the 3 other sets) or can you simply show the other sets (on the fly) once the previous one has been successfully filled?
Depending on the answers, this may vary your approach.
As for me, the way I’d do it is simply have/show one set that loads at the beginning.
Once the user has selected an item from the dropdown, I would make an AJAX call passing along the selected item and get back a list of values for the second dropdown.
Then, using jQuery, I would duplicate the row (or div) of the first set all while changing the values in the second dropdown box.
Repeat process for when an item is selected in the second dropdown.
But wait! There’s more!!!
Let’s assume you’ve reached the third set. What if the user decides to change the value in the first dropdown? What are your requirements if that happens? Should you remove all other sets and start back at square one? I guess so…
Since we are not aware of the full set of specs for your tasks, we can only assume stuff and this may (or not) be the best path to take.
Duplicating a row (or a div) using jQuery is quite fun and performance wise, it’s nice.
Keep in mind, you will have to give a different ID to your controls (dropdown + textbox) so when you submit the form, you could use the FormCollection to get those dynamically generated controls.

Resources