【发布时间】:2014-05-28 19:26:17
【问题描述】:
我有一个 javascript 代码可以清除表单的所有 p:inputText(在 p:commandButton 操作之后)。问题是p:selectOneMenu 在它被选中的选项中仍然有f:selectItem 被选中。 我需要将值放在每个p:selectOneMenu 的第一个 f:selectItem。
我该怎么做?如何清除选定的值?
java脚本代码:
<script type="text/javascript">
function limpiarForm()
{
document.getElementById("formularioAltas").reset();
}
</script>
formularioAltas 是表单 ID。
p:commandButton的代码:
<p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" oncomplete="limpiarForm()" />
并且该代码不会重置(我不想清除值,我只想选择第一个选项)p:selectOneMenu 的值
这里是:
<h:outputText value="Estado de la refacción" />
<p:selectOneMenu value="#{altasBean.refaccion.estado}">
<f:selectItem itemLabel="..." itemValue="0" />
<f:selectItem itemLabel="Ok" itemValue="Ok" />
<f:selectItem itemLabel="Reparar" itemValue="Reparar" />
<f:selectItem itemLabel="Sospechoso" itemValue="Sospechoso" />
</p:selectOneMenu>
豆子:
private RefaccionBean refaccion = null;
/**
* Get the value of refaccion
*
* @return the value of refaccion
*/
public RefaccionBean getRefaccion() {
return refaccion;
}
/**
* Set the value of refaccion
*
* @param refaccion new value of refaccion
*/
public void setRefaccion(RefaccionBean refaccion) {
this.refaccion = refaccion;
}
public void agregarRefaccion() {
I did a lot of things here...
And after those things i clear the p:inputText with the javascript code
-> After that i want to set the values of the p:selectOneMenu in the fist f:selectItem
}
【问题讨论】:
-
您想用 javascript 清除值吗?到目前为止,您介意发布您的代码吗? :)
-
我用 javascript 清除了 p:inputText。但我想知道如何在第一个 f:selectItem 中设置 p:selectOneMenu。我只想知道如何去做,不管是 javascript 还是其他东西。纯 JSF 应该更好。
-
好吧,让我看看我能做什么
-
我只需清除操作方法中我想要的任何内容,并使用命令按钮中的更新属性更新受影响的组件。如果您发布您的 xhtml 和 bean 代码,我可以向您展示如何做到这一点。
-
当然让我放一部分代码:)
标签: java jsf primefaces selectonemenu