-1

我做了以下jsf页面。在我的托管 Bean 中,我想评估输入,但我没有得到值。

如果我按我的 commandLink,我不会得到任何值。当我使用命令按钮时,它可以工作:

<?xml version="1.0" encoding="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"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="../templates/common.xhtml">
    <ui:define name="pageTitle">Test</ui:define>
    <ui:define name="pageHeader">Test</ui:define>
    <ui:define name="body">
        <h:panelGroup id="messagePanel" layout="block">
            <h:messages errorStyle="color: red" infoStyle="color: green"
                layout="table" />
        </h:panelGroup>
        <h:form>
            <h:outputLabel value="#{bundle.SearchAdressLabel_name}"
                for="axname" />
             <h:inputText id="axname"
                    value="#tbaxController.name}"
                    title="#{bundle.SearchAdressTitle_name}" />
                     </h:panelGrid>
            <br />
            <br />
            <h:commandButton id="submit" value="#{bundle.SearchAdressLabel_cmdsearch}"  action="#{tbaxController.prepareList}">
        </h:commandButton>

            <h:commandLink action="#{tbaxController.prepareList}"
                value="#{bundle.SearchAdressLabel_cmdsearch}" immediate="true" />  
            <br />
            <br />
            <h:commandLink value="#{bundle.SearchAdressLabel_cmdclear}"
                type="reset" />
        </h:form>
    </ui:define>
</ui:composition>
</html>

这是我的MB的一部分:

@ManagedBean(name = "tbaxController")
@SessionScoped
public class tbaxController implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
            .getLogger(tbaxController.class);

    private Tbax current;
    private DataModel items = null;
    @EJB
    private TbaxFacade ejbFacade;
    private PaginationHelper pagination;
    private int selectedItemIndex;

    private String name;


    public tbaxController() {
    }

    public String getname() {
        // Get the field
        return searchAxart;
    }

    public void setname(String oname) {
        // Set the field this.searchAxart
        this.name = oname.trim();
    }

    ...

    public String prepareList() {
        logger.info("prepareList:" + name); **//null with commandLink!
        recreateModel();
        return "ADList";
    }

     ...

为什么我的 prepareList 方法没有通过 commandLink 获得任何值?

4

1 回答 1

1

immediate="true"使得 jsf 跨过流程验证和更新模型阶段。它直接跳转到调用应用程序阶段。这就是为什么您没有在模型上获得任何值的原因。尝试删除它,看看会发生什么。

于 2012-08-21T09:57:35.703 回答