I am new to Stripes and appreciate every hint that brings me closer to a functioning web application!
technological installation : java, dynamic web project, stripes, jsp
:
users can log in (index.jsp). After the correct email address and password (LoginFormActionBean.java), the user is redirected to the welcome page (loggedin.jsp). The content on this welcome page is something like "welcome <username>, you were logged in successfully!".
implementation :
I have a form in index.jsp where I take user input and pass it to a method in LoginFormActionBean.java -> works!
in the appropriate method, I check if the user is correct, and if so, I insert the user in the ActionBeanContext:
getContext.setUser(loggedinUser);
after that go to loggedin.jsp:
return new ForwardResolution("/loggedin.jsp");
loggedin.jsp contains the following important lines:
<jsp:useBean id="loggedinBean" class="mywebapp.controller.LoggedinBean" scope="session" /> ... ${loggedinBean.context.user} //show the whole user object ... <s:form beanclass="mywebapp.controller.LoggedinBean" name="ButtonForm"> <s:submit name="foo" value="PrintUser" /> </s:form> <s:form beanclass="mywebapp.controller.LoggedinBean" name="TextForm"> <s:text name="user" /> </s:form> ...
LoggedinBean.java contains the MyActionBeanContext attribute (e.g. LoginFormActionBean.java).
to get a custom object out of context that I use:
public String getUser(){ return getContext().getUser().toString(); }
Additionally, LoggedinBean.java contains a method that is annotated with @DefaultHandler and forwarded to loggedin.jsp (on the same page)
result
now what happens: after logging in correctly, I am redirected to loggedin.jsp, the line "$ {loggedinBean.context.user}" is empty, and therefore <s: text> -field.
BUT after pressing the "PrintUser" button, the <s: text> -field button in the "TextForm" form is populated with the user object of the registered user!
output
what I think is happening is that the setContext () method "LoggedinBean.java" is not called before I manually executed the method in the bean. Since the setContext () method in the bean is not called before I press the button!
online documentation says that to use the context attribute in JSP just write "$ {actionBean.context.user}". But the context is null!
even the book Pragmatic Stripes (2008) no longer contains information about using ActionBeanContext.
Question
what is happening there?
how can I get the string $ {loggedinBean.context.user} to display the logged in user at all?
and how can I get <s: text> -field to display a custom object after loading the JSP, but without clicking a button?
Hope my problem is clear and my comments satisfy