【发布时间】:2012-09-25 15:30:30
【问题描述】:
在我的 JSF 页面上,我在 dataTable 中显示了一个简单的数据库表。我希望能够编辑此表中的行。作为解决方案,当您单击第一列中的值时,我会弹出一个对话框。我使用setPropertyActionListener 在我的支持bean 中设置当前行/实体。这似乎有效。但是,弹出窗口会在几分之一秒后消失。我不明白为什么会这样。有人有什么建议吗?
这是我的 dataTable 的 JSF 代码:(如您所见,我使用的是 PrimeFaces)
<h:form id="dataForm">
<p:dataTable value="#{misterBean.values}" var="value">
<p:column>
<h:commandLink value="#{value.name}" onclick="updateDlg.show()">
<f:setPropertyActionListener
target="#{misterBean.value}"
value="#{value}" />
</h:commandLink>
</p:column>
<!-- more columns -->
</p:dataTable>
</h:form>
以及对话框的 JSF 代码:
<p:dialog id="updateDialog" header="Update data" widgetVar="updateDlg">
<h:form id="updateForm">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="name" value="Name:" />
<p:inputText id="name" value="#{misterBean.value.name}" />
<h:outputLabel for="flag" value="Flag:" />
<p:selectBooleanButton id="flag"
value="#{misterBean.value.flag}"
onLabel="On"
offLabel="Off" />
<f:facet name="footer">
<p:commandButton id="submitButton"
value="Submit"
actionListener="#{misterBean.update}"
oncomplete="updateDlg.hide()"
update=":dataForm" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
backing bean 看起来像这样:
@Controller
@ManagedBean( name = "misterBean" )
@ViewScoped
public final class MisterBean {
private final MyService myService;
private final List<Value> values;
private Value value;
@Autowired
public MisterBean( final MyService myService ) {
this.myService = myService;
this.values = this.myService.loadValues();
this.value = new Value();
}
public List<Value> getValues() {
return this.values;
}
public Value getValue() {
return this.value;
}
public void setValue( final Value value ) {
this.value = value ;
}
public void update( final ActionEvent e ) {
this.myService.save( this.value );
this.value = new Value();
}
}
【问题讨论】:
-
你的 'updateDlg.show()' 的 JavaScript 代码怎么样?如果我错了,请告诉我,但 onClick 只能调用客户端 javascript 方法。与“updateDlg.hide()”相同的问题。
-
我在不同的页面上做了同样的事情,它在那里工作。无论如何:我实际上非常简短地看到了对话框,所以我猜
show()有效。我承认我真的不知道这是怎么回事。 -
您正在同步提交表单,而不是通过 ajax 异步提交。
标签: java jsf dialog primefaces