为什么我的jsf< h:inputText>不要在bean类中设置值? [英] Why my jsf <h:inputText> dont set the value in bean class?

查看:97
本文介绍了为什么我的jsf< h:inputText>不要在bean类中设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JSF的<h:inputText>有问题,我试图在Bean类中设置变量的值,但<h:inputText> tag无法设置它的值.我是有关JSF的新手.

I have a problem about <h:inputText> of JSF, I'm trying to set value of a variable in a bean class but it can't set value by <h:inputText> tag. I'm a newbie about JSF.

我的jsp代码:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../style.css" />
<title>Tìm hồ sơ</title>
</head>
<body>
    <div id="content">
        <jsp:include page="header.jsp" />
        <h1>Nhập hồ sơ thí sinh - Kì tuyển sinh 2015</h1>
        <f:view>
                <h:form>
                    <font color="black"> Tìm hồ sơ: <br /></font>
                    <table>
                        <tr>
                            <td>SBD:</td>
                            <td><h:inputText id="sbd" value="#{hsinfo.fsbd}"
                                    required="true"></h:inputText></td>
                            <td><h:message for="sbd" /></td>
                        </tr>
                        <tr>
                            <td>Họ tên:</td>
                            <td><h:inputText id="ten" value="#{hsinfo.fname}"></h:inputText></td>
                        </tr>
                        <tr>
                            <td>Giới tính: <h:selectOneRadio id="gioitinh"
                                    value="#{hsinfo.fgioitinh}">
                                    <f:selectItem itemValue="M" itemLabel="Nam" />
                                    <f:selectItem itemValue="F" itemLabel="Nữ" />
                                </h:selectOneRadio>
                            </td>
                        </tr>
                        <div style="position: absolute;margin-top: 24px;margin-left: 654px;">
                            <h:commandButton
                                style="width:84px; height:84px;margin-top:-24px;"
                                action="#{hsinfo.findHS}" value="Tìm kiếm" immediate="true" />
                        </div>
                    </table>
                </h:form>
        </f:view>
    </div>
</body>
</html>

我的豆类:

package Beans;

public class hsinfo {

    private String fsbd;
    private String fname;
    private String fgioitinh;



    public String getFsbd() {
        return fsbd;
    }

    public void setFsbd(String fsbd) {
        this.fsbd = fsbd;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getFgioitinh() {
        return fgioitinh;
    }

    public void setFgioitinh(String fgioitinh) {
        this.fgioitinh = fgioitinh;
    }

}

我制作了另一个jsp和bean类,可以通过<h:inputText>标记成功设置值,但是我不知道为什么在这个jsp和bean类中它不起作用!

I made another jsp and bean class that successful to set value by <h:inputText> tag, but I don't know why it not work in this jsp and bean class!

推荐答案

您的问题是由<h:commandButton>上的immediate="true"引起的.

Your problem is caused by having immediate="true" on the <h:commandButton>.

<h:commandButton ... action="#{bean.action}" immediate="true" />

它将跳过对所有没有immediate="true"的输入字段的处理.

It will skip processing of all input fields which doesn't have immediate="true".

摆脱它.

<h:commandButton ... action="#{bean.action}" />

另请参见:

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆