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???

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

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
0

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

2 Comments

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 I'm using JSF 1.x version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.