matthew simcox

Greenhorn
+ Follow
since Aug 20, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by matthew simcox

Hi, I'm using visual jsf on netbeans 6.1.

I have a panelgrid that contains static text or text fields depending on a backing bean field (true|false). This works. However I have an Edit link which calls the following method in the Bbean:

public void setUserDetailToEdit() {

if (getEditUserDetail().equals("true")) {

log("Set EditUserDetail false");
getSessionBean().setEditUserDetail("false");
} else {

log("Set EditUserDetail true");
getSessionBean().setEditUserDetail("true");
}
}

This method sets a field on the sessionbean.EditUserDetail to either value and in the backing bean I reference this value in the constructor as:

setEditUserDetail(getSessionBean().getEditUserDetail());

Each time the page is refreshed it checks the current sessionbean value and sets the BB value to this saved value.

The problem is my Edit link needs to be clicked twice to get the static text to change to text fields the first time. AFter this it flicks between the two witha single click. I'm not sure why this would be the case.
16 years ago
JSF
i believe visual jsf does support this. theres a section on ajax which includes javascript in the book "core java server faces". It also includes sections on javascript libraries that reduce the amount of javascript code you need to write.

I'm a newbie at this as well but try googling the prototype libraries or go to http://prototype.conio.net (from the book not been there myself as yet)
16 years ago
JSF
thanks for the help. In the end I've changed it so that the navigation sends the user back to the login page and then in the constructor of the backingbean it checks to see if some login variables are null or not. if they're not null then the session gets invalidated. Any better ideas would be gratefully accepted:

public login() {



/*If user already logged in then log them out when redireted back here*/
if (getSessionBean().getRetrievedUserName() != null) {

log("About to invalidate login");

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();
}
}
16 years ago
JSF
sorry pasted the code the wrong way around:

This doesn't work:

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)fc.getExternalContext().getRequest();
request.getSession().invalidate();

this does work:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = externalContext.getSession();
session.invalidate();

The first appears to get the session off the back of the request and invalidate, the second gets the session from the external context. What is the difference here and why would it prevent naviagtion. The navigation occurs after the invalidate() is called.
16 years ago
JSF
Yeah I believe so:

<navigation-rule>
<from-view-id>/Entry.jsp</from-view-id>
...
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/login.jsp</to-view-id>
<redirect/>
</navigation-case>
...

I've had a hunt around and found this variation does work:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();

Not sure what the difference is between the two though.
16 years ago
JSF
I forgot to include the action code in the backing bean:

public String logout_action() {

log("Invalidating Session for user: " + getSessionBean().getProvidedUserName());

/*Invalidate the session and return user to login page*/
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();

return "logout";
}
16 years ago
JSF
I've a banner jsf subview used on all my pages. In this banner I have a logout link that invalidates the user session then redirects to the initial login page. when the logout link was in the main page (not in a subview) it worked a treat however inside the subview the session is invalidated but no redirection occurs. The setup is as follows:

Entry page:

</ui:head>
<f:subview id="entryviewbanner">
<jsp:include page="/BannerView.jsp"/>
<jsp:include page="/EntryView.jsp"/> ***contains the link


EntryView page:

<ui:form id="form_entryview">
<h:panelGrid columns="2" id="welcomepanelgrid" style="left: 24px; top: 144px; position: absolute">
<ui:label id="welcomelabel" text="#{bundle.entryview_welcome_label}"/>
<ui:staticText id="welcometext" text="#{SessionBean.firstName} #{SessionBean.surName}"/>
<ui:label id="rolelabel" text="#{bundle.entryview_role_label}"/>
<ui:staticText id="roletext" text="#{SessionBean.role}"/>
</h:panelGrid>
<ui:hyperlink action="#{EntryView.logout_action}" id="logout" style="left: 1150px; top: 144px; position: absolute" text="#{bundle.entry_logout}"/>
</ui:form>
</f:subview>

Can anyone suggest why this wouldn't work. I really don't want to have to include the logout button in every page separately. Is there a better way of doing this?
16 years ago
JSF