ModelDriven returns NULL for the params which have empty values.
Bean:
public class MyBean
{
private String userName;
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserName()
{
return userName;
}
}
Class:
public class MyAction extends ActionSupport implements ModelDriven<MyBean>
{
MyBean myBean = new MyBean();
public String execute()
{
System.out.println(myBean.getUserName());//getting null here
return "SUCCESS";
}
}
Request:
/home/MyAction.do?userName=&pass=
Hear I am passing empty value for userName param but in action I getting the null value.
How to get exact value in ModelDriven?
Although,
HttpServletRequest#getParameter()handles the two cases differently; for most practical purposes, it shouldn't matter much. That's because using ${EL} expressions or Struts display tags, thenullvalues would get rendered as blanks only.If, however, you have some code that depends on it (like
?chrometelling the browser type) you're better off changing it (to something like?browser=ff) because making your ActionsServletRequestAwareis not worth it.If you would still like to go for it, here's how to do it: