DTOがセッションに格納されない
SAStruts 1.0.3 RC1/Seasar2.4.25を使って認証情報をセッションに格納しようとしたんだけど、どうやってもうまくいかない。
test.jsp
<s:form> ユーザ名:<input type="text" name="name"/><br/> パスワード:<input type="password" name="password"/><br/> <input type="submit" value="ログイン" name="login"/> </s:form>
UserDto
public class UserDto { public String name; public String password; }
TestAction
public class TestAction { @ActionForm @Resource protected UserDto userDto; @Resource protected AuthenticationDto authenticationDto; @Execute(validator = false) public String login() { authenticationDto.id = 1; authenticationDto.name = userDto.name; return "index.jsp"; } }
AuthenticationDto
@Component(instance = InstanceType.SESSION) public class AuthenticationDto implements Principal, Serializable { private static final long serialVersionUID = 1L; public int id; public String name; public String getName() { return name; } }
test/index.jsp
<logic:notEmpty name="authenticationDto" scope="session"> DTOあり<br/> </logic:notEmpty> <logic:notEmpty name="authenticationDto" property="name" scope="session"> nameあり<br/> </logic:notEmpty> ${authenticationDto.name}
結果
DTOあり
デバッガで追ってくと、UserDtoからデータは取得できて、Action内でAuthenticationDtoへセットはしていた。
んで、JSPで表示させたらセッションの中にはauthenticationDtoは入ってるんだけど、中身がid=0、name=nullになってる。なぜだ。。。