Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!

Naveen Sampra

Ranch Hand
+ Follow
since Jun 11, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Naveen Sampra

Tim and others,

Are the partial updates done on page after AJAX call available on a post (i.e JSF submit) ?



In my example above initially data table is empty. Clicking on "Populate People Table" link renders 3 rows in the table. However when I click "Save" the bean property dataBean.peopleList does not get set with 3 items.

I'm using requestScope bean and JSF1.2

Appreciate if you can help me understand why this happens.
Also how to post values that are only available on client after AJAX call and not on the Server(i.e component tree) ?


Thanks.


8 years ago
JSF
Tim and others,

I'm at a loss at following valueChangeListener behavior. I could not find this behavior in the documentation. If anyone wants they can use the code below and create simple facelet and managed bean to test. I'm using JSF 1.2.

I have a simple JSF page with 2 input componenets.




MBean class has following action methods:


Below are 2 issues I found:

1) valueChangeListener method gets fired during validation phase.


This is an issue since I need to invoke business logic and update bean values in valueChangeListener method.
I want the new values to get rendered on page. However my values gets overwritten in the later phases. Should'nt action/listener methods get invoked in invoke application phase ? How do I update bean values on the server side based on drop down selection and redisplay after post back?


2. valueChangeListener method gets fired although no value was changed
Enter a value in inputText and clicking save fires valueChangeListener and then saveSPConfig action method. However I did NOT change drop down value.

From the logs below I see why this happens, but this is incorrect behavior. User did not select a new value from drop down.


valueChangeListener is a common feature. I'm pretty sure there's a standard pattern out there to fix above behavior.


Overall I think the JSF model is quite complex. The detailed life cycle phases make the model very robust but at the same time a very big learning curve. What would be nice is to have a good design pattern book for JSF.

8 years ago
JSF
Thanks for the tips on StringBuilder optimization and word optimization.

I'm still not sure if the issue is to do only with URL formating.
If you look at the error message, the J2EE context path or webapp path i.e /sonic2 is correctly prefixed.

However relative path to current JSF page jsf/page/ps/qa/ is also prefixed. This is causing forward to return a HTTP 404 error.

I'm looking into getRequestDispatcher behavior to try fix the path.

In the meantime are there any other suggestions to forward to a Servlet after JSF submit? Perhaps javascript on page that can be tied to an event.
8 years ago
JSF
Tim and others,

I'm doing a form submit using: <h:commandLink value="Mark Approve" actionListener="#{pageBeanName.handleActions}" /> from an IFrame window on my page.

On the actionListener I want to update DB and forward the request to Dispatcher servlet which will re-render complete page including embeded JSF IFrame component.




I get the error: The requested resource (/sonic2/jsf/page/ps/qa/Dispatcher) is not available

This is because /jsf/page/ps/qa which is relative path to current JSF resource is pre-appended.

I need /sonic2/Dispatcher?rid=356& ......... format for the request to be forwarded successfully.

Any idea how to make this forward work ?

8 years ago
JSF
Gustavo,

My solution was to use <a4j:keepAlive />
I put these hidden params in separate bean and inject it to my backing bean. Then on facelet page I preserve the new bean using <a4j:keepAlive beanName="hiddenParamBean" />. All beans are in request scope.

In backing bean constructor I initialize using values from hiddenParamBean.

There is definietly an issue with <h:commandLink> and using EL for the rendered="#{}" attribute value.

As you might have also observed there is no disabled attribute for <h:commandLink> unlike other components.



8 years ago
JSF
Tim,

Thanks for your points.

I see... the list values are needed for validation phase.
Isn't this is a constraing in JSF model? I cannot defer initialization upto just before page rendering, in the case of SelectOneMenu.
This would happen if list is dynamic and is determined after invoke application phase.







8 years ago
JSF
Tim and others,

I have a slightly different approach in one of my apps.

The list values(for dropdown selects) on page is created by external framework. On page display the list is set in HttpRequest by external framework and passed to bean(which has request scope). This works fine during display since I can read the value(if available) in the bean constructor.

On the submit process I call the external framework to save data. I have a callback mechanism that allows external framework to set the list value in my bean. As you know call to save happens only during invoke application phase.

The problem is I get a JSF exception during update model values phase since the list is null.

At this moment I don't want to change the approach of using external framework.

Is there anyway I can manupilate the JSF phases? I don't have much experience with custom componenets; would that help?

Please let me know.


Thanks,
Sampra



8 years ago
JSF


hasSavePrivilege passed to JSF page on initial request is read in bean constructor and set as bean property. Bean has request scope.
A hidden field on page is used to preserve hasSavePrivilege. The initialization of hasSavePrivilege property happens through the setter then afterwards, using hidden field value on page. i.e. initialization NOT in the bean constructor.

The problem is even when hidden field hasSavePrivilege=true the action method is not invoked.

Any help appreciated.
8 years ago
JSF
Phil,

You are on the right track. Part of your explanation fits what I found in my debugging. By the way hasSavePrivilege is passed in the initial request to my page, so I have the <h:inputHidden ../> mechanism already setup to save this value on page to be used in subsequent form submissions/page rendering.

Here's the issue:
hasSavePrivilege is true. I have verified that. However on clicking "Save" link, the bean field gets updated to true only at Update Model phase(my bean has REQUEST scope). At this point my target action DOES NOT get invoked at Invoke Application phase(Not sure why?).

When I forcefully initialize hasSavePrivilege value to true in bean constructor(NOTE:- During Apply Request values phase and before update model), the target action gets invoked!

I tried using immediate="true" in hidden field to force the bean update at Apply Request values phase, but that does not work.
I'm not sure why <h:commandLink> is behaving this way with rendered attribute.

So looks like only solution is to to retrieve hidden field value from HttpRequest in bean constructor and set it. This will make sure target action gets invoked if hasSavePrivilege=true.

Any other ideas?



8 years ago
JSF
When rendered="true" the link is displayed as expected. However when clicking link, the target action listener is not called.

The debug statments from my phase listener shows that all phases are executed:



I'm not sure what's wrong in the page. Has anyone run into this problem ?

I have a simple debug statment in target listener method.

8 years ago
JSF
When I use the rendered attribute, the action listener method does NOT get invoked :



However when I remove the rendered attribute, the action listner DOES get invoked:



Any ideas why this might happen ?


Note:- rendered="#{pageBean1.hasSavePrivilege}'' itself works properly. i.e when value is false link does not get rendered and vice versa.



8 years ago
JSF
I need some advice on design choices available managed bean initiallization:

My managed bean backs a JSF page that has both user input fields and Lists which drive the drop down choices presented to user.

I'm populating the List values and initial user values from DB in the constructor of the Managed Bean. (I can also use @PostConstruct but its the same thing expect I can throw exceptions in the constructor).

Now when the page is submitted, JSF creates a new Bean instance. So the initialization code gets invoked in constructor again.

Here are my issues:

1. Initializing list values again: This is OK since page might need to be rendered again if it contains validation errors, so List data will be needed. However if no validation errors then the initializing Lists is a wasted call.

2. Initializing user values from DB: On submit reading user values from DB is a waste since they will be over-written by FORM values.

Can someone tell me how issues 1 and 2 above are handled ? Is this the standard way of Managed bean initialization( i.e. in bean Constructor or using @PostConstruct).

Appreciate if you can give clear details on Managed bean initialization choices.



8 years ago
JSF
I figured this one out.

8 years ago
JSF
How would I reference myPage1Bean that is passed to the include file?
I need to reference both a property(say idValue and action listener(say myListener).

I need to use idvalue on a <h:selectOneListbox ...> component and myListener on a <h:commandLink ...> component.

Appreciate if you can help with correct usage since I'm getting errors when I tried value="#{pageBeanName).idValue" or binding="#{pageBeanName).idValue" etc.
8 years ago
JSF
This issue is same as the one I posted earlier today. Looks like no one was able to answer this upto now.

http://www.coderanch.com/t/519780/JSF/java/Invoking-bean-included-JSF-page


Can anyone give input as to how underlying JSF framework handles an include.

Also the problem we are running into seems like a common design issue. i.e How to abstract bean invocation from a common include file.

8 years ago
JSF