0

The form doesn't submit to the bean.

login.xhtml

<h:form>
    <p:panel header="Login">  
        <p:messages id="msgs" showDetail="true"/>
        <h:panelGrid columns="2" columnClasses="column" cellpadding="5">
            <h:outputLabel for="user" value="Username" />
            <h:inputText id="user" value="#{login.username}" />

            <h:outputLabel for="pw" value="Passwort" />
            <h:inputSecret id="pw" redisplay="false" value="#{login.password}" />
        </h:panelGrid>
        <p:button value="Anmelden" action="#{login.login}" type="submit" />
    </p:panel>
</h:form>

Login.java

@ManagedBean
@ViewScoped
public class Login {

    private FacesContext fCtx;
    private String username;
    private String password;

    public Login() {
        fCtx = FacesContext.getCurrentInstance();
    }

    public String login(){
        HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false);
        String sessionId = session.getId();
        fCtx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info: ", getUsername()+", "+getPassword()+", "+sessionId));  

        return "login.xhtml";
    }


    public void setUsername(String username) {
        this.username = username;
    }
    public String getUsername() {
        return username;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getPassword() {
        return password;
        }
    }

There are even no exceptions in the logs. What's the problem and how can I fix it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sven
  • 6,288
  • 24
  • 74
  • 116

1 Answers1

1

The <p:button> doesn't submit the parent form, it's just a hook to be able to execute some JS code on button press without the intent to submit any POST form. Replace it by <p:commandButton>. Also, you'd like to add update="msgs" to refresh the component with id="msgs" after submit.


Unrelated to the concrete problem, you don't want to use getSession(false) since it may return null. Just use getSession(true).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you BalusC! But after fixig that my application responds with an error message :-) http://stackoverflow.com/questions/4605118/jsf2-exeptions-while-submiting-to-bean – Sven Jan 05 '11 at 14:26