| Author |
Struts2, have to eneter site twice to get the list populated
|
Zenek Kowalski
Greenhorn
Joined: Apr 12, 2010
Posts: 4
|
|
Hello!
I have the following problem, I am using struts2 and hibenrate 3.0.
1. I click for the first time on menu postion that calls web page with a list with all users i get empty result( despite the fact there should be something)
I see in debug mode that it goes to execute() but not to getUsersList()
2. I have to go back in browser
3. Click one more time: It works, (goes to both: execute() and getUsersList())
Is there any parameters in beans/struts/xml that tells the web page not to try to wait for result from getter with elements for the list?
_____________________________________________________________________________________
struts.xml:
<action name="viewUsersList" class="main.java.trzy.ViewUsersListAction">
<result name="exception">/exceptions/notEnoughPermissions.jsp</result>
<result name="success">/admin/viewUsersList.jsp</result>
</action>
_____________________________________________________________________________________
viewUsersList.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/utils/libs.jsp" %>
<br>
<h3>Lista Userów:</h3>
<display:table decorator="main.java.trzy.util.LpTableDecorator"
uid="user" name="usersList" class="tabela" requestURI="" export="true"
pagesize="50" defaultsort="2">
<display:column title="Lp." class="number" property="lp" />
<display:column title="First name" property="firstName" sortable="true" />
<display:column title="Last name" property="lastName" sortable="true" />
<display:column title="Login" property="login" sortable="true" />
<display:column title="Mobile" property="mobile" sortable="true" />
<display:column title="">
<a
href="<s:url action="editUser" includeParams="none"><s:param name="userId" value="%{#attr.user.userId}" /><s:param name="submit" value="1" /></s:url>">Edytuj</a> |
<a
href="<s:url action="addUserAction" includeParams="none"><s:param name="submit" value="1" /></s:url>"
onclick="return confirm('Usuwanie jeszcze nie gotowe!');">Usuń</a>
</display:column>
</display:table>
<br>
_____________________________________________________________________________________
Action:
public class ViewUsersListAction extends ActionSupport {
private List<Users> usersList;
private String role = EMPTY_STRING;
private Integer userId = ILLEGAL_INT;
private String login = EMPTY_STRING;
private String firstName = EMPTY_STRING;
private String lastName = EMPTY_STRING;
private String password = EMPTY_STRING;
private String email = EMPTY_STRING;
private Integer pesel = ILLEGAL_INT;
private Integer mobile = ILLEGAL_INT;
private String submit = EMPTY_STRING;
private UserDao userDao;
private Users user;
public ViewUsersListAction() {
System.out.println("ViewUsersList()");
userDao = new UserDao();
}
public String execute() {
System.out.println("ViewUsersList execute!");
return SUCCESS;
}
public List<Users> getUsersList() {
System.out.println("getUsersList...");
try {
System.out.println("userdao.getAllUsers()");
System.out.println("userdao.toString()"+userDao.toString());
usersList = userDao.getAllUsers();
} catch (Exception e) {
addActionError("Błąd bazy danych przy pobieraniu listy użytkowników - filtr.");
}
return usersList;
}
public void setUsersList(List<Users> usersList) {
System.out.println("setUsersList...");
this.usersList = usersList;
}
/**below: all getters and setters**/
}
_____________________________________________________________________________
Any ideas whats the reason?
|
 |
Ahmed M. Omar
Ranch Hand
Joined: Mar 02, 2010
Posts: 43
|
|
try
|
 |
Zenek Kowalski
Greenhorn
Joined: Apr 12, 2010
Posts: 4
|
|
Ahmed M. Omar wrote:try
Thanks for try, but it helped me partly:
Good: It goes straight to getUsersList()
Bad:
It gives me
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String
So i think struts tries to match the result from getUsersList(), which is ArrayList,
to string (possible results in struts.xml for action ViewUsersListAction)...
Waiting for any ideas...
|
 |
Zenek Kowalski
Greenhorn
Joined: Apr 12, 2010
Posts: 4
|
|
zenon kowalski wrote:
Ahmed M. Omar wrote:try
Thanks for try, but it helped me partly:
Good: It goes straight to getUsersList()
Bad:
It gives me
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String
So i think struts tries to match the result from getUsersList(), which is ArrayList,
to string (possible results in struts.xml for action ViewUsersListAction)...
Waiting for any ideas...
I ve changed the execute() in ViewUsersListAction class to:
public String execute() {
System.out.println("ViewUsersList execute!");
getUsersList(); //new line!!!
return SUCCESS;
}
And it accured that it display-tag is faster than function getUsersList() gives the result...
I found also simmilar problem:
http://www.coderanch.com/t/467734/Other-Open-Source-Projects/nd-page-Next-link-Nothing
|
 |
Zenek Kowalski
Greenhorn
Joined: Apr 12, 2010
Posts: 4
|
|
Anyone? Please help
|
 |
 |
|
|
subject: Struts2, have to eneter site twice to get the list populated
|
|
|