I create one test project with one XHTML file basing on primefaces-showcase as following:
Code: Select all
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:ft="http://primefaces.prime.com.tr/facestrace">
<f:view contentType="text/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Cache-Control" content="must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="Mon, 1 Aug 1999 10:00:00 GMT" />
<link rel="icon" href="#{request.contextPath}/favicon.ico" />
<h:outputScript name="jquery-1.4.4.min.js" library="scripts" target="head"/>
<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/favicon.ico" />
<ui:insert name="head">
<title>#{uimsg.sitename}</title>
</ui:insert>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold"/>
<h:inputText id="name" value="#{createBookBean.test}" />
<p:commandButton value="Submit" update="display"/>
<p:ajaxStatus style="width:16px;height:16px;">
<f:facet name="start">
<h:graphicImage value="../design/ajaxloading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
<h:outputText value="#{createBookBean.test}" id="display" />
<p:panel header="New Book">
<h:panelGrid columns="2">
<h:outputLabel value="Subject :" for="txt_title"></h:outputLabel>
<h:inputText id="txt_title" value="#{createBookBean.book.title}" required="true"/>
<h:outputLabel value="Author :" for="txt_author"></h:outputLabel>
<h:inputText id="txt_author" value="#{createBookBean.book.author}" required="true"/>
<p:commandButton value="New Add" action="#{createBookBean.createNew}" update="books" />
<p:ajaxStatus style="width:16px;height:16px;">
<f:facet name="start">
<h:graphicImage value="/resources/images/ajaxloading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</p:panel>
<br />
<p:dataTable id="books" value="#{createBookBean.books}" var="book">
<p:column>
<f:facet name="header">
<h:outputText value="Title" />
</f:facet>
<h:outputText value="#{book.title}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
<h:outputText value="#{book.author}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</f:view></html>
1: input some value in <h:inputText id="name" value="#{createBookBean.test}" />, and click <p:commandButton "Submit", no value shows in
<h:outputText value="#{createBookBean.test}" id="display" />
2: then input values in Book Section and click <p:commandButton value="New Add", then the information are shown in
<p:dataTable id="books" value="#{createBookBean.books}" var="book">
3: again, do the first step: input some value in <h:inputText id="name" value="#{createBookBean.test}" />, and click <p:commandButton "Submit",
this time, <h:outputText value="#{createBookBean.test}" id="display" /> shows the value.
If remove Book Section, the <p:commandButton "Submit" works correctly.
Why?
only one difference:
one button: <p:commandButton value="Submit" update="display"/> ---NO action
the other: <p:commandButton value="New Add" action="#{createBookBean.createNew}" update="books" /> --- contains action
is it the root cause or others? please help