浏览 7116 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2005-04-27
1.两个POJO,一个考试卷,一个是选择题,多对多的关系! 2.业务层方法把一张考试卷的所有选择题取出来,然后return一个List对象singles(里面是选择题) 3.Action调用业务方法后把取到的List对象存到session中 4.打印选择题的jsp页面,把session中的List对象打印出来 <html:form action="subSingles.do"> <logic:iterate id="single" name="singles"> <table border="1" width="100%"> <tr> <td width="15%"> Topic: </td> <td width="85%"> <bean:write name="single" property="topic"/> </td> </tr> <tr> <td align="left" width="15%"> <html:radio property="answer0" value="A"/>A: </td> <td width="85%"> <bean:write name="single" property="answerA"/> </td> </tr> <tr> <td width="15%"> <html:radio property="answer0" value="B"/>B: </td> <td width="85%"> <bean:write name="single" property="answerB"/> </td> </tr> <tr> <td width="15%"> <html:radio property="answer0" value="C"/>C: </td> <td width="85%"> <bean:write name="single" property="answerC"/> </td> </tr> <tr> <td width="15%"> <html:radio property="answer0" value="D"/>D: </td> <td width="85%"> <bean:write name="single" property="answerD"/> </td> </tr> </table> </br> </logic:iterate> </html:form> 打印效果见附件。。。现在我的问题是此页面有10道选择题,我如果想把10道题做完,然后把答案传到formBean里的话,这个formBean该如何设计啊?定义10个String型的radioValue,还是一个数组?按照上面两种formBean的方法,本页中的radio按钮的property怎么写? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2005-04-28
这个问题我可以再详细点提问,就是类似与像
<html:radio property="answer0" value="D"/> 这样的标签,如果里面的property属性里面的值我不想写成一个定值,该怎么办?我的办法是在JSP页面里面定义一个String属性的字段,然后代替上面的property,那应该怎么写呢? <html:radio property="<%=myStr%>" value="D"/> 还是 <html:radio property='<%=myStr%>' value="D"/> 我的写法是不是有问题啊,这样写不报错,但是运行的时候页面上什么都没有,是个空页! |
|
返回顶楼 | |
发表时间:2005-04-28
可以用Map-backed ActionForm来做。或者是用javascript取得数据,来拼接字符串,最后在java中解析,不过这样稍微麻烦点。你可以试下第一种方法。
|
|
返回顶楼 | |
发表时间:2005-04-28
谢谢楼上兄弟指点,问题已经解决!
fromBean构建方法 public class SubSinglesForm extends ValidatorForm { protected Map map = new HashMap();; public void setValue(String key, Object value); { map.put(key, value);; } public Object getValue(String key); { return map.get(key);; } JSP页面显示办法 <logic:iterate id="single" name="singles" [color=red]indexId="ctr"[/color]> <table border="1" width="100%"> <tr> <td align="left" width="15%"> <html:radio property=[color=red]'<%= "value(answer"+ctr+");" %>'[/color] value="A"/>A: </td> <td width="85%"> <bean:write name="single" property="answerA"/> </td> </tr> Action中获得formBean的方法: SubSinglesForm subSinglesForm = (SubSinglesForm); form; String answer1=(String); subSinglesForm.getValue("answer1");; |
|
返回顶楼 | |
发表时间:2005-04-30
不客气,注意,用map的话,structs就不能自动为你进行类型转换了,你需要手工获取后再人为进行转换。
|
|
返回顶楼 | |
发表时间:2005-06-17
我个人感觉还是偏向于用 list-backed formbean,更oo一些吧
|
|
返回顶楼 | |