JSP页面值未传递或填充到setter和getter

时间:2012-07-09 12:28:31

标签: java jsp struts2

我的jsp页面,我将数据发送到javabean:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<%@taglib uri="/struts-tags" prefix="s" %>
<%@taglib uri="/struts-dojo-tags" prefix="sx" %>
<%@page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<sx:head parseContent="true" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Set the Leaves </title>
<script language="JavaScript" src="../Advance_Academic_ERP/css/Ck_Effect.js"></script>
<link rel="stylesheet" type="text/css" media="all"
    href="../Advance_Academic_ERP/css/jsDatePick_ltr.min.css" />
<script type="text/javascript"
    src="../Advance_Academic_ERP/css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
    useMode:2,
    target:("fromDate"),
    dateFormat:"%d-%m-%Y"
    });

new JsDatePick({
    useMode:2,
    target:("toDate"),
    dateFormat:"%d-%m-%Y"
    }); 
};
</script>

<script type="text/javascript">
function display(val) {
    var o = document.getElementById('name1');
    var b = document.getElementById('leaveNo1');
    (parseInt(val) == '5' || parseInt(val)=='6')? o.style.display = 'block' : o.style.display = 'none';
    (parseInt(val) == '5' || parseInt(val)=='6')? b.style.display = 'block' : b.style.display = 'none';
    }
</script>
</head>

<body>

<s:form action="LeaveSetterAction" name="leave" validate="true">

<s:select label="Type Of Holiday/Leave*" 
            headerKey="-1" headerValue="Select Type"
            list="#{'1':'National Holidays', '2':'Weekly Holidays', '3':'Local Holidays', '4':'Situational Holidays', '5':'Seek Leaves', '6':'Personal Leaves'}" 
            name="leaveType" id="leaveType" onchange="display(this.value);"/>

    <table id="name1" style="display: none;">
      <tr>
        <td>Name</td>
        <td><input type="text" name="name" id="name"></td>
      </tr>
    </table>

    <table id="leaveNo1" style="display: none;">
      <tr>
        <td>No Of Alloted Leaves</td>
        <td><input type="text" name="leaveNo" id="leaveNo"></td>
      </tr>
    </table>

<s:textfield name="fromDate" label="From date*" key="fromDate" id="fromDate"></s:textfield>

<s:textfield name="toDate" label="To date*" key="toDate" id="toDate"></s:textfield>

<s:textfield name="difference" label="Duration" key="difference" id="difference" readonly="readonly"></s:textfield>

<s:textarea name="desc" label="Description*" key="desc" onmouseover="setDifference(this);"></s:textarea>

<s:submit align="center"></s:submit> <s:reset align="center"></s:reset>

</s:form>

</body>
</html>

我的javabean页面,我应该得到数据:

package abc.Model;

public class SetLeave {

    String leaveType;
    String name;
    String leaveNo;
    String fromDate;
    String toDate;
    String difference;
    String desc;

    public String getLeaveType() {
        return leaveType;
    }
    public void setLeaveType(String leaveType) {
        this.leaveType = leaveType;
    }
    public String getName() {
        System.out.println(name);
        return name;

    }
    public void setName(String name) {
        this.name = name;
    }
    public String getLeaveNo() {
        System.out.println(leaveNo);
        return leaveNo;
    }
    public void setLeaveNo(String leaveNo) {
        this.leaveNo = leaveNo;
    }
    public String getFromDate() {
        return fromDate;
    }
    public void setFromDate(String fromDate) {
        this.fromDate = fromDate;
    }
    public String getToDate() {
        return toDate;
    }
    public void setToDate(String toDate) {
        this.toDate = toDate;
    }
    public String getDifference() {
        return difference;
    }
    public void setDifference(String difference) {
        this.difference = difference;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
}

我在一些获取空值的文本字段上使用javascript 请帮帮我。 提前致谢。

1 个答案:

答案 0 :(得分:0)

<s:textfield name="difference" label="Duration" key="difference" id="difference" disabled="true"></s:textfield>

在此字段中,您已禁用=“true”,因此发送到Model / Bean的值显然为null。

<s:textfield name="difference" label="Duration" key="difference" id="difference" disabled="true"></s:textfield>

<s:hidden name="difference"/>

如果要向bean发送值。如果仍然出现错误,请回复。

好的,完成并回复..

<table id="name" style="display: none;">
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name"></td>
</tr>
</table>

<table id="leaveNo" style="display: none;">
<tr>
<td>No Of Alloted Leaves</td>
<td><input type="text" name="leaveNo" id="leaveNo"></td>
</tr>
</table>

在上述两种情况下,您对表和文本字段都使用相同的ID,将表的id更改为name1和leaveNo1并尝试。我想这是唯一的问题。

您的解决方案在下面的代码中粘贴并享受。

<s:textfield name="difference" label="Duration" key="difference" id="difference" readonly="readonly"></s:textfield>