Struts 1:将jsp的值放入使用java列表的表单中

发布于 2024-12-19 16:44:14 字数 684 浏览 4 评论 0原文

在我的 jsp 中,我有一些这样的字段:

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

在我的表单中,我有一个 java.util.list,我需要从顶部的字段填充它:

private List<Double> field = new ArrayList<Double>();

public final List<Double> getField() {
    return field;
}
public final void setField(final List<Double> valeur) {
    this.field = valeur;
}

问题是该列表未填充。 有什么想法吗??? 谢谢 !!

In my jsp, I have some fields like this :

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

And in my form I have a java.util.list that I need to populate from the fields on top :

private List<Double> field = new ArrayList<Double>();

public final List<Double> getField() {
    return field;
}
public final void setField(final List<Double> valeur) {
    this.field = valeur;
}

The problem is that the list is not populated.
Any ideas ???
Thanks !!

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

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

发布评论

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

评论(2

青巷忧颜 2024-12-26 16:44:14

据我所知,
1、如果是struts 1,美元“$”字段不起作用取值。
2.您不应该在属性名称中指定索引,但标签翻译器会自动使用它,因此您的代码看起来像

 <html:text property="field" indexed="true"> 
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">  

我希望这可以帮助您解决问题。

According to my knowledge,
1. If it is struts 1, the dollar "$" field does not work to take the values.
2. You should not specify the index in the property name, but it will be automatically used by the tag translator and hence your code will something look like

 <html:text property="field" indexed="true"> 
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">  

I hope this helps you to solve your problem.

关于从前 2024-12-26 16:44:14

只需执行此操作

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

并采用以下形式:

private String[] field = new String[0];

public final String getField(int index) {
    return field[index];
}
public final void setField(int index, String value) {
    //Copy last values of the array into a temporary array, then add the new value
    String[tmp] = new String[index + 1];
    for(int i=0; i<field.length; i++){
        tmp[i] = field[i];
    }
    tmp[index] = value;
    this.field = tmp;
}

Simply do this

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

And in the form :

private String[] field = new String[0];

public final String getField(int index) {
    return field[index];
}
public final void setField(int index, String value) {
    //Copy last values of the array into a temporary array, then add the new value
    String[tmp] = new String[index + 1];
    for(int i=0; i<field.length; i++){
        tmp[i] = field[i];
    }
    tmp[index] = value;
    this.field = tmp;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文