Rendered attribute executing before button action - jsf

I have two view htmls(V001 & V002) both of which are to be rendered using the same jsf page. There is a continue button in my JSF Page which performs the action of storing the V001 DOM in Cache and fetches the V002 from Content server and displays it to the user. This is achieved through a managed bean.
In view V002, I have a button which I need to be rendered based on whether the view is V002 or not.
However the issue is the rendered condition is executing before the continue action and hence always evaluate to false since the view change from V001 to V002 happens only when the continue button action is executed.
NB: My bean is request scoped and I am using JSF 1.1

Related

.NoSuchElementException on click of the submit button, working with SelctOneMenu in JSF1.2

I have a jsf page with few input components and two h:selectOneMenu components.
On selection of a value in the first drop down I'm calling a valuechange listener and submitting the form. Then I populate the value into the other drop down depending on the value selected from the first drop down. Now I enter other fields and click on the submit button.
It throws me the below mentioned exception.
My Backing bean is in Request scope. I hope it will work fine for me if I change it to session bean which is not right to do in my application. I'm populating the data to SelectItem variable from the "ValuechangeListener" method.
JSF version is 1.2, I can't upgrade it to 2.0 at this point.
RequestScope in this case is not enough. You need at least ViewScope.
This is because the Bean will get reset with every request. The listeners of your Bean will be called for another instance of that bean and will change that. After that you do some changes in the browser and the next time you send a request, your bean has already been destroyed. Thus everything you did in your listeners got lost and that's why you run into problems.
If you work with ajax, or stay on the same page and keep manipulating it, then you should switch to a higher scope.

JSF component value not properly updated to model upon submit

I have facelets page with a control that usually is disabled by default, i. e. when the page is first rendered to the client. This is determined by an EL expression:
disabled="#{referenceValue != requestbean.dependentControlValue}" id="notWorking"
After the page is rendered, the user can set the requestbean.dependentControlValue to referenceValue and via some Javascript for the dependent control, the component "notWorking" is enabled.
However, upon submitting the form the value for notWorking does not get updated as found out by adding a debug log message in the setter for the value. I can see, that the value for notWorking is set in the request when inspecting it with firefox.
Question:
What am I doing wrong?
By the way:
I know that according to HTML specification, disabled controls cannot be successful thanks to the research here on StackOverflow.
Moreover, I know from this post, that the disabled and rendered expressions are considered before updating the model values, but I think the disabled expression should evaluate to false upon submitting the form.
What am I doing wrong?
Using JavaScript instead of JSF to re-enable the input.
As part of JSF's builtin safeguard against tampered/hacked HTTP requests, the disabled attribute is (like rendered and readonly attributes) re-evaluated during processing the form submit. If they evaluate in such way that the value shouldn't be processed at all (i.e. disabled/readonly=true and rendered=false, then the submitted value won't be applied, converted, validated and the model won't be updated.
The solution would be to use JSF instead of JavaScript to re-enable the input, or to rewrite the condition in disabled attribute in such way so that the disabled attribute evaluates false during processing the form submit.

ViewScope beans behaves like it has application scope

I am doing work on a project using primefaces 3.5 and my problem is that...
I have a search form I enter some criteria in the form and press Search Button...Result is displayed...suppose using FireFox
Now If I open application same page in some other browser suppose IE there I will see the form with same values and same search result returned earlier...even this is a new session
More over suppose in the same browser if I logout and then login and navigate to same page I see the search form with same values and same result returned.
More or less this behavior is close to application scope Beans where as I have not any application scope Bean and have only one Bean with session scope for login purpose...rest of the beans are #ViewScoped
If I use #Scope("request")...Bean is created on each request but in this case I am unable to set parameter to the confirm dialog for deleting the record because when i click on dialog delete button previous values gets nullified due to new request.
I am in great difficulty and have done too much workaround but all in vain....

what happens to jsf components after render attribute is updated

Given the following scenario : A jsf component's (e.g a CommandButton) render attribute depends on an application scoped managed property. Since the property is shared across all sessions, the following might easily happen : User A loads a jsf page and the button's render attribute is true, so it is rendered. Now user B also loads the page and the render attribute is still true. Now user A clicks the button which causes the property to change its value and the button is not rendered anymore. User B still has the old view and although the render attribute is false now, he can click the button because he didn't update his view in the meantime. What happens now if user B clicks the button?
I thought the button's action is fired anyway because the render attribute is just used for rendering the button and has no influence anymore, once the page is rendered. But after doing some tests it seems to me that the render attribute is also checked again after clicking the button and if the attribute is false then, the action is not performed. Can someone confirm this ?
Disclaimer: I'll ignore the strange design for now.
But after doing some tests it seems to me that the render attribute is also checked again after clicking the button and if the attribute is false then, the action is not performed. Can someone confirm this ?
Yes, that's correct. This is part of safeguard against possibly tampered requests wherein the hacker is trying to simulate the invocation of an action component which is actually not rendered by the server side (such as an admin-only command button which is only rendered when the current user has the admin role). The rendered (and disabled and readonly) attributes are always re-checked during processing the form submit.
In your particular case, you'd like to have a copy of the condition responsible for the rendered attribute in the view scope so that only this copy will be used as long as you're interacting with the same view. This can be achieved by just injecting the application scoped property as a managed property of a view scoped managed bean and then referencing it in the rendered attribute instead.
#ManagedBean
#ViewScoped
public class ViewBean {
#ManagedProperty("#{appBean.rendered}")
private boolean rendered;
// ...
}
with
<h:commandButton ... rendered="#{viewBean.rendered}" />

What is the difference between partialSubmit and autoSubmit in JSF?

I guess I knew the difference, but right now I find myself confused. :P
Both of them seem to be do the same thing, except that partialSubmit is used on submit buttons to submit the form using AJAX and autoSubmit is used on editable components, which submits only its own contents. Am I right in saying this?
The accepted answer isn't 100% correct for ADF. The partialTriggers attribute is involved in the lifecycle.
From Enabling Partial Page Rendering Declaratively
The autoSubmit attribute on an input component and the partialSubmit
attribute on a command component are not the same thing. When
partialSubmit is set to true, then only the components that have
values for their partialTriggers attribute will be processed through
the lifecycle. The autoSubmit attribute is used by input and select
components to tell the framework to automatically do a form submit
whenever the value changes. However, when a form is submitted and the
autoSubmit attribute is set to true, a valueChangeEvent event is
invoked, and the lifecycle runs only on the components marked as root
components for that event, and their children. For more information,
see Section 4.4, "Using the Optimized Lifecycle".
They are both AJAX enabled calls occurring from custom properties of custom JSF components. The autoSubmit essentially asynchronously postsback content specific to the component for keeping the server side managed bean values current with the content within the component on the client side.
A partialSubmit is another asynchronous AJAX call that will serve to immediately postback a component value on some kind of component event, like losing focus on an ICEFaces inputText component for example.
The interesting thing to note is that the entire ViewState is posted back on each type of asynchronous submit, so if the values of other components HAD changed on the page before the submit, the bound server side managed bean properties will have their values refreshed as well, even though the client side components MAY not be refreshed to reflect any server side data changes that may have occurred.
In fact, the entire JSF server side lifecycle occurs on each postback, read the following article on implementing a debug PhaseListener that allows you to see what Phases are occurring after each asynchronous submit operation occurs.
http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

Resources