我有一个弹出窗口,您必须在其中为pc选择组件。每个组件都包含一个标签和一个下拉列表,其中包含数据库中所有选定的组件。列表旁边有一个"添加"按钮,单击后会弹出另一个弹出窗口,当用户在列表中找不到他想要的内容时会使用该按钮。add函数调用一个方法,该方法检查用户的输入是否存在已存在的输入,如果没有则添加。我的问题是:我找不到刷新更新后的列表的解决方案。我正在尝试使用<p:ajax />
,但一直出现找不到组件错误。
---HTML代码----
<form id="dialog">
<h:outputText value="Computer: " styleClass="dialog-labels" />
<ul style="list-style-type: none">
<li>
<div class="dialog-container">
<h:outputLabel value="Processor: " style="float:left;" />
<p:selectOneMenu id="procs" filterFunction="true" filterMatchMode="true" styleClass="dialog-dropdown-list" style="width:15em;">
<f:selectItem itemLabel="Select Processor" itemValue="" noSelectionOption="true" />
<f:selectItems id="list" value="#{javaHTMLConnection.procList}" />
</p:selectOneMenu>
<p:commandButton value="Add" id="addProc" styleClass="dialog-buttons" onclick="PF('addProcBox').show();" style="font-size: 10px;" />
<h:form id="popUp">
<p:dialog header="Add Processor" widgetVar="addProcBox" height="200" width="180" draggable="false" resizable="false" style="font-size:13px;">
<h:outputLabel value="Processor: " style="float:left;" />
<p:inputText id="procInput" value="#{components.procID}"/>
<p:growl id="growl" life="10000" />
<p:commandButton value="Save" styleClass="dialog-bottom-buttons" action="#{components.addProcessor()}" update="growl" onclick="PF('addProcBox').hide();" style="font-size: 10px;" />
<p:ajax listener="#{javaHTMLConnection.onAdd()}" update=":dialog:list" />
<p:commandButton value="Cancel" id="CancelAddProc" styleClass="dialog-bottom-buttons" onclick="PF('addProcBox').hide();" style="font-size: 10px;" />
</p:dialog>
</h:form>
</div>
</li>
</form>
----JavaHTML连接----
public void onAdd()
{
if(components.addProcessor()==true)
{
components.getAllComponents();
}
}
----组件(Java代码)----
public boolean addProcessor()
{
try
{
db.openDatabase();
db.con.setAutoCommit(false);
if (!db.ifExists("processor.name", "processor", procID))
{
db.Entry("processor", procID);
addMessage("Success ! Your input has been saved");
return true;
}
else
{
addMessage("Error, the input already exists");
}
}
catch (SQLException e)
{
try
{
db.con.rollback();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
finally
{
try
{
db.con.setAutoCommit(true);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return false;
}
附言:不要介意命名,因为当它被发现时,一切都将变得通用,因为我需要将其适应另外15个组件
正如Emil已经提到的,嵌套表单是一件非常糟糕的事情,应该立即处理掉。
此外,正如Emil所建议的,这种错误消息通常与不正确的组件选择器有关。这主要是因为选择器中缺少父命名容器。使用一些调试工具确定正确的id,或者,而不是
<p:ajax listener="#{javaHTMLConnection.onAdd()}" update=":dialog:list" />
尝试使用此线程中建议的一些解决方案:Primefaces-无法在数据表之外找到标识符为的组件
我个人更喜欢使用以下语法,它依赖于在各种命名容器中搜索id的素数面方法:
<p:ajax listener="#{javaHTMLConnection.onAdd()}" update=":#{p:component('list')}" />
首先,您有嵌套的表单,应该去掉它。
至于这个问题,你应该检查特定的html元素(例如使用firebug)来找出它的id。