I have a little scenario. I have two POJO classes and two tables User
and Domain
(same name for tables). Every user will belong to one and only one domain.
I have two Action classes one is UsersManagemntAction
and other is DomainsManagementAaction
. I use UsersManagemntAction
to perform CRUD operations that are related to users. In my User
class I have an attribute domainId
. This attribute will contain the id
of Domain
to which user belong. My problem is that I when I show user information in jsp page I show the domainId
with the users information. This is because user object will have the domainId
. Rather than showing domainId
I want to show domain name. I can't perform join query. what i supposed to solve this problem that when I am displaying information of user I call a function in user management action class pass the domainId
to that function. That function perform search on Domain
table and return the domain name. This solutions is not working because I didn't find any way to pass domainId
to that function. I am able to call a function of UsersManagemntAction
class but unable to pass domainId
. Please help me or otherwise suggest me an alternative solution.
Below is the code of JSP page and User
class.
JSP:
<s:if test="users.size() > 0">
<tbody>
<s:iterator value="users" >
<tr>
<td><s:property value="userId" /></td>
<td><s:property value="loginId" /></td>
<td><s:property value="password" /></td>
<td><s:property value="email" /></td>
<td><s:property value="domainName" /></td> <!--- It will call getDomainName function in action class -->
</td>
</tr>
</s:iterator>
</tbody>
User.java:
public class User {
private Long userId;
private String loginId;
private String password;
private String email;
private Long domainId;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getUserId() {
return userId;
}
@Override
public String toString() {
return "User [domainId=" + domainId + ", password=" + password + ", userId=" + userId + ", Login Id=" + getLoginId() + "]";
}
public String getLoginId() {
return loginId;
}
public void setLoginId(String loginId) {
this.loginId = loginId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
You can get it from the value stack, while you are iterating the User
object in on top of the value stack, so you can get it there
public String getDomainName(){
User user = (User) ActionContext.getContext().getValueStack().peek();
return domainService.findDomainById(user.getDomainId()).getName();
}