Jsf 命令按钮“不调用函数”和“不工作更新”属性
Sample.xhtmlJsf 命令按钮“不调用函数”和“不工作更新”属性,jsf,Jsf,Sample.xhtml <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> <h:head> <f:event listener="#{sample.dosamplelist}" type="p
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:event listener="#{sample.dosamplelist}" type="preRenderView" />
</h:head>
<h:body>
<h:form>
<h:panelGrid id="samplesetting" columns="6" cellpadding="5">
<f:facet name="header">Name Setting</f:facet>
<h:outputLabel for="samplename" value="Name:" />
<p:inputText value="#{sample.name}" id="samplename"
required="true" label="samplename" />
</h:panelGrid>
<p:panel id="sampleview" header="Sample List">
<p:dataTable var="spl" value="#{sample.samplelist}" rowKey="#{spl.name}"
selection="#{sample.selectedname}"
selectionMode="single">
<p:column headerText="Name">
<h:outputText value="#{spl.name}" />
</p:column>
<p:column>
<p:commandButton id="one" value="View Details" action="#{sample.setSelectedsample(spl)}" update="@form:samplesetting">
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
名称设置
托管Bean
@SuppressWarnings("serial")
@ManagedBean(name = "sample")
@RequestScoped
public class Sample implements Serializable
{
private String name;
private List<Sample> samplelist;
private String selectedname;
//getters and setters
public void dosamplelist(ComponentSystemEvent event)
{
List<Sample> samplelist = new ArrayList<Sample>();
Sample configA = new Sample();
configA.setName("John");
samplelist.add(configA);
Sample configB = new Sample();
configB.setName("David");
samplelist.add(configB);
this.samplelist = samplelist;
}
public void setSelectedsample(Sample smpl)
{
this.name = smpl.name;
}
}
@SuppressWarnings(“串行”)
@ManagedBean(name=“sample”)
@请求范围
公共类示例实现了可序列化
{
私有字符串名称;
私人名单样本名单;
私有字符串selectedname;
//接球手和接球手
公共无效dosamplelist(组件系统事件)
{
List samplelist=new ArrayList();
样本配置a=新样本();
配置设置名称(“John”);
samplelist.add(configA);
样本配置B=新样本();
configB.setName(“大卫”);
samplelist.add(configB);
this.samplelist=samplelist;
}
公共无效设置选定样本(样本smpl)
{
this.name=smpl.name;
}
}
这是小-大表单的示例,需要的是,当我们从底部选择表行时,它将显示在顶部输入框中以进行编辑
但当我按下命令按钮时,它不起作用。为什么?请问原因是什么?可能的问题 一个明显的问题是,在类级别,您定义了:
private List<Sample> samplelist;
结合将bean标记为@RequestScoped
,它将保证示例列表的内容在JSF请求处理期间不一致
要解决的问题:
将bean标记为@ViewScoped
,然后根据需要解决变量隐藏问题
进一步阅读:
List<Sample> samplelist = new ArrayList<Sample>();