java - 使用 jsf 标签发送参数豆
问题描述
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="New categorie"></h:outputText>
<h:inputText value="${categorieBean.categorie.name}"></h:inputText>
<h:commandButton value="Add categorie" action="#{categorieBean.dodajKategoriju}">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
</h:panelGrid>
<h:dataTable value="${categorieBean.categories}" var="categor">
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="${categor.name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">DELETE</f:facet>
<h:commandButton value="Delete-${categor.id}" action="#{categorieBean.obrisiKategoriju()}"
style="width: 64px;background-color: green;color: white;border: none;height: 27px;border-radius:
5px;">
<f:ajax render="@form" execute="@form"></f:ajax>
<f:param value="${categor.id}" name="id"></f:param>
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
</ui:composition>
</html>
@ManagedBean(name="categorieBean")
@SessionScoped
public class CategorieBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7281388938441323040L;
private List<Categorie> categories=new ArrayList<Categorie>();
private Categorie categorie=new Categorie();
public CategorieBean() {
// TODO Auto-generated constructor stub
}
public List<Categorie> getCategories() {
categories=CategorieDAO.readAll();
return categories;
}
public void setCategories(List<Categorie> categories) {
this.categories = categories;
}
public Categorie getCategorie() {
return categorie;
}
public void setCategorie(Categorie categorie) {
this.categorie = categorie;
}
public String obrisiKategoriju() {
System.out.println("hocu da obrisem kategoriju");
HttpServletRequest req=(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println(req.getParameter("id"));
Map<String,String> mapa=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
for(Entry<String,String>pom:mapa.entrySet()) {
System.out.println(pom.getKey()+" "+pom.getValue());
}
if(mapa.containsKey("id")) {
System.out.println("Usao sam");
int id=Integer.parseInt(mapa.get("id"));
CategorieDAO.delete(id);
}
return "";
}
public String dodajKategoriju() {
CategorieDAO.insert(categorie);
return "";
}
}
当我打印 requestparammap 的值时,我没有在方法 obrisiKategoriju() 中将 id 参数发送到 Bean 我只得到 j_idt6 j_idt6 j_idt6:j_idt9 j_idt6:j_idt11:0:j_idt17 Delete-1 javax.faces.ViewState 9066186310981453487:-225522103390500738 有人有想法吗?我有另一个 Bean,但它工作得很好,有了这些它没有,我尝试了一切
解决方案
推荐阅读
- javascript - 在同一页面上的多个位置显示复选框总数
- node.js - 我需要知道如何使用 vue.js 添加分页?
- batch-file - 批处理文件未被识别为内部或外部命令
- python - 寻找一个简单的容器来存储带时间码的未压缩 YUV 视频
- python - Python 3的`map`函数中的`int`参数是什么?
- c# - c#如何使用ninject注入对WebAPI的自定义处理程序的依赖
- kotlin - 属性的 Kotlin 命名约定
- react-native - React Native 离线位置分享应用
- python - TypeError:'int'对象在python中没有属性'__getitem__'
- django - Django:如何将 URL 请求路由到 django.contrib.admin 函数