Accessing value of a session bean on a JSF page

L

laredotornado

Hi,

I was hoping someone could help me optimize some code on my JSF page,
since I figure that's the point of JSF. Here's what I haev

SSOSessionBean ssoSessionBean = null;
ssoSessionBean = (SSOSessionBean)
session.getAttribute(IMConstants.SSOSession);
String userName = ssoSessionBean.getUserName();
out.println(userName);

Is is possible to condense this down to a single line of code? What
changes, if any, would I have to make to my faces-config.xml file?

Thanks, - Dave
 
C

conrad

laredotornado said:
I was hoping someone could help me optimize some code on my JSF page,
since I figure that's the point of JSF.  Here's what I haev

        SSOSessionBean ssoSessionBean = null;
        ssoSessionBean = (SSOSessionBean)
session.getAttribute(IMConstants.SSOSession);

How come you initialize then assign, when you could initialize in a
single step?

Is 'SSOSessionBean' an EJB?
        String userName = ssoSessionBean.getUserName();
        out.println(userName);

JSF is not used inside Java classes, but can invoke methods from such
classes. The JSF components are embedded in XHTML or JSP pages,
typically.
Is is possible to condense this down to a single line of code?  What
changes, if any, would I have to make to my faces-config.xml file?

What is the magic of having it in a single line of code?

In any event, you're better off putting display logic in a JSP than in
a "regular" servlet.

This will not condense the logic into a single line. In fact, it will
add lines and split the answer into two artifacts - the JSP that
displays 'userName' and the business logic that uses the
'SSOSessionBean' to obtain the value. It will be a better solution
than what you show us here.
 
L

laredotornado

laredotornadowrote:


How come you initialize then assign, when you could initialize in a
single step?

Is 'SSOSessionBean' an EJB?


JSF is not used inside Java classes, but can invoke methods from such
classes.  The JSF components are embedded in XHTML or JSP pages,
typically.


What is the magic of having it in a single line of code?

In any event, you're better off putting display logic in a JSP than in
a "regular" servlet.

This will not condense the logic into a single line.  In fact, it will
add lines and split the answer into two artifacts - the JSP that
displays 'userName' and the business logic that uses the
'SSOSessionBean' to obtain the value.  It will be a better solution
than what you show us here.

The code I had above was in a JSP but I was wondering I could replace
it with JSF tags. That is fine is this is not in a single line, but
how would you code it in JSF?

Thanks, - Dave
 
C

conrad

laredotornado said:
The code I had above was in a JSP but I was wondering I could replace
it with JSF tags.  That is fine is this is not in a single line, but
how would you code it in JSF?

Approximately like this:

<html> ... <body> ...

<h:eek:utputText id="userName" value="#{backer.userName}" />
...

where 'backer' is an instance of a JavaBean that encapsulates the
'SSOSe4ssionBean' call.

BTW, in your code snippet you showed
SSOSessionBean ssoSessionBean = (SSOSessionBean)
session.getAttribute(IMConstants.SSOSession);

What is 'IMConstants.SSOSession'? If it's a field, it's name violates
the coding conventions, as it looks like a nested class name.
 
L

laredotornado

laredotornadowrote:

Approximately like this:

<html> ... <body> ...

 <h:eek:utputText id="userName" value="#{backer.userName}" />
...

where 'backer' is an instance of a JavaBean that encapsulates the
'SSOSe4ssionBean' call.

BTW, in your code snippet you showed


What is 'IMConstants.SSOSession'?  If it's a field, it's name violates
the coding conventions, as it looks like a nested class name.

How would I construct the managed-bean construct such that it is
understood that the session attribute's name is "USER_CREDENTIAL"?

Thanks for your replies, - Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top