[英]Updating row on complete of <p:ajax event=“cellEdit”>
I want to update cellValue in same row. 我想更新同一行中的cellValue。 I followed the sugestions of BalusC Updating entire <p:dataTable> on complete of <p:ajax event="cellEdit">
我遵循了BalusC的建议, 在完成<p:ajax event =“ cellEdit”>之后更新整个<p:dataTable>
After all my code perform 2 Requests. 毕竟我的代码执行2个请求。 The secound one makes a full page Reload and all data will reseted.
第二个文件将重新加载整页,所有数据将被重置。
I also tried <p:remoteCommand name="updateTable" process="@this" update="kAbnrTbl" />
following this suggestion. 我也按照这个建议尝试了
<p:remoteCommand name="updateTable" process="@this" update="kAbnrTbl" />
。 Using ap:remoteCommand to update ap:dataTable 使用ap:remoteCommand更新ap:dataTable
Here is JSF Page: 这是JSF页面:
<h:form id="kalkEditForm">
<p:outputPanel id="dropArea">
<p:remoteCommand name="updateTable" update="kAbnrTbl" />
<p:dataTable id="kAbnrTbl" value="#{tableBean.data}" var="data" editable="true" editMode="cell">
<p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" oncomplete="updateTable()"/>
<p:column headerText="Col1">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{data.col1}" /></f:facet>
<f:facet name="input"><p:inputText value="#{data.col1}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Col2">
<h:outputText value="#{data.col2}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
And here Bean: 在这里Bean:
@ManagedBean(name="tableBean")
@ViewScoped
public class TableBean {
public TableBean() {
RowData entry = new RowData("a1", "b1");
entries.add(entry);
entry = new RowData("a2", "b2");
entries.add(entry);
entry = new RowData("a3", "b3");
entries.add(entry);
}
public class RowData {
private String col1;
private String col2;
public RowData(String col1, String col2) {
this.col1 = col1;
this.col2 = col2;
}
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
public String getCol2() {
return col2;
}
public void setCol2(String col2) {
this.col2 = col2;
}
}
private final ArrayList<RowData> entries = new ArrayList<RowData>();
public List<RowData> getData() {
return entries;
}
public void onCellEdit(CellEditEvent event) {
final DataTable dataTable = (DataTable)event.getComponent();
RowData data = (RowData) dataTable.getRowData();
data.setCol2("changed");
}
} }
I have no idea what is wrong with the code. 我不知道代码有什么问题。 Why perform
<p:remoteCommand ...
the second Request. 为什么要执行
<p:remoteCommand ...
第二个请求。
Using:Primface 5.3 使用:Primface 5.3
Back to the beginning point. 回到起点。 If I don't use
<p:remoteCommand name="updateTable" update="kAbnrTbl" />
hack, it works ok but I have to press the refreshButton . 如果我不使用
<p:remoteCommand name="updateTable" update="kAbnrTbl" />
hack,它可以正常工作,但我必须按下refreshButton 。 If I use the hack I have 2 Requests and a full page reload. 如果我使用黑客程序,则会有2个请求和整页重新加载。 There must be a tiny typo or something that I overlook.
必须有一个很小的错别字或我忽略的东西。
Here the code without the hack. 这里的代码没有hack。
<h:form id="kalkEditForm">
<p:outputPanel id="dropArea">
<!-- <p:remoteCommand name="updateTable" update="kAbnrTbl" /> -->
<p:dataTable id="kAbnrTbl" value="#{tableBean.data}" var="data" editable="true" editMode="cell">
<p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" update="kAbnrTbl"/>
<!-- <p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" oncomplete="updateTable()"/> -->
<p:column headerText="Col1">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{data.col1}" /></f:facet>
<f:facet name="input"><p:inputText value="#{data.col1}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Col2">
<h:outputText value="#{data.col2}" />
</p:column>
</p:dataTable>
</p:outputPanel>
<p:commandButton id="refreshButton" value="Redisplay" update="kAbnrTbl" />
</h:form>
我使用event =“ rowEdit” ,这对我有用 。
<p:ajax event="rowEdit" listener="#{tableBean.onCellEdit}" oncomplete="updateTable()" />
Following the note from user3821232, the workaround is to be used instead of "celleditor" "inplace" in conjunction with a standard <p:ajax..
call. 遵循user3821232的注释后,将替代方法与标准
<p:ajax..
调用结合使用,而不是使用“ celleditor”“ inplace”。
Here you can see the workaround. 在这里您可以看到解决方法。
xthml: xthml:
<h:form id="kalkEditForm">
<p:outputPanel id="dropArea">
<p:dataTable id="kAbnrTbl" value="#{tableBean.data}" var="data" editable="true" editMode="cell" rowIndexVar="row">
<p:column headerText="Col1" id="col1" sortBy="#{data.col1}" sortable="true">
<p:inplace>
<f:facet name="output"><h:outputText value="#{data.col1}" /></f:facet>
<f:facet name="input">
<p:inputText value="#{data.col1}" >
<p:ajax event="blur" process="@this" listener="#{tableBean.updateData(row, 'col1')}" update="kAbnrTbl"/>
</p:inputText>
</f:facet>
</p:inplace>
</p:column>
<p:column headerText="Col2">
<h:outputText id="col2" value="#{data.col2}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
Bean: 豆角,扁豆:
@ManagedBean(name="tableBean")
@ViewScoped
public class TableBean {
private static final Logger logger = Logger.getLogger(TableBean.class);
public TableBean() {
RowData entry = new RowData("a1", "b1");
entries.add(entry);
entry = new RowData("a2", "b2");
entries.add(entry);
entry = new RowData("a3", "b3");
entries.add(entry);
}
public class RowData {
private String col1;
private String col2;
public RowData(String col1, String col2) {
this.col1 = col1;
this.col2 = col2;
}
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
public String getCol2() {
return col2;
}
public void setCol2(String col2) {
this.col2 = col2;
}
}
private final ArrayList<RowData> entries = new ArrayList<RowData>();
public List<RowData> getData() {
return entries;
}
public void updateData(Integer row, String colName){
logger.debug(String.format("updateData called row:%d colName %s", row, colName));
RowData data = getData().get(row);
data.setCol2("changed");
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.