ショーケースGrid (Editable/Multiselect) で示されているように、 struts2-jquery-grid-3.7.0プラグインを使用して Struts jQuery グリッドを使用して CRUD 操作を試みています。
これは次の形式です。
<s:form namespace="/admin_side" action="Test" validate="true" id="dataForm" name="dataForm">
<s:url id="remoteurl" action="TestGrid" namespace="/admin_side"/>
<s:url id="editurl" action="EditTest"/>
<sjg:grid
id="gridmultitable"
caption="Example (Editable/Multiselect)"
dataType="json"
href="%{remoteurl}"
pager="true"
navigator="true"
navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
navigatorEdit="true"
navigatorView="true"
navigatorAddOptions="{height:280, width:500, reloadAfterSubmit:true}"
navigatorEditOptions="{height:280, width:500, reloadAfterSubmit:false}"
navigatorViewOptions="{height:280, width:500}"
navigatorDelete="true"
navigatorDeleteOptions="{height:280, width:500,reloadAfterSubmit:true}"
gridModel="gridModel"
rowList="5,10,15"
rowNum="5"
rownumbers="true"
editurl="%{editurl}"
editinline="true"
multiselect="true"
onSelectRowTopics="rowselect">
<sjg:gridColumn name="countryId" index="countryId" title="Id" formatter="integer" editable="false" dataType="Long" sortable="true" search="true" sorttype="integer" searchoptions="{sopt:['eq','ne','lt','gt']}"/>
<sjg:gridColumn name="countryName" index="countryName" title="Country Name" editable="true" sortable="true" search="true" sorttype="text"/>
<sjg:gridColumn name="countryCode" index="countryCode" title="Country Code" sortable="true" search="true" editable="true" sorttype="text"/>
</sjg:grid>
</s:form>
行の追加、削除、編集などの操作の実行中に、対応するアクション クラスのメソッドがマップされ、呼び出されます。
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value = "json-package")
@InterceptorRefs(
@InterceptorRef(value = "store", params = {"operationMode", "AUTOMATIC"}))
public final class TestAction extends ActionSupport implements Serializable, ModelDriven<Country>
{
@Autowired
private final transient CountryService countryService=null;
private static final long serialVersionUID = 1L;
private Country entity=new Country();
private List<Country> gridModel=new ArrayList<Country>();
private String oper; //Getter and setter.
@Action(value = "EditTest",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "defaultStack", params = {"validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
public String edit() throws Exception {
System.out.println(entity.getCountryId()+" : "+entity.getCountryName()+" : "+entity.getCountryCode()+" : "+oper);
if(oper.equalsIgnoreCase("add")) {
//Adding a row.
}
else if(oper.equalsIgnoreCase("edit")) {
//Editing/updating a row.
}
else if(oper.equalsIgnoreCase("del")) {
//Deleting a row.
}
return ActionSupport.SUCCESS;
}
@Override
public Country getModel() {
return entity;
}
@Action(value = "Test",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "defaultStack", params = {"validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
public String load() throws Exception {
//This method is required to return an initial view on page load. Nothing to see here. Leave it empty.
return ActionSupport.SUCCESS;
}
}
削除中、ID (この場合はcountryId
) は常にnull
です。
編集中は、対応するグリッドの列countryId
に設定するのでnullです。editable="false"
に設定するtrue
と取得されますが、countryId
はデータベースの主キーであるため、編集しないでください。
削除および編集中にこの ID を取得する方法 (編集中は編集しないでください)。
これはもう特に関係ありModelDriven
ません。
編集:
編集および削除中id
に、次のようなアクション クラスの文字列型のフィールド
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
問題のグリッドの (選択された行の) 行 ID に初期化されます。
複数の行を削除する際、選択した ID で構成されるカンマ区切りの文字列に初期化されます。
グリッドの行 ID に基づく操作の実行は信頼できません。これらは、データベース内の主キーの値に基づいて実行する必要があります。これは可能ですか?