Update datatable - without Id

UI Components for JSF
Post Reply
edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

31 Jan 2011, 22:00

When I update a datatable with Id it work's but when I update a table (without id) all my lines on the datatable are selected even being selectionMode="single". Why ?

Thank's.
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

jaideralba
Posts: 51
Joined: 06 Sep 2010, 23:01
Location: São Paulo - Brazil

01 Feb 2011, 14:42

How are you trying to update withou id? Are you using "@form" ?

Post the code please.
Mojarra 2.0.2 (FCS b10)
GlassFish 3.0.1
PrimeFaces 2.2.1

edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

01 Feb 2011, 15:05

Code: Select all

<p:dataTable value="#{bean.lista}"
                                                 selectionMode="single"
                                                 id="endTabela"
                                                 var="end"
                                                 selection="#{bean.person}"
                                                 update="endTabela"
                                                 >                                    

public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name="name", length=100, nullable=true)
    private String name;
I have a remove button. If i don´t update de datatable the selection="#{bean.person}" doesn´t work. If i update all my rows on the datatable are selected. :shock:

Code: Select all

<p:commandButton action="#{bean.remove}"
                                                     value="Remover" immediate="true">
                                    </p:commandButton>

public void remove(){
    list.remove(person);
}
If i set an Id (person.setId()) the datatable list a row and delet but i can´t do it because I will save on the DB with a auto-increment id.
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

jaideralba
Posts: 51
Joined: 06 Sep 2010, 23:01
Location: São Paulo - Brazil

01 Feb 2011, 15:24

Sorry, but I didn't understand it very well. I guess you don't need to use update="endTabela" in the dataTable, and even use the person.id

The remove() is working? This method is being executed when you click the button?

Take a look at the showcase example : http://www.primefaces.org/showcase/ui/d ... Single.jsf
it might help.
Mojarra 2.0.2 (FCS b10)
GlassFish 3.0.1
PrimeFaces 2.2.1

edudebom
Posts: 70
Joined: 14 Jan 2011, 18:01
Location: Brazil

01 Feb 2011, 17:39

I think I don´t need to use update but i'm trying to find a correct code.

<f:facet name="footer"> doesn´t work for me on 2.1. :?
Mojarra 2.1.6; GlassFish 3.1.2.2; PrimeFaces 4.0-SNAPSHOT
Brasil

mianor
Posts: 3
Joined: 09 Jun 2011, 15:23

09 Jun 2011, 15:35

Hi,

I have the same issue with primefaces 2.2.1
I use Spinner component with Ajax. For each change on the spinner I want to update a (primefaces) DataTable component. And I don't know why, each time I update datatable, all rows are selected even though selectionMode="single" and selection takes a parameter which is a POJO and not a list. This happens in a composite implementation.

Code: Select all

<h:form id="frm">
			<table>
				<tr>
					<td>
						<p:dataTable id="openingHoursTbl" var="oh" value="#{cc.attrs.openingHours}" rows="7"
			               selection="#{cc.attrs.selectedHours}" selectionMode="single"
			               onRowSelectUpdate="hoursTable"
			               style="width: 300px">
				
					        <p:column>
					            <f:facet name="header">
					                <h:outputText value="Day" />
					            </f:facet>
					            <h:outputText value="#{oh.displayedDays}" />
					        </p:column>
					
					        <p:column>
					            <f:facet name="header">
					                <h:outputText value="Opening Hours" />
					            </f:facet>
					            <h:outputText id="ohHeader" value="#{oh.displayedHours}" />
					        </p:column>
						</p:dataTable>
					</td>
					<td width="50"><h:outputText value=" " /></td>
					<td>
						<p:dataTable id="hoursTable" var="hour" value="#{cc.attrs.selectedHours.hours}" rows="7" style="width: 300px" emptyMessage="Closed">
					        <p:column>
					            <f:facet name="header">
					                <h:outputText value="Opening" />
					            </f:facet>
					            <p:spinner value="#{hour.fromHour}" maxlength="2" size="2" stepFactor="1" min="0" max="23">  
	                    			<p:ajax process="@form" update="#{cc.clientId}:frm:openingHoursTbl" event="change" />
	                			</p:spinner>
	                			<h:outputText value=" : " /> 
	                			<p:spinner value="#{hour.fromMinute}" maxlength="2" size="2" stepFactor="5" min="0" max="59">  
	                    			<p:ajax process="@form" update="#{cc.clientId}:frm:openingHoursTbl" event="change" />
	                			</p:spinner>
					        </p:column>
					
					        <p:column>
					            <f:facet name="header">
					                <h:outputText value="Closing" />
					            </f:facet>
					            <p:spinner value="#{hour.toHour}" maxlength="2" size="2" stepFactor="1" min="0" max="23">
	                    			<p:ajax process="@form" update="#{cc.clientId}:frm:openingHoursTbl" event="change" />
	                			</p:spinner>
	                			<h:outputText value=" : " />
	                			<p:spinner value="#{hour.toMinute}" maxlength="2" size="2" stepFactor="5" min="0" max="59">
	                    			<p:ajax process="@form" update="#{cc.clientId}:frm:openingHoursTbl" event="change" />
	                			</p:spinner>  
					        </p:column>
						</p:dataTable><br/>
						<h:commandButton value="Add">
							<f:ajax execute="@form" listener="#{cc.attrs.addRange}" render="hoursTable" event="click" />
						</h:commandButton>
					</td>
				</tr>
			</table>
		</h:form>
Here is what is sent during the Ajax call (one of the spinner changed):

Code: Select all

j_idt162:frm	j_idt162:frm
j_idt162:frm:openingHoursTbl_selection	0
j_idt162:frm:hoursTable:0:j_idt149	1
j_idt162:frm:hoursTable:0:j_idt151	5
j_idt162:frm:hoursTable:0:j_idt154	0
j_idt162:frm:hoursTable:0:j_idt156	0
javax.faces.ViewState	8248512111669847648:5360384544614039404
javax.faces.partial.ajax	true
javax.faces.source	j_idt162:frm:hoursTable:0:j_idt151
javax.faces.partial.execute	j_idt162:frm
javax.faces.partial.render	j_idt162:frm:openingHoursTbl
javax.faces.behavior.event	change
And here is the response received from the server (notice the tag in response: <input type="hidden" id="j_idt162:frm:openingHoursTbl_selection" name="j_idt162:frm:openingHoursTbl_selection" value="0,1,2,3,4,5,6" />):

Code: Select all

<partial-response>
	<changes>
		<update id="j_idt162:frm:openingHoursTbl">
			<div id="j_idt162:frm:openingHoursTbl" class="ui-datatable ui-widget"
				style="width: 300px">
				<table>
					<thead>
						<tr>
							<th id="j_idt162:frm:openingHoursTbl:j_idt139" class="ui-state-default">Day</th>
							<th id="j_idt162:frm:openingHoursTbl:j_idt142" class="ui-state-default">Opening
								Hours</th>
						</tr>
					</thead>
					<tbody id="j_idt162:frm:openingHoursTbl_data" class="ui-datatable-data">
						<tr id="j_idt162:frm:openingHoursTbl_row_0"
							class="ui-widget-content ui-datatable-even ui-selected ui-state-highlight">
							<td>Monday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:0:ohHeader">01:05 - 00:00 </span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_1"
							class="ui-widget-content ui-datatable-odd ui-selected ui-state-highlight">
							<td>Tuesday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:1:ohHeader">Closed</span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_2"
							class="ui-widget-content ui-datatable-even ui-selected ui-state-highlight">
							<td>Wednesday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:2:ohHeader">Closed</span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_3"
							class="ui-widget-content ui-datatable-odd ui-selected ui-state-highlight">
							<td>Thursday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:3:ohHeader">Closed</span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_4"
							class="ui-widget-content ui-datatable-even ui-selected ui-state-highlight">
							<td>Friday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:4:ohHeader">Closed</span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_5"
							class="ui-widget-content ui-datatable-odd ui-selected ui-state-highlight">
							<td>Saturday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:5:ohHeader">Closed</span>
							</td>
						</tr>
						<tr id="j_idt162:frm:openingHoursTbl_row_6"
							class="ui-widget-content ui-datatable-even ui-selected ui-state-highlight">
							<td>Sunday</td>
							<td>
								<span id="j_idt162:frm:openingHoursTbl:6:ohHeader">Closed</span>
							</td>
						</tr>
					</tbody>
				</table>
				<input type="hidden" id="j_idt162:frm:openingHoursTbl_selection"
					name="j_idt162:frm:openingHoursTbl_selection" value="0,1,2,3,4,5,6" />
			</div>
			<script type="text/javascript">widget_j_idt162_frm_openingHoursTbl = new
				PrimeFaces.widget.DataTable('j_idt162:frm:openingHoursTbl',{url:'/bt/admin/businessEdition.faces',formId:'j_idt162:frm',selectionMode:'single',instantSelect:true,onRowSelectUpdate:'j_idt162:frm:hoursTable'});</script>
		</update>
		<update id="javax.faces.ViewState">8248512111669847648:5360384544614039404</update>
	</changes>
	<extension primefacesCallbackParam="validationFailed">{"validationFailed":false}</extension>
</partial-response>
Thanks for your help

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests