aspose file tools*
The moose likes Struts and the fly likes input values like name= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "input values like name="bean.property" can not be populated to interceptors" Watch "input values like name="bean.property" can not be populated to interceptors" New topic
Author

input values like name="bean.property" can not be populated to interceptors

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
Hi,

In my Strut2 application I have to pass uservo.userId and uservo.password to AuthenticationInterceptor's intercept method.

UserVO is a model object that has userId and password properties.

index.jsp:-


<s:textfield theme="simple" name="uservo.userId" cssClass="LoginTextBox" size="20" />

<s:password theme="simple" name="uservo.password" cssClass="LoginTextBox" size="20" />

when the page is submitted, AuthenticationInterceptor will be invoked to do authentication for checking userId and password entered by the user.

AuthenticationInterceptor.java


public class AuthenticationInterceptor extends AbstractInterceptor implements SessionAware,RequestAware{

private UserVO uservo;
private String userId;

private String password


UserServices userServices=new UserServicesImpl();
Map<String,Object> session;
Map<String,Object> request;

public void setSession(Map session) {
this.session = session;
}
public void setRequest(Map request) {
this.request = request;
}

@SuppressWarnings("unchecked")
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Inside AuthenticationInterceptor");
log.debug(" Inside AuthenticationInterceptor ");
ActionContext ctx = invocation.getInvocationContext();

session = ActionContext.getContext().getSession();

log.debug(" ActionContext ctx :"+ctx);
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
log.debug(" HttpServletRequest request :"+request);

String userIPAddress = request.getRemoteAddr();
String loginID = "anonymous";

//assertCanCreateSession(request);


if (authenticateCoinUser(request))
{
loginID = (String)session.get("userId");
if(loginID == null || loginID.trim().equals("")){
loginID = "anonymous";
}
log.debug("loginId and IP :"+loginID+" : "+userIPAddress);
if(userServices.enlistUserProfile(loginID, userIPAddress)){
return invocation.invoke();
}
}else{
throw new AuthenticationException("You are not authorised");
}
return null;
}

public boolean authenticateCoinUser(HttpServletRequest request){

System.out.println(" uservo >>"+uservo);
String userId=getUserId();
String password=getPassword();
System.out.println(" userId >>"+userId);
System.out.println(" password >>"+password);

return false;
}

public UserVO getUservo() {
return uservo;
}

public void setUservo(UserVO uservo) {
this.uservo = uservo;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}
}

I could not get the uservo.userId and uservo.password input values from index.jsp to the interceptor even i implement RequestAware.

uservo object throws NullPointerException.

Could anybody tell the answer?



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

1) Interceptors are not actions, and are not treated as such: request parameters are not set on interceptors, and doing so would be a potential nightmare. Ideally, interceptors are completely ignorant of other interceptors in the interceptor stacks.

2) This is an inappropriate use of an interceptor: interceptors are designed to handle cross-cutting application concerns, not logging someone on. Logging someone on should be handled by an action. *Checking* if someone is logged on would be handled by an interceptor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: input values like name="bean.property" can not be populated to interceptors
 
Similar Threads
passing input type="text" from jsp to bean & using that in servlet
Struts 2 session writing efficiency / timing
struts 2 passing parameter to interceptor
Bean values are null
Setting request parameter from interceptor and accessing in ActionClass