This is how I solved this. But I'm not sure if this is the correct way..
as it seems more like a hack.
1. I created a property on managed bean, which just captures the
childObject (so, instead of accessing beanForm.entity.childObject, I can
access it as beanForm.childObject), also corresponding changes required
to tie it back to the beanForm.entity
2. In the validator method which I had written for the component (used as:
<h:selectOneMenu id="entity" value="#{beanForm.childObject}"
styleClass="common-dropdown" immediate="true"
validator="#{beanForm.validateChildObject}"
>
)
I check if a valid childObject is submitted, and if yes, then I load
that childObject from persistence and set it to
beanForm.entity.setChildObject()..
This seems to work in all the cases,
a: when a user unselects a previously selected childObject
b: user choses another childObject instead of current childObject
c. use does not change current childObject.
In any case, if this is not a 'good' way of doing this, how should one
proceed with such a scenario? (i.e if dropdown options are built using
values from the managed bean's properties?)
Thanks
MRather
M Rather wrote:
I thought provide a bit more debug info..
If a user selects any other option, then the lifecycle phases are:
----------------------------------------------
INFO: AFTER APPLY_REQUEST_VALUES(2)
Dec 24, 2007 1:26:11 PM org.exadel.jsf.PhaseTracker afterPhase
INFO: AFTER APPLY_REQUEST_VALUES(2)
[AppName] DEBUG [http-8080-1] LifecycleImpl.executePhase(110) |
exiting APPLY_REQUEST_VALUES(2) in
org.apache.myfaces.lifecycle.LifecycleImpl
[AppName DEBUG [http-8080-1] LifecycleImpl.executePhase(81) | entering
PROCESS_VALIDATIONS(3) in org.apache.myfaces.lifecycle.LifecycleImpl
Dec 24, 2007 1:26:11 PM org.exadel.jsf.PhaseTracker beforePhase
INFO: BEFORE PROCESS_VALIDATIONS(3)
Dec 24, 2007 1:26:11 PM org.exadel.jsf.PhaseTracker beforePhase
INFO: BEFORE PROCESS_VALIDATIONS(3)
...... it continues till save and then processess the action 'list'
to listing page.
If a user does not change the option, i.e., keeps the original option,
the lifecycle phases are:
------------------------------------------------------------
Dec 24, 2007 1:25:23 PM org.exadel.jsf.PhaseTracker afterPhase
INFO: AFTER APPLY_REQUEST_VALUES(2)
Dec 24, 2007 1:25:23 PM org.exadel.jsf.PhaseTracker afterPhase
INFO: AFTER APPLY_REQUEST_VALUES(2)
[AppName] DEBUG [http-8080-1] LifecycleImpl.shouldRenderResponse(164)
| exiting from lifecycle.execute in APPLY_REQUEST_VALUES(2) because
getRenderResponse is true from one of the after listeners
[AppName] DEBUG [http-8080-1] LifecycleImpl.render(121) | entering
RENDER_RESPONSE(6) in org.apache.myfaces.lifecycle.LifecycleImpl
Dec 24, 2007 1:25:23 PM org.exadel.jsf.PhaseTracker beforePhase
INFO: BEFORE RENDER_RESPONSE(6)
Dec 24, 2007 1:25:23 PM org.exadel.jsf.PhaseTracker beforePhase
INFO: BEFORE RENDER_RESPONSE(6)
So , after apply_request_values phase (2), it jumps to Render_response
phase (6).
What would make getRenderResponse to be true if the user is not
changing the current selection from dropdown?
Thanks
MRather
M Rather wrote:
Hello,
I have a <h:selectOneMenu ... . It has its options populated by
<f:selectItems value="#{lookupObject.availableOptions...}" />
I addtionally have two <f:selectItem along with it
<f:selectItem itemValue="" itemLabel="Select One Option" />
<f:selectItem itemValue="#{beanForm.entity.childObject.id}"
itemLabel="#{beanForm.entity.childObject.id}"
/>
(eventually, the second f:selectItem needs to be rendered
optionally.. but assume for now that is is needed.
The reason for this is this:
I have a dropdown in a form, its options and values should be :
"" "Select One Option"
"currentId" "Current Selected Option"
"optionOneId" "Available Option 1"
"optionTwoId" "Available Option 2"
If users select 'Select One Option', that delinks the obejct
relationship with that option (as this field is optional)
If user selects any of the Available Options, then on submit, object
is linked with that option.
And, if the user does not change the option from 'Current Selected
Option', then the object retains its existing relationship
In my case,
If a user selects 'Select One Option' or any of other options, the
submit works fine, including building of relationships.
BUT , IF a user does not change the options, upon submit I get the
following error:
beanForm:childObject: Validation Error: Value is not valid
I tried to use, 'immediate=true' to skip validation, and even wrote
my custom validator for the component, (actually, doing nothing in
it, assuming that will treat it as no error on validations), but I
still get this error?
Am I doing something wrong here?
Another thing to note is when the form is drawn after submit, the
'Current Selected Option' is empty and its value is empty. Should I
be populating this option in any other way? instead of the
bean.entity itself?
Thanks
MRather