我有一个数据表,它显示基于List <>的各种实体.当我选择一个单元格进行编辑时,我希望能够以某种方式获取实体以便更新它.当然有event.getRowIndex,然后我可以使用List <>,但这并不总是方便的.是否有另一种方法可以从CellEditEvent获取实体?
我在valueChangeListener上遇到了问题.我在Weblogic 6.0上使用JSF 1.2.
我有一个页面,页面顶部有2个单选按钮,名称为Name1和Name2.单击Name1时,单选按钮下方将显示Name1详细信息(大约30个字段),单击Name2时,将显示Name2详细信息.现在,用户可以更新单击的命名详细信息.例如,用户单击Name1并更改地址字段,然后单击Name2并更改Name2的年龄.当用户单击Name1时,地址应显示为使用新值更新,并且当用户单击Name2时,应再次更新年龄.
我使用valueChangeListener来解决它,因为我需要更改事件的旧值和新值.问题是,当在VALIDATION阶段结束时调用valueChangeListener时,我没有在valueChangeListener方法中获取Name1字段的更新地址.有人可以帮我解决问题吗?
我想使用部分处理但它在我的代码中不起作用.有人知道为什么吗?
<h:form id="frmVehicle" prependId="false">
<p:toolbar styleClass="form_toolbar">
<p:toolbarGroup>
<p:commandButton id="save" process="@(form :not(.noprocess))" ajax="false" value="#{uimsgs.save}" action="#{vmsVehicleActionBean.save()}"
</p:toolbarGroup>
</p:toolbar>
<p:messages id="vmsgs" severity="error,warn" autoUpdate="true" />
<p:tabView id="tabViewSections" orientation="left" styleClass="ses-ui-tabs-left">
<p:tab title="#{vms_uimsgs['vehicle.tab.data']}">
<p:panelGrid id="gridHeader" columns="4" columnClasses="form-label,form-input,form-label,form-input" styleClass="form-grid" >
<p:outputLabel for="kmStatus" value="#{vms_uimsgs['vehicle.kmStatus']}" />
<p:inputText id="kmStatus" value="#{vmsVehicleActionBean.vehicle.kmStatus}"/>
<p:outputLabel for="powerKw" value="#{vms_uimsgs['vehicle.power']}" />
<p:inputText id="powerKw" styleclass="noprocess" value="#{vmsVehicleActionBean.powerKw}">
<p:ajax event="keyup" update="powerPs" />
</p:inputText>
<p:outputLabel value="kw" />
<p:inputText id="powerPs" styleclass="noprocess" value="#{vmsVehicleActionBean.powerPs}">
<p:ajax event="keyup" update="powerKw" />
</p:inputText>
<p:outputLabel value="ps" />
</p:panelGrid>
</p:tab>
</p:tabView>
</h:form>
Run Code Online (Sandbox Code Playgroud)
两个setter(kw&ps)仍在处理中.任何的想法?
我在我的项目中使用JSF.我正在使用PrimeFaces的上下文菜单.我看到p:menuItem我们有action,actionListener,onclick方法.所以我的问题是:什么时候我都用action,actionListner,onclick,什么是执行的顺序?
HI,
请参阅以下代码:
<h:selectOneMenu id="countries" value="#{countryBean.selectedCountry}" onchange="submit()
valueChangeListener="#{countryBean.changeCountry}">
<f:selectItems value="#{countryBean.countries }" />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
支持Bean
public void changeCountry(ValueChangeEvent event){
String newValue = (String)event.getNewValue();
String oldValue = (String)event.getOldValue();
System.out.println("New Value : " + newValue);
System.out.println("Old Value : " + oldValue);
if ("1".equals(newValue)){
this.countries = new ArrayList<SelectItem>();
this.cities.add(new SelectItem("1","Delhi"));
this.cities.add(new SelectItem("2","Mumbai"));
}
if ("2".equals(newValue)){
this.cities = new ArrayList<SelectItem>();
this.cities.add(new SelectItem("1","Mossco"));
}
}
Run Code Online (Sandbox Code Playgroud)
如果实施正确,请告诉我.它工作正常.我的问题是:
是否可以使用单个命令组件调用多个侦听器方法?例如,
视图范围的bean:
@ManagedBean
@ViewScoped
public final class ViewScopedBean implements Serializable
{
@ManagedProperty(value = "#{sessionScopedBean}")
private SessionScopedBean sessionScopedBean; //Getter/Setter.
private static final long serialVersionUID = 1L;
public ViewScopedBean() {}
public void action()
{
//Do something.
sessionScopedBean.action();
}
}
Run Code Online (Sandbox Code Playgroud)
会话范围的bean:
@ManagedBean
@SessionScoped
public final class SessionScopedBean implements Serializable
{
private static final long serialVersionUID = 1L;
public SessionScopedBean () {}
public void action() {
//Do something.
}
}
Run Code Online (Sandbox Code Playgroud)
一个命令按钮,如下所示,
<h:commandButton value="Action" actionListener="#{viewScopedBean.action}"/>
Run Code Online (Sandbox Code Playgroud)
调用该方法action(),ViewScopedBean然后通过注入该bean的实例来调用该action()方法SessionScopedBean.
是否有可能在XHTML上做同样的事情,以便可以消除只是为了调用方法而注入bean的需要?
在处理JSF ajax请求时抛出异常时,如何处理异常并访问堆栈跟踪?现在,当JSF项目阶段设置为Development时,我只在JavaScript警报中获取异常类名称和消息.更糟糕的是,当JSF项目阶段设置为Production时,没有任何视觉反馈,并且服务器日志不显示有关异常的任何信息.
如果这是相关的,我在Netbeans中使用GlassFish.
我想在进一步处理之前使用多个动作侦听器来设置两个支持bean的状态
第一种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
它给出了一个例外:
警告:/ testGroup/List.xhtml @ 26,88 binding ="#{testController.nodeListener()}":找不到方法nodeListener javax.el.ELException:/testGroup/List.xhtml @ 26,88 binding ="#{ testController.nodeListener()}":找不到方法nodeListener
第二种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener(event)}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate(event)}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
nodeListener和prepareCreate方法的事件为null
怎么做对吗?
我在JSF项目中使用Passthrough元素,并且需要执行以下操作:
<h:commandLink action="#{myBean.acao()}" value="click me">
<f:setPropertyActionListener target="#{myBean.object}" value="#{localObject}"/>
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
但是使用Passthrough元素可以更好地控制前端,例如尝试以下操作:
<a href="#" jsf:action="#{myBean.acao()}">click me
<f:setPropertyActionListener target="#{myBean.object}" value="#{localObject}"/>
</a>
Run Code Online (Sandbox Code Playgroud)
但显然这不起作用,我收到以下错误消息:
<f:setPropertyActionListener> Parent is not of type ActionSource, type is: com.sun.faces.component.PassthroughElement
Run Code Online (Sandbox Code Playgroud)
有谁知道我该怎么解决?
我正在努力将Primefaces bean属性直接发送到javascript,以便打开一个新页面并将bean属性的内容写入新页面.
我正在使用Primefaces 4.0.
我有一个这样的命令按钮:
<p:commandButton id="buttonId" update="buttonId, otherComponentId"
value="press me" process="@this" actionListener="#{homeController.myMethod}"
oncomplete="handleComplete(xhr, status, args)">
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
在handleComplete中,javascript函数args未定义,但不是xhr和status.javascript函数定义:
function handleComplete(xhr, status, args){
var w = window.open();
w.document.open();
alert(xhr.responseText.substring(100));
alert(status);
alert(args);
var d = '<head></head><body>'+ args.firstParam +'<body>';
w.document.write(d);
w.document.close();
}
Run Code Online (Sandbox Code Playgroud)
首先警告它给我页面,第二个解析错误,错误是:Uncaught TypeError:无法读取未定义的属性'firstParam'
我想在args中传入一个这样的字符串:
public String MyMethod() {
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("firstParam", "my string");
return "";
}
Run Code Online (Sandbox Code Playgroud)
并使用javascript访问它args.firstParam.
该方法被调用,(我有一些工作的打印屏幕.)
我必须尝试这种方式,而不是将文本设置为
<h:outputText id="myText" escape="false" rendered="true"
value="#{homeController.property}" />
Run Code Online (Sandbox Code Playgroud)
然后得到这个元素的innerHTML,因为我将使用innerHTML获得的内容与bean中的字符串变量不同.这种方法有效但不是我想要的.我想知道为什么args对象是未定义的,或者我怎样才能从javascript中管理bean属性.谢谢.