package de.msg.logon;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
public class LogonAction {
public String doLogin() {
LogonForm form = (LogonForm) getManagedBean("LogonForm");
// Benutzer einloggen, wenn Username = Password ;-)
if (! form.getUser().equals(form.getPass()))
return "sucess";
else
return "failure";
}
/**
* * Get managed bean based on the bean name. * *
*
* @param beanName
* the bean name *
* @return the managed bean associated with the bean name
*/
protected Object getManagedBean(String beanName) {
return getValueBinding(getJsfEl(beanName)).getValue(FacesContext.getCurrentInstance());
}
private Application getApplication() {
ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
.getFactory(FactoryFinder.APPLICATION_FACTORY);
return appFactory.getApplication();
}
private ValueBinding getValueBinding(String el) {
return getApplication().createValueBinding(el);
}
private String getJsfEl(String value) {
return "#{" + value + "}";
}
}