开发者

<h:inputText inside <t:datatable not set

i am new to JSF.

i have a problem with tag my .jsp page is like this:

<h:form id="form1">
                <t:inputHidden id="primaryKey"
                    value="#{EditConfigurationBean.primaryKey}" forceId="true" />
                <t:inputHidden id="beanName"
                    value="#{EditConfigurationBean.beanName}" forceId="true" />
                <t:dataTable id="datatable" value="#{EditConfigurationBean.config}"  rowIndexVar="rowIndex" var="rowvar"
                    rowClasses="standardTable_Row1,standardTable_Row2" 
                    columnClasses="standardTable_Column1,standardTable_Column2,standardTable_Column3">
                        <h:column>
                            <f:facet name="header">
                                <h:panelGroup>
                                    <f:verbatim>
                                        <object width="0px" height="0px"></object>
                                    </f:verbatim>
                                    <h:outputText
                                        value="Entry Name" />
                                </h:panelGroup>
                            </f:facet>
                            <h:outputLabel value="#{rowvar.bean.name}"></h:outputLabel>
                        </h:column>
                        <t:column>
                            <f:facet name="header">
                                <h:panelGroup>
                                    <f:verbatim>
                                        <object width="0px" height="0px"></object>
                                    </f:verbatim>
                                    <h:outputText
                            开发者_如何学Go            value="Entry Value" />
                                </h:panelGroup>
                            </f:facet>
                            <h:inputText styleClass="inputText" value="#{rowvar.value}"></h:inputText>
                        </t:column>
                    </t:dataTable>
                        <t:htmlTag value="div" styleClass="commandBar">

        <h:commandButton onmouseover="over(this)" onmouseout="out(this)" action="#{EditConfigurationBean.back}" id="navigation" immediate="true" value="back" styleClass="commandButton" />

        <h:commandButton onmouseover="over(this)" onmouseout="out(this)" action="#{EditConfigurationBean.update}" value="Update" styleClass="commandButton" />

    </t:htmlTag>
            </h:form>

and my backbean code is:

public class ConfigurationEditBean{
    public String getInit(){
        try {
            config = loadConfig();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (config != null)
            this.entriesCount =this.config.size();
        return "";
    }
    private int primaryKey;
    private java.lang.String beanName;
    private int entriesCount;
    private List<ConfigurationFullEntry> config;

    public int getEntriesCount() {
        return entriesCount;
    }

    public void setEntriesCount(int entriesCount) {
        this.entriesCount = entriesCount;
    }

    public void setConfig(List<ConfigurationFullEntry> config) {
        this.config = config;
    }

    public int getPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(int primaryKey) {
        this.primaryKey = primaryKey;
    }

    public java.lang.String getBeanName() {
        return beanName;
    }

    public void setBeanName(java.lang.String beanName) {
        this.beanName = beanName;
    }
    private List<ConfigurationFullEntry> loadConfig() throws Exception{
        List<ConfigurationFullEntry> entriesList = new ArrayList<ConfigurationFullEntry>();
            //do load from DB
        return entriesList;
    }
    public List<ConfigurationFullEntry> getConfig() {
        return config;
    }
    public String update(){
        return "";
    }
    public String back(){
        return "";
    }
}

the problem is that page display correctly but when i am change value of one

tags and submit the form, corresponding setXXX of backbean is not called.

also when i have tried an inputtext tag outside of

wha's wrong about my codes? thanks in advance


Update: this is my generated HTML no nested form exist within it.:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="http://localhost:7001"><title>My JSF 'ConfigurationEditor.jsp' starting page</title></head><body><form id="j_id_id2" name="j_id_id2" method="post" action="/HealthMonitorConsole/ConfigurationEditor.jsf" enctype="application/x-www-form-urlencoded"><input type="hidden" id="primaryKey" name="primaryKey" value="0"><input type="hidden" id="beanName" name="beanName" value="com.pardis.healthMonitor.dm.service.ServiceBean"> <table><thead><tr><th scope="col">Name</th><th scope="col">Value</th></tr></thead><tbody id="j_id_id2:j_id_id5:tbody_element"><tr><td>Server</td><td><input id="j_id_id2:j_id_id5:0:j_id_id13" name="j_id_id2:j_id_id5:0:j_id_id13" type="text" value=""></td></tr><tr><td>arash</td><td><input id="j_id_id2:j_id_id5:1:j_id_id13" name="j_id_id2:j_id_id5:1:j_id_id13" type="text" value=""></td></tr></tbody></table><br> 
<input id="j_id_id2:j_id_id14" name="j_id_id2:j_id_id14" type="submit" value="Save" onclick="if(typeof window.getScrolling!='undefined'){oamSetHiddenInput('j_id_id2','autoScroll',getScrolling());}"> <input type="hidden" name="autoScroll"> <input type="hidden" name="j_id_id2_SUBMIT" value="1"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="8EgC7hvJoXWgMHaUZxk5rx66APlnNueyP32ajDxbvc/i5akMf2jX5SQ5BLInRDoWgWvcMUADuXlYwCWVxYrNWghZBdlolM+1zLfQTh4aUm4="></form>
<script type="text/javascript"><!--

    function getScrolling()
    {
        var x = 0; var y = 0;if (self.pageXOffset || self.pageYOffset)
        {
            x = self.pageXOffset;
            y = self.pageYOffset;
        }
         else if ((document.documentElement && document.documentElement.scrollLeft)||(document.documentElement && document.documentElement.scrollTop))
        {
            x = document.documentElement.scrollLeft;
            y = document.documentElement.scrollTop;
        }
         else if (document.body) 
        {
            x = document.body.scrollLeft;
            y = document.body.scrollTop;
        }
        return x + "," + y;
    }

//--></script>
</body></html>

i am writing every thing like tutorial examples but it does not work!


You need to ensure that exactly the same datamodel is preserved during the apply request values phase of the form submit as it was during the render response phase of the initial page display. A normal place is to do the preloading is the constructor of the backing bean.

public class Bean {
    private List<Item> items;

    public Bean() {
        items = itemDAO.list();
    }

    // ...
}

An alternative is to put the bean in the session scope, but this has more impact on user experience.

Since you're using Tomahawk, you can also just set the preserveDataModel attribute of the t:dataTable to true like so:

<t:dataTable preserveDataModel="true">

This will store the datamodel in the view's component tree (which in turn is stored in the session scope) so that exactly the same datamodel is available in the subsequent request.

See also:

  • Using Datatables
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜