2

I am working on a JSF 1.1 project.

JSP:

<h:column>
        <f:facet name="header"> <h:outputText value="Edit" />     </f:facet>

        <h:commandLink rendered="#{(Table1_var.status == 'CONFIRMED') or (Table1_var.status == 'CHECKED_IN')}"
            action="#{Table1_var.onEditReservation}">
            <h:graphicImage id="view-details-link" alt="Drill Down on the Dynamic Link!"
                    url="images/editReservationSmall.png" styleClass="view-details-img"/>
           <f:param
                name="VastuId"
                value="#{Table1_var.id}" />                 
        </h:commandLink>

        <f:facet name="footer"><h:outputText value="Edit" /> </f:facet>                
    </h:column>

In the <f:param>, the VastuId parameter is been assigned the id. Because of var=Table1_var I don't know where it is mapped with class. But I got class/method by searching it manually where that value can be get from:

public void navReservationDetail(final ActionEvent e) {
    Calendar cal1 = Calendar.getInstance();
    String rowId = FacesHelper.getRequestParameter("VastuId");
    System.out.println("ID :"+rowId);
}

FacesHelper.getRequestParameter is

public static String getRequestParameter(String parameter) {
    return (String) FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap().get(parameter);
}

I would like to set that parameter by Java mannually without using the UI. I tried using this:

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().put("#{VastuId}", reservationBean.getParentReservationProperty());              
String rowId = FacesHelper.getRequestParameter("VastuId");
System.out.println("selectedVastuId = "+rowId);

It is throwing an exception at getRequestParameterMap().put()

java.lang.UnsupportedOperationException: Cannot set ServletRequest Parameter
at org.apache.myfaces.context.servlet.RequestParameterMap.setAttribute
(RequestParameterMap.java:44)
at org.apache.myfaces.context.servlet.AbstractAttributeMap.put(AbstractAttributeMap.java:104)

How is this caused and how can I solve it?

1 Answer 1

3

The parameter map is read-only. In a servlet environment this data structure represents the values in the query part of the URL (e.g. http://foo/bar?queryValue=queryKey.) The server can only change these values by issuing a redirect call to the browser.

The per-user read/write scopes available in the base JSF 1.1/1.2 implementations are request and session.

When placing data into scope you should use the literal name and not the EL expression:

FacesContext.getCurrentInstance()
            .getExternalContext()
            .getRequestMap()
            .put("VastuId", reservationBean.getParentReservationProperty()); 

This value can then be resolved in the view using the expression #{VastuId} or #{requestScope.VastuId}.

4
  • Thanx alot ll try in min. and at the time of Get am using .getRequestParameterMap().get(parameter) then can i use .getRequestMap().put(,) ?
    – V.Rohan
    Dec 27, 2012 at 9:50
  • .getRequestMap().put("VastuId",id) giving me null and if .getRequestParameterMap().put("VastuId",id) giving same error.am using it for my REST webservice
    – V.Rohan
    Dec 27, 2012 at 10:15
  • 1
    If the FacesContext is null then you are attempting to access it outside the FacesServlet. This is not supported.
    – McDowell
    Dec 27, 2012 at 10:43
  • there is single simple class where i put and get it's value.And for get am using FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap().get(parameter) And it is giving me Warnning Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized
    – V.Rohan
    Dec 27, 2012 at 11:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.