Praful, I doubt your approach will work... Of course your code is legal 100% but how to trigger it upon typing: http://localhost:8080/test/a.jsf?id=1 in your browser? JBoss Seam offers a solution for such situations.
Praful Sinha
Greenhorn
Joined: Jan 25, 2008
Posts: 18
posted
0
I have tested it in tomcat application and its working fine here.
hi wrong,
on which server you are working.
And if the protocal you are using is Http then i dont think you will get any issue to retrieving data from request parameter.
Hi, There are atleast two approaches by which you can call your required method. if the managed bean associated with your class is in request scope you can call the method from the constructor of the managed bean. Or you can bind a component to your backing bean using the HTML Form and call the method from there.
The cleanest approach is actually to realize that a "backing bean" isn't a special type of object - it's a POJO that's defined to JSF for management purposes.
What I'm doing in cases like this is to simply write a small servlet or JSP to catch the parameter request. The servlet/JSP then captures the parameter in the usual way, resolves the backing bean in its usual way, and calls the backing bean's setter for that property.
As a rough sketch:
Doing this will avoid using a lot of esoteric features that might change in future releases. I think the servlet and JSP definitions are pretty well stabilized by now.
Customer surveys are for companies who didn't pay proper attention to begin with.
Praful Sinha
Greenhorn
Joined: Jan 25, 2008
Posts: 18
posted
0
I have tested it in tomcat application and its working fine here.
hi wrong,
on which server you are working.
And if the protocal you are using is Http then i dont think you will get any issue to retrieving data from request parameter.
I also tried getting the Faces Context but it also comes back as null: FacesContext fctx = FacesContext.getCurrentInstance();
It seems when I am in the servlet I am not able to access objects normally available when I go through the Faces Servlet. Any suggestions or am I missing something?
I think the main problem is that a method wont get triggered once the parameter is passed. For instance we have a url like example.jsf?id=10 and a method like setViewID should be called in the managed bean. We can use the <managed-property> to do this Example is as follows * <managed-bean> * <managed-bean-name> manageBeanEx</managed-bean-name> * <managed-bean-class>urldata.web.ManageBeanEx</managed-bean-class> * <managed-bean-scope> request</managed-bean-scope> * <managed-property> * <property-name>viewID</property-name> * <property-class>java.lang.Integer</property-class> * <value>#{param.id}</value> * </managed-property> * </managed-bean>
"id" which is getting passed as the URL parameter is mapped to the viewID of the bean. This will call setViewID method in the managed bean. Note that you need to access the managed bean for this to happen. So something like <hutputText value="#{manageBeanEx.viewID}"></hutputText> Should trigger it.
I also tried getting the Faces Context but it also comes back as null: FacesContext fctx = FacesContext.getCurrentInstance();
It seems when I am in the servlet I am not able to access objects normally available when I go through the Faces Servlet. Any suggestions or am I missing something?
Reggie, I'm sorry I didn't see this earlier.
If your servlet attempts to get a session object before JSF has created it, you'll get back null. In order for it to work, you have to have created a session and you have to have initialized the bean. I haven't checked the spec, but as far as I know, a JSF session bean isn't created until the first time a JSF reference is made to that bean. If a session doesn't exist yet, the session will be created and then the session object will be created and stored in the session.
If you're calling the external servlet before this happens, you can have the servlet create the session object (and the session as well). However, the JSF management parameters won't be taken into consideration, so you'd have to handle all the initialization yourself (assuming there is any).
The JSF context is created and destroyed by the JSF servlet each time an HTTP request is made for JSF. So you can't reference it in non-JSF code.