p:rowEditor: add and immediately edit a row

UI Components for JSF
Post Reply
piace82
Posts: 8
Joined: 09 Feb 2011, 10:43

09 Feb 2011, 11:37

Hello,
I use p:rowEditor in a datatable.
I added a button to add a row. After the row is added I must click on the p:rowEditor icon to edit the cells.
How can I add a new row and go immediately to edit the form (without click on the row editor's icon)?

I have this datatable:

<p:dataTable id="indiceTesoreriaTable" styleClass="datatable"
value="#{targetInsertFormController.indiceTesoreriaList}" var="item"
rowEditListener="#{targetInsertFormController.rowEditMonthListener}">
.
.
.
<p:column rendered="#{!item.deleted}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.m12}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{item.m12}" size="4"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column rendered="#{!item.deleted}">
<p:rowEditor/>
</p:column>
<p:commandButton value="Aggiungi una nuova riga" action="#{targetInsertFormController.addRow(1)}" update="indiceTesoreriaTable"/>

and in the controller..:

@ManagedBean(name = "targetInsertFormController")
@ViewScoped
public class TargetInsertFormController implements Serializable {
.
.
.
public void rowEditMonthListener(RowEditEvent ree) {
((MonthBean) ree.getObject()).setEdited(true);
}

public void addRow(int index) {
MonthBean monthRow;
switch (index) {
case 1:
monthRow = new MonthBean();
indiceTesoreriaList.add(monthRow);
break;
}
.
.
}

crazy_mice
Posts: 1
Joined: 14 Feb 2011, 09:01

14 Feb 2011, 09:08

I do have the same problem.
I have a p:dataTable and want to add a new row just by clicking on an empty row, then the input text appear to add data direct to the table. And then, after inputted data successfully, a new empty row will appear again to input new data.
I wonder if i can use javascript to customize this or not?
My Code is:
<p:dataTable id="dTable" var="user" value="#{tableBean.listUsers}"
selection="#{tableBean.selectedUser}" rows="20"
>
<f:facet name="header">
List of Users - Add new row - selected row to delete by context menu (right-click on table to show menu)
</f:facet>
<p:column selectionMode="single" />
<p:column headerText="User Name">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{user.username}" /> </f:facet>
<f:facet name="input"> <h:inputText value="#{user.username}" /> </f:facet>
</p:cellEditor>
</p:column>

<p:column headerText="First Name">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{user.firstname}" /> </f:facet>
<f:facet name="input"><h:inputText value="#{user.firstname}" /> </f:facet>
</p:cellEditor>
</p:column>

<p:column headerText="Last Namer">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{user.lastname}" /> </f:facet>
<f:facet name="input"> <h:inputText value="#{user.lastname}" /> </f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Age">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{user.age}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{user.age}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor />
</p:column>
</p:dataTable>
<p:contextMenu for="dTable" >
<p:menuitem value="Add new row" ajax="false"
actionListener="#{tableBean.addRow}" update="dTable"/>
<p:menuitem value="Delete row" actionListener="#{tableBean.removeRow}" update="dTable" ajax="false" >
<f:setPropertyActionListener target="#{tableBean.selectedUser}" value="#{user}" />
</p:menuitem>
</p:contextMenu>

Could any one be able to help?

remmel
Posts: 4
Joined: 15 Feb 2011, 17:57

16 Feb 2011, 13:24

Hi,

In this post http://primefaces.prime.com.tr/forum/vi ... f=3&t=6175
someone uses a javascript to edit the last row of the datatable. Using jquery, he click on the last pencil.

Right now I'm looking for a way to know if the current item is the last one or not (my bad, varStatus is not existing for datatable) in order to use the rendered attribut to do something like that:


<p:outputText value="#{car.nombre}" rendered=#{i_varstatus.index!=list.length-1} />
<p:inputText value="#{car.nombre}" rendered=#{i_varstatus.index==list.length-1} />

Did you found a way to do it?

Remy

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests