mail2bansi (2) [Avatar] Offline
#1
My requirement is
" Our users are Authenticated by External System . On successful
authentication the external system returns header variables viz. userId,
firstName, lastName etc to our System.
Currently I am able to retrieve these header variables using
request.getHeader("userId") in my JSP page.
But this is certainly not the best practice. I am thinking of storing this
information in Backing Bean via Phase Listener for further use like
1) retrieving user Roles from the Database based on userId and
2) displaying JSP page based on user roles

I am not sure how to tie up PhaseListener with the Backing Bean . I mean how
do I call backing bean method from Phase Listener if I retrieve header
variables in afterPhase method.

Here are my snippets of code

--------------------
Faces-config.xml :
--------------------
<lifecycle>
<phase-listener>
com.mycompany.MyPhaseListener
</phase-listener>

<managed-bean>
<managed-bean-name>greetingForm</managed-bean-name>
<managed-bean-class>com.mycompany.GreetingForm</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>id</property-name>
<value>#{param.id}</value>
</managed-property>
<managed-property>
<property-name>testSpringBean</property-name>
<property-class>
com.mycompany.TestSpringBean
</property-class>
<value>#{testSpringBean}</value>
</managed-property>
</managed-bean>

--------------------
MyPhaseListener
--------------------
public void afterPhase(PhaseEvent pe)
{
System.out.println("after - " + pe.getPhaseId().toString());

if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE)
System.out.println("Done with Request!
");
Map requestHeaderMap = new HashMap();

requestHeaderMap =
pe.getFacesContext().getExternalContext().getRequestHeaderMap();

System.out.println("Hash Map Size:"+requestHeaderMap.size());

String bemsId = (String)requestHeaderMap.get("USERID");
System.out.println("userId="+userId);


}

Any pointers/suggestions with little snippets of code will be highly
appreciated

Regards
Bansi
kito75 (49) [Avatar] Offline
#2
Re: How to call Backing Bean method from Phase Listener
Bansi,

You can easily retrieve a backing bean by accessing the EL programmatically. You can do this through the Application class, which has methods for creating and evaluating EL expressions. So, for example, you could get a reference to geetingForm like so:

GreetingForm form = (GreetingForm)application.getVariableResolver().resolveVariable("greetingForm");

See the book for details.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann - Author, JavaServer Faces in Action
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info

* Sign up for the JSF Central newsletter! http://oi.vresp.com/?fid=ac048d0e17 *
sandy312 (1) [Avatar] Offline
#3
Re: How to call Backing Bean method from Phase Listener
Hi I am having a similar problem like this. can you please share some information on this.

Regards

Sandeep
SteveColin (1) [Avatar] Offline
#4
Re: How to call Backing Bean method from Phase Listener
I was delighted to find this web site.I wanted to thank you for your time reading this wonderful!
Logoinn
561191 (1) [Avatar] Offline
#5
Such a great post to know different useful information.
Logo Mines
Online Design (1) [Avatar] Offline
#6
561191 wrote:Such a great post to know different useful information.
Online Design Company


Yes, it is this website make true and good branded logo