我想使用上下文菜单从 h:panelGrid
中删除行:
<h:form id="components_list">
<h:panelGrid id="entrance_list" columns="2" style="margin-bottom:10px" cellpadding="5">
<c:forEach items="#{exit.comp}" var="listItem">
<p:outputLabel value="#{listItem.name}" />
<p:selectOneMenu style="width:125px">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
<f:selectItem itemLabel="PS4" itemValue="PS4" />
<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectOneMenu>
</c:forEach>
</h:panelGrid>
<p:contextMenu id="menuArquivos" for=":components_list:entrance_list">
<p:menuitem value="Move Up" icon="ui-icon-disk" update=":components_list:entrance_list"/>
</p:contextMenu>
</h:form>
管理bean:
@Named
@ViewScoped
public class Exit implements Serializable
{
private List<EntranceComponentsObj> comp = new ArrayList<EntranceComponentsObj>();
public void onSelect(SelectEvent event)
{
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", event.getObject().toString()));
}
public void onUnselect(UnselectEvent event)
{
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Unselected", event.getObject().toString()));
}
public void onReorder()
{
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "List Reordered", null));
}
public void addDelay()
{
comp.add(new EntranceComponentsObj("Delay", "Sensor"));
}
public void addSensor()
{
comp.add(new EntranceComponentsObj("Sensor", "Sensor"));
}
public void addInductionLoop()
{
comp.add(new EntranceComponentsObj("Induction Loop", "Sensor"));
}
public void addDatabaseCheck()
{
comp.add(new EntranceComponentsObj("Database Check", "Sensor"));
}
public void addWhiteListCheck()
{
comp.add(new EntranceComponentsObj("White List Check", "Sensor"));
}
public void addBlackListCheck()
{
comp.add(new EntranceComponentsObj("Black List Check", "Sensor"));
}
public List<EntranceComponentsObj> getComp()
{
return comp;
}
public void setComp(List<EntranceComponentsObj> comp)
{
this.comp = comp;
}
public void save()
{
addMessage("Success", "Data saved");
}
public void update()
{
addMessage("Success", "Data updated");
}
public void deleteRow()
{
comp.remove(new EntranceComponentsObj("Delay", "Sensor"));
}
public void addMessage(String summary, String detail)
{
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
但是当我调用Context Menu并选择删除时没有任何反应。可能是因为找不到Java对象。实现这个的正确方法是什么?