struts 1.3 を使用してアプリケーションに取り組んでいます。私の JSP ページでは、登録されたすべてのユーザーの詳細が 1 行に 1 レコードとしてテーブルに表示されます。
各行には、FM と「ODP」の 2 つのラジオ ボタンがあります。ユーザー登録時のデフォルト値は、すべてのユーザーに対して FM になります。
管理者は特定のユーザーを選択し、そのオプションを ODP に変更する必要があります。管理者は、すべてのユーザーのオプションを変更したり、一部のユーザーをスキップしたりできます。送信ボタンを押した後、変更されたすべてのラジオ ボタンの値を 1 つずつ読み取り、管理者の選択に従ってデータベースを更新するにはどうすればよいですか。
値を変更した後に送信ボタンを押すたびに、アクション クラスで同じ古い値が取得されます。選択したラジオ ボタンの新しい値にアクセスするにはどうすればよいですか?
これに関するヘルプは大歓迎です。
これが私のサンプルコードです-
JSP-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
<div style="color:red">
<!-- <html:errors/> -->
</div>
<html:form action="/User.dp?parameter=save" >
<div>
<div style="float:left;padding-left:30px;">UserName</div>
<div style="float:left;padding-left:30px;">Address</div>
<div style="float:left;padding-left:30px;">Satus</div>
<div style="float:left;padding-left:30px;">Radio</div>
<div style="clear:both;"></div>
</div>
<logic:iterate id="listUserIdDetails" name="UserForm" property="listUserId">
<p>
<div>
<div style="float:left;padding-left:30px;"><bean:write name="listUserIdDetails" property="name"/> </div>
<div style="float:left;padding-left:60px;"><bean:write name="listUserIdDetails" property="address"/></div>
<div style="float:left;padding-left:60px;"><bean:write name="listUserIdDetails" property="active"/></div>
<div style="float:left;padding-left:60px;"><html:radio indexed="true" property="active" name="listUserIdDetails" value="001" /> <html:radio indexed="true" property="active" name="listUserIdDetails" value="002" /></div>
</div><div style="clear:both;"></div>
</logic:iterate>
<html:submit value="submit" ></html:submit>
</html:form>
</body>
</html>
これが私のアクションクラスです-
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserListForm userForm = (UserListForm) form;
ArrayList alist=userForm.getListUserId();
for(int i=1;i<alist.size();i++)
{
UserListForm ulist= (UserListForm)alist.get(i);
System.out.println("User:"+ulist.getName()+":"+ulist.getActive());
}
System.out.println(userForm.getName()+":"+userForm.getActive());
return mapping.findForward("success");
}
}
形-
public class UserListForm extends ActionForm {
private String name=null;
private String address=null;
private String active=null;
private ArrayList<UserListForm> listUserId=null;
public ArrayList<UserListForm> getListUserId() {
return listUserId;
}
public void setListUserId(ArrayList<UserListForm> listUserId) {
this.listUserId = listUserId;
}
......
......
}
管理者がラジオボタンを変更した場合、アクションクラスで変更された値を取得するのを手伝ってください。