h:inputText and h:outputText show different values for same (EL) field - jsf

I've got a very strange problem here. I have a rich:popupModal which is used to edit an entity. Some of the input fields on that modal use a validator. There is also some ajax going on which is used to update other fields on that modal. There is e.g. a 'Number of packages' field, a weight per package field and a total weight field. If you change the number of packages it will update the total weight field, etc.
Now when e.g. the user entered a value that is too high, the validation fails, an error message is shown. The user can either correct the values on the modal or press cancel.
When he cancels the entity is reset to the values it had before the edit (there were some ajax changes so I need to reset those). The modal closes and a table is showing the correct (reset) values for that entity.
Now the strange thing happens. When I edit another entity the modal is suddenly showing the old values for the previous entity (the ones that did not pass validation).
To debug this I was checking whether the correct instance of the commodity is used so I added h:outputText fields for some of the values and I am also showing the System hash of the entity on the modal.
I've got e.g.
<h:outputText value="#{backingBean.entity.description}"/> which prints 'Stuff 1'
and then
<h:inputText value="#{backingBean.entity.description}"/> which prints 'Stuff 3' (the first entity I've edited). WTH?
I've added getter and a dummy setter on the entity to return the System.identityHashCode. And h:outputText and h:inputText use indeed a different entity but how is that possible when the EL is #{backingBean.entity.hashId} in both cases?
I've used the richfaces a:log to see whether that shows any errors but it all looks okay.
I have tried to clear the modal on cancel (rerender it with no components in) but that didn't fix the problem either. I've tried it on both Chrome and Firefox. Both have the same problem.
What could be going on here?
My environment: JSF 2, Seam 2.3, RichFaces 4.3.3, JBoss EAP 6.1

Related

Incorrect view update after validation error

View looks like this:
form (can have only one checkbox selected)
----------------------------------------
checkbox_1 (on value change clears checkbox_1 and checkbox_2 values in the backing bean and updates form**. new checkbox_1value is set after all checkbox values are cleared)row_checkbox_1(rendered only ifcheckbox_1` is checked)
checkbox_2 (on value change clears checkbox_1 and checkbox_2 values in the backing bean and updates form**. new checkbox_2value is set after all checkbox values are cleared)row_checkbox_2(rendered only ifcheckbox_2` is checked)
saveButton (on click updates formand a separate messages component)
---------------------------------
Lets state checkbox_1 is selected meaning that row_checkbox_1 components is also visible. Also there are errors in row_checkbox_1 fields.
After saveButtonis pressed the errors are displayed.
Problem: pressing/checking checkbox_2 updates backing bean - checkbox_1 value field in the backing bean gets set to false (debugged and verified by looking at getter) and checkbox_2 value field is set to true. However view does not update correctly since checkbox_1 is rendered as checked while row_checkbox_1 is not rendered at all. Remember row_checkbox_1 is rendered only if checkbox_1 is true. checkbox_2 is rendered and checked as it should be and row_checkbox_2 fields are visible as it should be.
I'm doing all this in PrimeFaces 6.0
ajax attribute restValues="true" helped. Maybe someone could do an explanation why this situation occurs? Would gladly give answer point to them!

JSF Validation fails for no (obvious) reason

I have a couple of mandatory PrimeFaces 5.2 <p:autoComplete> components in my JSF 2.2 page tied to a #ViewScoped bean. The page consists of the following mandatory elements:
Employee (p:autoComplete)
Order (p:autoComplete)
Location (p:autoComplete)
WorkingTime (p:inputText)
Description (p:inputTextArea)
DaysOfBookkeeping (custom component for a multi date picker).
When I complete the form and submit the record immediately, everything works fine. When I leave the form alone for a couple of minutes before hitting the submit button, I get validation errors for "Order" and "Location", even though the values in the form are still present and the HTTP-POST is exactly the same as during the successful submit. In the HTTP-Post I can see, that the values for "Order" and "Location" are set, just like during the succesful HTTP-POST. I never get any validation errors for "Employee", even there's no difference between the three p:autoComplete elements.
javax.faces.partial.ajax=true&javax.faces.source=NewTimesheetForm%3AsH_submit&javax.faces.partial.execute
=%40all&javax.faces.partial.render=NewTimesheetForm%3Agrowl&NewTimesheetForm%3AsH_submit=NewTimesheetForm
%3AsH_submit&NewTimesheetForm=NewTimesheetForm&NewTimesheetForm%3AMain_employeeAutoComplete_input=Sebastian
+Lang&NewTimesheetForm%3AMain_employeeAutoComplete_hinput=df27af76-9937-4e28-bee8-66a000f0ce9c&NewTimesheetForm
%3AMain_dateArray_input=&NewTimesheetForm%3AMain_dateArray_datepicker=&NewTimesheetForm%3AMain_wspOrderAutoComplete_input
=Development+(Kolibri)& NewTimesheetForm%3AMain_wspOrderAutoComplete_hinput=21c2259e-08bf-4a98-b718-8be67dba3b55&NewTimesheetForm%3AMain_locationAutoComplete_input=Wien&NewTimesheetForm%3AMain_locationAutoComplete_hinput
=15e41fee-ef98-4176-a118-032cef4e4c02&NewTimesheetForm%3AMain_workingTime=12&NewTimesheetForm%3AMain_description
=123&javax.faces.ViewState=15843050982783687%3A7588832336313498775
Any ideas what might be the reason for the validation errors?
PrimeFaces 5.2
Mojarra 2.2.10
Wildfly 9.0.1
I was using the wrong converter. This is the right way to do it: http://showcase.omnifaces.org/converters/ListConverter

Null value submitted for a conditionally disabled field in a reusable JSF popup

I have a popup dialog developed in IceFaces 1.8.x (JSF 1.2).
The dialog is reusable (used for account creation as well as modification) and has a cancel button with immediate = true (to avoid validations). This dialog suffered a problem in the past ,where old values were rendered on re-opening the dialog, but that problem is now fixed as directed here (by setting submittedValue to null etc.).
The problem that I am facing now is specific to a conditionally disabled input field (<ice:inputText>) and here is what happens:
The popup is first opened (say for account creation) and this field
is NOT disabled.
User then cancels this dialog and, as we have incorporated the fix mentioned above (setSubmittedValue(null)), the submittedValue for this field is set to null (along with other fields).
Now the user opens "modify account" dialog, where in this field IS disabled. Everything seems to be rendered fine until user makes any changes to the form.
When user changes some field (say name) in the form, a partial submit happens for the name field as expected, but along with it null value is submitted for this disabled field.
This problem can be worked around by adding a null check in the setter method for the field in question, but this is not the desired solution for the project - as there are multiple places where this could be needed and doesn't seem like a very intuitive thing to do.
So I need to understand:
Why is the setter for this disabled field getting called in the
first place? and that too with a null value. The setter is not
called for any other enabled fields.
More importantly, is there any way to fix this (other than adding null check in the setter)?
You must be using rendered attribute to show/hide the dialog
<ice:panelPopup modal="true" rendered="#{bean.enabled}">
When dialog is reopened, it is coming up with some residual values from previous instance
The solution (or workaround) is to use <c:if> instead of rendered attribute, this way the DOM is completely destroyed when dialog closes and created from scratch when dialog opens
<c:if test="#{bean.enabled}">
<ice:panelPopup modal="true">
...
</ice:panelPopup>
</c:if>
This way you even would not need the fix to set submittedValue to null

User manipulating the legal values in a JSF selectOneMenu

Technology: Java EE 6, JSF 1.1, ajax4jsf
I'm representing a selectOneMenu to the user (dropdown-list) that is pre-filled with all the legal values the user can submit. Let's say it's datevalues:
01.01.2010
01.01.2011
01.01.2012
The selected value in the dropdown-list is bound to a property on a backing object (form.chosenDate) and the values in the list is retrieved from a list on a backing object (form.selectableDates). form.chosenDate is updated with a4j as the user selects different values.
The question is, is it possible for the user to submit the form with other values than the list was populated with (values in form.selectableDates)? If so is the case, how can this be done? In the dev-tools in Google Chrome, I can manipulate the html and change the values "runtime", but when I submit, the dropdown-list is refreshed with the original values, and I have to submit again. Is this enforced by Google Chrome or JSF?
The question also goes for radio-buttons. Please enlighten me!
Yes, it is possible for user to submit a value that is not in the dropdown. Tamper data plugin for Firefox could do this for example. However, it will fail the JSF validation as the submitted value is checked against the list to see if it is contained in it. The user will get a "form:location: Validation Error: Value is not valid" error message.

Using `immediate` for a cancel button but saving only some fields

I have a JSF 1.2 Form which is composed of several parts.
I have validation with required tag turned on.
I want to be able to clear a certain part of the form which has required fields so on the 'clear' button i used the immediate tag.
Now the challenge - When pressing the 'clear' button all the values that were filled since the last submission are restored to the last submitted state while I would like only the certain part of the form to be affected. (Meaning, all the values that are not in that part of the form should be sumbitted although the button pressed is immediate)
Is there a way to do this?
EDIT - Can I submit a value after every time it was filled? This might be a solution.
Thanks!
If you want to take some fields along with the cancel button with immediate="true", then you should also put immediate="true" on those fields.
If you want to skip validation on those fields as well, then you need to change required="true" to required="#{empty param['formId:cancelButtonId']}" so that it is only required when the cancel button is not been used to submit the form.
As to submitting the values on change, that's best to be achieved with ajax in combination with a value change listener. To achieve that you would need to upgrade to JSF 2.0 or to introduce an ajaxified JSF component library.

Resources