struts2 - optiontransferselect - 将整数列表传递给操作

发布于 2024-07-16 03:06:07 字数 967 浏览 2 评论 0原文

我在表单中有一个选项transferselect,但我不知道如何在我的操作中获取右侧列表中的选定项目。

我需要获取包含所有访问过的国家/地区 ID 的列表。 我在我的操作列表中尝试过(整数)countriesVisitedId; 但它返回 nullPointerException。 然后我尝试了 Integer id 但它返回 null。

这就是我所拥有的:

s:optiontransferselect

              label="Select visited countries"
              name="countriesNotVisitedId"
              leftTitle="Not visited countries"
              rightTitle="Visited Countries"
              list="%{countriesNotVisited}"
              listKey="id"
              listValue="name"
              headerKey="countryNotVisitedId"
              headerValue="--- Please Select ---"

              doubleName="countriesVisitedId"
              doubleList="%{countriesVisited}"
              doubleHeaderKey="countryVisitedId"
              doubleHeaderValue="--- Please Select ---"
              doubleListKey="id"
              doubleListValue="name" />

如何在我的操作中获取包含所访问国家/地区的整数 ID 的列表?

I have an optiontransferselect in a form but i dont know how to get the selected items in the rightlist back in my action.

I need to get a list with all the visited countries' ids. i tried in my action List (Integer) countriesVisitedId; but it returns nullPointerException. then i tried Integer id but it returns null.

this is what i have:

s:optiontransferselect

              label="Select visited countries"
              name="countriesNotVisitedId"
              leftTitle="Not visited countries"
              rightTitle="Visited Countries"
              list="%{countriesNotVisited}"
              listKey="id"
              listValue="name"
              headerKey="countryNotVisitedId"
              headerValue="--- Please Select ---"

              doubleName="countriesVisitedId"
              doubleList="%{countriesVisited}"
              doubleHeaderKey="countryVisitedId"
              doubleHeaderValue="--- Please Select ---"
              doubleListKey="id"
              doubleListValue="name" />

how can I get the list with the Integers ids of the visited countries in my action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

征棹 2024-07-23 03:06:07

我用头撞墙,想知道我做错了什么。 这非常简单

doubleName="fields" 是返回的标记字段

public void setFields(String fields) { 这是您的操作类中需要的内容。

我没有意识到的是需要选择元素才能发回。 或者简单地在标头中使用 ajax with

I was banging my head on the wall wondering what I was doing wrong. It is pretty simple

doubleName="fields" is the tag field that is returned

public void setFields(String fields) { this is what needs to be in your action class.

The thing that I didn't realise is the elements need to be selected in order to be sent back. Or simple use ajax with in your header

静赏你的温柔 2024-07-23 03:06:07

这是我尝试过的,效果很好。

步骤1:JSP将国家从左侧选择到右侧。

<s:optiontransferselect 
 label="Favourite Characters"
 name="leftSide"
 id="left"
 leftTitle="Left Title"
 rightTitle="Right Title"
 list="%{countriesNotVisited)"
 multiple="true"
 headerKey="headerKey"     
 doubleList="{}"
 doubleId="right"
 doubleName="rightSide"
 doubleHeaderKey="doubleHeaderKey"
 doubleMultiple="true" /> 

第 2 步:Javascript 代码自动选择右侧的所有数据。

 function selectall()
 {
 var list = document.getElementById("right");
 for (var i = 0; i < list.options.length; i++) 
   {
    alert(list.options[i].value)
    list.options[i].selected = true;
   }
 var form = document.getElementById("right");
 form.submit();
      return true;

}

步骤 3:在提交时从 JSP 端调用此函数。

<s:submit id="submitid" value="Submit" action="insert" onclick="selectall()"/>

步骤4:在action中,使左右两侧对象名的getter和setter采用字符串而不是字符串数组。

private String leftSide;
private String rightSide;

public String getLeftSide() {
    return leftSide;
}

public String getRightSide() {
    return rightSide;
}

public void setRightSide(String rightSide) {
    this.rightSide = rightSide;
}

public void setLeftSide(String leftSide) {
    this.leftSide = leftSide;
}

现在,如果您尝试在操作中打印一个值,您将得到以下值:

System.out.println("right side list " + ad.getRightSide());

Here's what I tried, it works fine.

Step 1: JSP to select the country from the left hand side into right hand.

<s:optiontransferselect 
 label="Favourite Characters"
 name="leftSide"
 id="left"
 leftTitle="Left Title"
 rightTitle="Right Title"
 list="%{countriesNotVisited)"
 multiple="true"
 headerKey="headerKey"     
 doubleList="{}"
 doubleId="right"
 doubleName="rightSide"
 doubleHeaderKey="doubleHeaderKey"
 doubleMultiple="true" /> 

Step 2: Javascript code to auto select all data from the right hand side.

 function selectall()
 {
 var list = document.getElementById("right");
 for (var i = 0; i < list.options.length; i++) 
   {
    alert(list.options[i].value)
    list.options[i].selected = true;
   }
 var form = document.getElementById("right");
 form.submit();
      return true;

}

Step 3: call this function on submit, from the JSP side.

<s:submit id="submitid" value="Submit" action="insert" onclick="selectall()"/>

Step 4: In the action, make the getters and setters of object names of the left and right sides take strings and not string arrays.

private String leftSide;
private String rightSide;

public String getLeftSide() {
    return leftSide;
}

public String getRightSide() {
    return rightSide;
}

public void setRightSide(String rightSide) {
    this.rightSide = rightSide;
}

public void setLeftSide(String leftSide) {
    this.leftSide = leftSide;
}

Now if you try to print a value in the action, you will get values:

System.out.println("right side list " + ad.getRightSide());
止于盛夏 2024-07-23 03:06:07

在你的行动中:

 public void setCountriesVisitedId(String[] countriesVisitedId) {
    this.countriesVisitedId = countriesVisitedId;
 }

In your action:

 public void setCountriesVisitedId(String[] countriesVisitedId) {
    this.countriesVisitedId = countriesVisitedId;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文