2011-03-07 10 views
6

मैं बटन क्लिक के आधार पर विशिष्ट पृष्ठ शामिल करना चाहता हूं।f का उपयोग करें: f के लिए कमांड बटन के लिए विशेषता: h के लिए param: commandLink

h:commandButton का उपयोग किया गया, मैं f:param का उपयोग नहीं कर सका, ऐसा लगता है कि मुझे f:attribute टैग का उपयोग करना चाहिए।

f:param के मामले में मैं इस तरह कोड होगा:

<h:commandLink action="connectedFilein"> 
    <f:param name="fileId" value="#{fileRecord.fileId}"/> 
<h:commandLink> 

<c:if test="#{requestParameters.fileId!=null}"> 
    <ui:include src="fileOut.xhtml" id="searchOutResults"/> 
</c:if> 

f:attribuite मामला क्या है?

धन्यवाद

उत्तर

14

मुझे लगता है कि आप JSF 1.x का उपयोग कर रहे मान, नहीं तो इस सवाल का कोई मतलब नहीं था। <h:commandButton> में वास्तव में विरासत जेएसएफ 1.x में समर्थित नहीं है, लेकिन यह जेएसएफ 2.0 के बाद से समर्थित है।

<f:attribute>actionListener के साथ संयोजन में उपयोग किया जा सकता है।

<h:commandButton action="connectedFilein" actionListener="#{bean.listener}"> 
    <f:attribute name="fileId" value="#{fileRecord.fileId}" /> 
</h:commandButton> 

public void listener(ActionEvent event) { 
    this.fileId = (Long) event.getComponent().getAttributes().get("fileId"); 
} 

(यह मानते हुए कि यह Long प्रकार है, जो एक आईडी के लिए क्लासिक है की है) के साथ


बेहतर JSF 1.2 <f:setPropertyActionListener> शुरू की उपयोग करने के लिए तथापि है।

<h:commandButton action="connectedFilein"> 
    <f:setPropertyActionListener target="#{bean.fileId}" value="#{fileRecord.fileId}" /> 
</h:commandButton> 

या जब आप पहले से ही एक सर्वलेट 3.0/ईएल 2.2 सक्षम कंटेनर (बिलाव 7, Glassfish 3, आदि) और अपने web.xml चला रहे हैं घोषित किया जाता है सर्वलेट 3.0 अनुरूप है, तो आप बस इसे के रूप में दे सकते हैं विधि तर्क

<h:commandButton action="#{bean.show(fileRecord.fileId)}" /> 

public String show(Long fileId) { 
    this.fileId = fileId; 
    return "connectedFilein"; 
} 

ठोस समस्या से संबंधित नहीं के साथ

, मैं दृढ़ता से JSTL लोगों जब भी संभव हो के बजाय JSF/Facelets टैग का उपयोग करने की सलाह देते हैं।

<ui:fragment rendered="#{bean.fileId != null}"> 
    <ui:include src="fileOut.xhtml" id="searchOutResults"/> 
</ui:fragment> 

+0

किसी भी मामले मैं bean.property घोषणा इस मामले का उपयोग करना चाहिए (ए <h:panelGroup> जब Facelets के बजाय JSP का उपयोग करके भी संभव है और सबसे अच्छा तरीका है)? अनुरोध पैरामीटर यहाँ नहीं खेलते हैं? मैं इसे आसान बनाना चाहता था – sergionni

+0

जेएसएफ 2.0 '' '' का समर्थन करता है। तो अगर आप इसे अपग्रेड कर सकते हैं। अन्यथा आपकी वर्तमान सर्वश्रेष्ठ शर्त '' है। – BalusC

+0

ठीक है, मैं देखता हूं, दुर्भाग्यवश हम अपने प्रोजेक्ट में जेएसएफ 1.2 का उपयोग करते हैं। धन्यवाद – sergionni