简体   繁体   English

Java-Struts 1.2组合框问题

[英]Java -Struts 1.2 combobox question

I am using java (Struts 1.2). 我正在使用java(Struts 1.2)。 My first page is a login page. 我的第一页是登录页面。 After a successful login, the second page is displayed The second page contains a form in which one of the fields is a combo box. 成功登录后,将显示第二页。第二页包含一个表单,其中一个字段是一个组合框。 I want this combo box should be filled so that the user can select the option. 我希望此组合框应填充,以便用户可以选择该选项。

I have tried many methods, like using html:option collections, and html:optionsCollections etc. but it is showing errors like bean not found. 我尝试了许多方法,例如使用html:options集合和html:optionsCollections等。但是它显示了诸如未找到bean之类的错误。

Can any body give me a sample working code. 谁能给我一个示例工作代码。

Thanks 谢谢

<%
List< LabelValueBean> hourList = new ArrayList<LabelValueBean>();
pageContext.setAttribute("hourList", hourList);
%>

<html:select property="endhour">
    <html:options collection="hourList" property="value" labelProperty="label" />
<html:select>

The property on html:select is the one in your form which will be filled when the user selects something from the combobox. html:select上的属性是表单中的属性,当用户从组合框中选择某些内容时,该属性将被填充。

--- sorry couldn't format it to show the code clearly ---很抱歉,无法格式化它以清楚显示代码

The use of html tag required to be in html:form and that both must have an associated bean, you configure it in struts.xml. 必须在html:form中使用html标记,并且两者都必须具有关联的bean,您可以在struts.xml中对其进行配置。

<form-beans>
    <form-bean name="LoginForm"
        type="struts.forms.LoginForm" />
</form-beans>

<action  name="LoginForm" path="/logon" type="common.Logon"
        parameter="cmd">
        <forward name="error" path="/html/login/login.jsp?login_error=1" />
        <forward name="success" path="/login.do" />            
</action>

What I can tell you is this: 我能告诉你的是:

  • Once you successfully login (through your LoginAction in this example), let your action forward to another action which will populate your list. 成功登录后(通过本示例中的LoginAction ),让您的操作前进到另一个将填充您的列表的操作。
  • Populate your list and save it in the request (like so, request.setAttribute("contents", list) . Now forward your page to a JSP file. 填充列表并将其保存在请求中(例如request.setAttribute("contents", list)将页面转发到JSP文件。
  • On the JSP file, you will have to read your contents (as stored in request.setAttribute method) and do something of this effect: 在JSP文件上,您将必须读取contents (存储在request.setAttribute方法中),并执行以下操作:

Example: 例:

<html:select property="selectedValue">
    <html:options name="contents" />
</html:select>

More information on Struts HTML TagLib. 有关Struts HTML TagLib的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM