1
<h:dataTable id="dt1" value="#{StudentMark.stuList}" var="stuList"  bgcolor="#9AC8E6" border="10" cellpadding="5" cellspacing="3" rows="18" width="120%" dir="LTR" frame="hsides>
                <h:column>
                    <f:facet name="header">
                        <h:outputText style=""value="Student Number" />
                    </f:facet>
                    <h:outputText style="" value="#{stuList.stuNumber}"></h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Date"/>
                    </f:facet>
                    <h:outputText value="#{stuList.date}">
                        <f:convertDateTime type="date" pattern="dd-MM-yyyy"/></h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Name"/>
                    </f:facet>
                    <h:outputText value="#{stuList.stuName}"></h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Division"/>
                    </f:facet>
                    <h:outputText value="#{stuList.division}"></h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Annual Marks"/>
                    </f:facet>
                    <h:outputText value="#{stuList.annualMark}"></h:outputText>
                </h:column>                    
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Student History"/>
                    </f:facet>
                     <h:form>
                        <h:commandButton id = "historyBtn" value="Student History" action="#{stuBean.showHistory}">
                            <f:param name="sNumber" value="#{stuBean.stuNumber}" />
                            <f:param name="sName" value="#{stuBean.stuName}" />
                        </h:commandButton></h:form>                        
                </h:column>
            </h:dataTable>

When i try to get the parameters passed using

        FacesContext context = FacesContext.getCurrentInstance();
        Map requestMap = context.getExternalContext().getRequestParameterMap();
        String studentNum = (String) requestMap.get("sNumber");
        String studentName = (String) requestMap.get("sName");

its showing "null" in studentName and studentNum thereby resulting with a null pointer exception. Any ideas to resolve this???

Manoj
  • 5,542
  • 9
  • 54
  • 80
Mango
  • 650
  • 2
  • 16
  • 38
  • possible duplicate of [pass values from jsp-jsf](http://stackoverflow.com/questions/5487728/pass-values-from-jsp-jsf) – BalusC Apr 05 '11 at 11:31

3 Answers3

1

I've resolved my issue. The mistake made was I've trying to pass the parameters at the page load itself,tried making the param value as value="#{stuList.stuNumber}" and got the error resolved.

<h:form>
 <h:commandLink id = "historyBtn" value="Student History" action="#{stuBean.showHistory}">
     <f:param name="sNumber" value="#{stuList.stuNumber}" />
     <f:param name="sName" value="#{stuList.stuName}" />
  </h:commandLink></h:form> 

Thanks for all the professionals for their time.

Mango
  • 650
  • 2
  • 16
  • 38
0

You are mixing POST and GET requests. h:form and h:commandbutton are for POST requests. f:param is for GET requests. If you want a GET request use h:button or h:link

For a quick overview of GET support look here it also explains how you can bind the parameter to a bean without having to go to the request parameter map.

Eelke
  • 20,897
  • 4
  • 50
  • 76
  • My problem is to send 2 of the field values(sNum and sName) of the datatable as input parameters to the database and get the respective child's history on his button click – Mango Apr 05 '11 at 11:22
0

I think f:param works only in h:commandLink and h:outputLink but not in h:commandButton.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • OP never mentioned in any question which JSF version he's using, but the above is true for JSF 1.x. In JSF 2.x, it's however supported on `h:commandButton` as well. – BalusC Apr 05 '11 at 11:33
  • @BalusC I'm using JSF 1.x version – Mango Apr 05 '11 at 11:35