我有这样的表格:
<h:form id="testForm">
<p:fieldset legend="data">
<p:dataTable id="fileData" var="dataList" value="#{fileUpload.displayData}">
<p:column headerText="Htno">
<h:outputText value="#{dataList.htno}" />
</p:column>
<p:column headerText="Ecode">
<h:outputText value="#{dataList.ecode}" />
</p:column>
<p:column headerText="Subcode">
<h:outputText value="#{dataList.subcode}" />
</p:column>
<p:column headerText="Imf">
<h:outputText value="#{dataList.imf}" />
</p:column>
<p:column headerText="Action">
<!-- <h:commandLink value="Upload" action="#{fileUpload.single}" rendered="true" >
<f:param name="imf" value="#{dataList.imf}" />
<h:inputHidden value="#{fileUpload.imf}" id="imf" />
</h:commandLink> -->
<h:commandButton image="delete" ajax="false" style="margin-right:20px;" action="#{fileUpload.single}" ></h:commandButton>
</p:column>
</p:dataTable>
<h:inputHidden value="#{fileUpload.uploadFileName}" id="uploadFileName" />
<h:inputHidden value="#{fileUpload.dirPath}" id="dirPath" />
<h:commandButton type="submit" value="Upload All" action="#{fileUpload.uploadAll}"></h:commandButton>
</p:fieldset>
</h:form>
和这个bean:
public class FileUpload {
public String single() {
System.out.println("-----------**---d---");
return "home";
}
}
导致此异常:
javax.servlet.ServletException: The class 'com.primefaces.sample.FileUpload' does not have the property 'single'
如果我使用getter和setter创建一个属性,则不再抛出异常。但是,在页面加载期间调用它而不按提交按钮。我终生无法弄清楚原因。
答案 0 :(得分:1)
您的问题是由此引起的:
<!-- <h:commandLink value="Upload" action="#{fileUpload.single}" rendered="true" >
<f:param name="imf" value="#{dataList.imf}" />
<h:inputHidden value="#{fileUpload.imf}" id="imf" />
</h:commandLink> -->
HTML注释被解释为模板文本。它们还需要以生成的HTML输出结束。 HTML注释不会阻止评估EL表达式。这就像你正在做的那样:
<p>Blah blah #{fileUpload.single} blah blah</p>
这被解释为<h:outputText value="#{fileUpload.single}"/>
,显然需要一个吸气剂。
您需要删除整个注释,或将其包装在<ui:remove>
中,或者通过web.xml
中的以下上下文参数告诉Facelets在解析期间跳过注释:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>