开发者

Struts Jquery Plugin: Remote Dialogs With Parameters

I have a somewhat complicated issue.

I have a grid defined (using the Struts2-JQuery Grid Plugin). One of the columns has a custom formatter that calls a Javascript function to put a button into that column. (Note: I absolutely HATE doing it that way).

The point of the button is to open up a dialog box. This dialog box contains a checkboxlist, which can't be rendered in the grid.

S开发者_开发知识库omehow, I need to pass a parameter to the action that returns the view that will be displayed inside the dialog.

Since this is somewhat complex, here is the code:

Grid definition:

<sjg:grid gridModel="gridModel"
          id="gridTable"
          caption="Manage Users"
          dataType="json"
          href="%{remoteUrl}"
          pager="true"
          rowList="10,15,20"
          rowNum="15"
          rownumbers="true"
          cellEdit="true"
          cellurl="%{editCell}"
        />
    <sjg:gridColumn name="id"
                    hidden="false"
                    title="id"
                    formatter="integer"
                    index="id"
                    key="true"
    />
    <!-- Other columns ommitted -->
    <sjg:gridColumn name="manageRoles"
                    title="Manage Roles"
                    sortable="false"
                    align="center"
                    formatter="formatRoles"
            />
</sjg:grid>

Javascript Custom Formatter:

    function formatRoles(cellValue, options, rowObject) {
        return "<button onClick='openRoleDialog(" + rowObject.id + ")'>Edit Roles</button>";
    }

Dialog Definition:

<s:url id="manageRoleUrl" action="viewRoles" namespace="userManagement" />
<sj:dialog id="manageRoles" title="Manage Roles" autoOpen="false" modal="true" href="%{manageRoleUrl}" resizable="true"/>

Remote Manage Roles JSP (trimmed):

    <s:form id="roleChoiceForm" action="/userManagement/editUserRole">
        <s:hidden id="id" name="id" />
        <s:checkboxlist list="roleChoices" name="selectedNameChoices" />
    </s:form>

Since I get the id of the grid object via javascript, but use the JSP taglib for the dialog, how can I pass the id around?


you need to pass the 'cellvalue'. Your Manage Roles column should have 'name' attribute same as the one which has unique id of the row. probably 'id' in your case.


Step 1: a javascript on the "selected" event fills a form field and opens the dialogue

<sjg:grid gridModel="gridModel"
onSelectRowTopics="rowselectEvent"

$.subscribe('rowselectEvent', function(event,data) {
    id = event.originalEvent.id;
    $("#idSelected").val(id);
    $("#manageRoles").dialog("open");
});

<s:form id="idSelectedForm">
    <s:hidden id="idSelected" name="idSelected" value="unset"></s:hidden>
</s:form>

Step 2: the "formIds" attribute of the sj:dialog tag is used to submit the form data

<sj:dialog id="manageRoles" formIds="idSelectedForm"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜