gpt4 book ai didi

java - 从 Struts 2 中的对象 ArrayList 填充复选框

转载 作者:行者123 更新时间:2023-11-30 11:26:18 26 4
gpt4 key购买 nike

我确信我在做一些愚蠢的事情,但在过去的几天里,我一直在努力让我的复选框在一个遍历 ArrayList 的迭代器中填充Object

这是我的对象:

public class EmailObject {
int emailId;
String emailAddress;

public int getEmailId() {
return emailId;
}
public void setEmailId(int emailId) {
this.emailId = emailId;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}

在我的 Action 类中,我创建了上述 ArrayListEmailObject

在我的 JSP 页面上,我可以通过 checkboxlist 获取复选框(但这对我不利,因为我希望它是垂直的并且不想与 Struts 样式混淆)

<s:checkboxlist name="selectedEmails" list="userEmails" listValue="emailAddress" listKey="emailId" />

我还可以遍历 ArrayList userEmails 并显示值:

<s:iterator value="userEmails" var="thisEmailData">
<s:property value="emailId"/>
<s:property value="emailAddress"/>
</s:iterator>

但是在遍历 emailId 时我无法让它显示 ArrayList userEmails 。我尝试了所有这些:

    <s:iterator value="userEmails" var="thisEmailData">
<tr><td><s:property value="emailId"/></td></tr>

<tr><td>
<s:checkbox fieldValue="%{#emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="#emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="thisEmailData.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="userEmails.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="#thisEmailData.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="#userEmails.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="%{#thisEmailData.emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="%{#userEmails.emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox fieldValue="emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>

<s:checkbox value="%{#emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="#emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="thisEmailData.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="userEmails.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="#thisEmailData.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="#userEmails.emailId" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="%{#thisEmailData.emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="%{#userEmails.emailId}" name="emailAddressesCB" theme="simple" ></s:checkbox>
<s:checkbox value="emailId" name="emailAddressesCB" theme="simple" >
</s:checkbox>
<s:property value="emailAddress"/>
</td></tr>
</s:iterator>
</td></tr>
</s:iterator>

从上面可以看出,值字段永远不会填充 emailId 的值。

我知道我缺少一些基本的东西。这是什么?

最佳答案

您可以执行以下操作。

<s:iterator value="EmailObjects">       
<s:checkbox name="emailAddressess" fieldValue="%{emailAddress}"
label="%{emailId}" >
</s:checkbox>
</s:iterator>

关于java - 从 Struts 2 中的对象 ArrayList 填充复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com