two <p.commandButton cannot work successfully in one page.

UI Components for JSF
Post Reply
xu_zhike1979
Posts: 1
Joined: 20 Nov 2010, 17:34

20 Nov 2010, 17:51

Hi, Team,
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>

but when try the two ajax button, found the behavior is too strange, the following step is my operation(first time access the page):
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

callahan
Posts: 768
Joined: 27 May 2010, 22:52

20 Nov 2010, 19:42

When the Submit button is clicked, the entire view is processed. This means that there will be validation errors that are currently not seen, as the page doesn't display validation errors. There are validation errors because the view contains required fields that are empty. The model isn't updated due to the validation errors. Use p:commandButtons process attribute to tell it which components to process.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests