JSF将参数传递给另一个视图
我有一个页面,其中有一个表,带有指向编辑项页面的链接JSF将参数传递给另一个视图,jsf,parameters,Jsf,Parameters,我有一个页面,其中有一个表,带有指向编辑项页面的链接 <h:dataTable rendered="#{cc.attrs.data.size() ne 0}" border="1" value="#{cc.attrs.data}" var="req"> <h:column> <f:facet name="header">Тема</f:facet> <h:link outcome
<h:dataTable rendered="#{cc.attrs.data.size() ne 0}" border="1" value="#{cc.attrs.data}" var="req">
<h:column>
<f:facet name="header">Тема</f:facet>
<h:link outcome="/pages/request" value="#{req.topic}">
<f:param name="reqId" value="#{req.id}"/>
</h:link>
</h:column>
...
和支持bean:
@ManagedBean(name = "requests")
@RequestScoped
public class Requests {
private Request currentRequest;
... getters setters
问题是currentRequest为null,并且在方法getAsString中的转换器中,对象值参数为null;
因此,编辑页面上的所有字段均为空
我不知道哪里出了什么问题,我也试过@FacesConverter,但当我读到BalusC的文章时,我不能使用@Inject
UPD:我通过为currentRequest字段添加getter方法来解决这个问题:
检查currentRequest是否为null,然后我从请求URL获取参数,因为URL仍然有?reqId=。。参数,然后从边界获取请求:
public Request getCurrentRequest() {
if(currentRequest==null) {
String param=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("reqId");
if(param!=null && !param.isEmpty()){
Long id=Long.valueOf(param);
currentRequest=boundary.getRequest(id);
}
else {
System.out.println("Request parameter is null");
}
}
return currentRequest;
}
但是我认为getter中的逻辑不是一个好主意:o我想补充:这在我的localhost环境中很好,但在其他计算机环境中不起作用。在这两种情况下,我都使用Glassfish+derby,我不明白为什么它使用getAsString,正如我看到的,getAsObject中的所有日志均被忽略。您已确认参数已从源页面正确传输,并且RequestBoundary的注入正在正确进行?1我已在getAsString和getAsObject方法中添加了日志,并且仅来自getAsString的日志显示RequestBoundary已正确注入。2在本地主机上,它工作正常且参数从一页传递到另一页并转换,但在另一台计算机上存在问题
@ManagedBean(name = "requests")
@RequestScoped
public class Requests {
private Request currentRequest;
... getters setters
public Request getCurrentRequest() {
if(currentRequest==null) {
String param=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("reqId");
if(param!=null && !param.isEmpty()){
Long id=Long.valueOf(param);
currentRequest=boundary.getRequest(id);
}
else {
System.out.println("Request parameter is null");
}
}
return currentRequest;
}