【问题标题】:checkboxlist with prechecked in struts2在struts2中预先检查的复选框列表
【发布时间】:2013-10-29 13:53:03
【问题描述】:

我正在尝试显示带有预检查项目的复选框列表。 这些值保存在我的数据库中的列表中,对于“编辑”,用户应该能够选择新选项以及“取消选中”一些先前选择的选项。 这就是为什么我需要将我的列表翻译回复选框列表......

你知道这怎么可能吗?

非常感谢!

【问题讨论】:

标签: select struts2 checkboxlist


【解决方案1】:

我会给你一个例子来说明如何做到这一点。

[1]edit.jsp 页面:

这是您要显示选中复选框列表的页面:

<s:checkboxlist name="type" list="typeList" />

这里的“type”是复选框的名称,“typeList”是一个列表,在我的例子中是从 actionclass 加载的。

[2]action类中的loadEditData方法:

public class your_action_class_name extends ActionSupport {
     private List<String> type;
    private List<String> typeList;
    public List<String> getType() {
        return type;}
    public void setType(List<String> type) {
                this.type = type;}
    public List<String> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<String> typeList) {
        this.typeList = typeList;
    }


    public String loadEditData(){
                tpyeList=\\add whole checkboxlist here;
                type.add("value that you want to prechecked");
                return SUCCESS;
    }
  }

[3]struts.xml:

 <action name="edit" method="loadEditData" class="your_action_class_Name" > 
    <result name="success">/edit.jsp</result>
 </action>

现在你的流程如下:

第一次调用将实现 loadEditData 方法的编辑操作,并在返回成功时显示带有预检查值的复选框列表的 edit.jsp 页面。

这个答案有用吗?

【讨论】:

  • 我完全以这种方式实现了它,但它不起作用:(我的类型被命名为ownKeywords,我做了一个addAll(keywords)。关键字填充了:publication.geyKeyword(),它是真的满了。但在我的 JSP 中仍然没有检查任何内容
猜你喜欢
  • 2016-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 2020-03-25
  • 1970-01-01
相关资源
最近更新 更多