网格编辑时Struts2 jquery jqgrid动态下拉列表

时间:2015-01-20 07:03:15

标签: jquery struts2 jqgrid grid

这是我的jsp代码。

<s:url id="myEditOptions" action="myEditOptions.action"/>
<sjg:gridColumn name="branch" align="left" index="Branch" id="bnch" title="Branch" 
    editable="true" onclick="" edittype="select" editoptions="%{myEditOptions}"  />

struts.xml代码

<action name="myEditOptions" class="com.example.action.BranchAction" method="getDynamicBranch">
    <result name="success" type="json" ></result>
</action>

此处的操作类代码

public class BranchAction implements Action {

    private Map<String, String> branchList = new LinkedHashMap<String, String>();
    List<Customer> customerList;
    private List<String> brnch;
    Struts2ExampleDAO exampleDao ;
    private String myEditOptions;
    public BranchAction() {
        exampleDao = new Struts2ExampleDAOImpl();
        customerList = new ArrayList<Customer>();
    }

    public String getDynamicBranch(){       
        customerList = exampleDao.getCustomerListData();
        brnch = new ArrayList<String>();
        for(Customer cust:customerList) {
            int i=0;
            if(cust.getBranch() != null && cust.getBranch().length() !=0) {             
                brnch.add(""+i+":"+cust.getBranch());
            }
            i++;

        }
        //Collections.sort(brnch);
        myEditOptions = "{value:'"+StringUtils.join(brnch,";")+"'}";
        System.out.println("************List size:::********"+brnch.size());
        return "success";
    }


    public String getMyEditOptions() {
        return myEditOptions;
    }

    public void setMyEditOptions(String myEditOptions) {
        this.myEditOptions = myEditOptions;
    }
}

分支下拉列表未显示。如果有人知道请帮助我使用struts2 jquery jqgrid 进行网格编辑时获取动态下拉列表。即使我能够通过使用普通的struts2选择选项

来获得动态下拉列表
<s:select label="What's your favor search engine" 
    headerKey="-1" headerValue="Select Search Engines"
    list="searchEngine" 
    name="yourSearchEngine" />

像这样我在执行struts2网格编辑选择选项时需要相同的功能(动态下拉列表)

1 个答案:

答案 0 :(得分:0)

糟糕!是的,当使用struts2 jquery jqgrid编辑网格时,终于得到了动态下拉列表的解决方案,并使以下更改工作正常。!

public String getDynamicBranch(){       
    customerList = exampleDao.getCustomerListData();
    myEditOptions = "<select>";
    for(Customer cust:customerList){
        if(cust.getBranch() != null && cust.getBranch().length() !=0) {
            System.out.println("******Branch values***:::"+cust.getBranch());
            myEditOptions += "<option value="+cust.getBranch()+">"+cust.getBranch();
        }

    }
    myEditOptions += "<select>";
    //Collections.sort(branchList);     
    return "success";
}