There's another problem with your approach. You cannot use managed-bean managed-property to inject a value of a *shorter* scope.

So when you get the current exception fixed I expect you'll then get an error about "cannot inject reference to value of shorter scope" or similar.

In this case searchBean is of scope "session" but you're trying to inject a value of scope "request" which just doesn't make sense; dependency injection only occurs once when the managed bean is created. If this was allowed, then the searchTerms property would only be set on the first access to this page, then *not* set on later accesses as the bean already exists. Rather than permit this confusing behaviour, JSF implementations are required to throw an exception in this situation.

You can add a tag to the page to force an "init" method to be invoked. I have a custom "callback" I use for that purpose; someday I'll try to get around to offering that for sandbox/tomahawk. However a hacky alternative can be implemented. In this case (invoke a JSF page from the submit of an HTML page) only the *render* of the JSF page is important, so:

<h:outputText style="display:none" value="#{searchBean.init}"/>

private void init() {
  // check request-scope flag to see if already initialised, and
  // if so then just return.
  //
  // set request-scope initialised flag
  // look for non-JSF parameters and deal with them
}

public String getInit() {
  init();
  return null;
}

public void setInit(String s) {
}


Another alternative might be to write a PhaseListener that scans the request for params of a specific name format, eg "jsf.param.bbbb.pppp" and for each one found create a ValueBinding for #{bbbb.pppp} then write the value to it. This looks like a very convenient approach but I'm not so sure about the security implications; looks a bit like that PHP feature that is now deprecated for security reasons. A somewhat more secure approach could be to have a config table of (view-id, param-name, target-property) for the PhaseListener to work from.

Regards,

Simon



Todd Nine wrote:
Thanks for the help.  I've tried something similar

<managed-bean>
        <description>
            The bean used to submit a search result
        </description>
        <managed-bean-name>searchBean</managed-bean-name>
        <managed-bean-class>
            com.purdueefcu.website.bean.SearchBean
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
            <property-name>searchTerms</property-name>
            <property-class>java.lang.String</property-class>
            <value>#{param.searchTerms}</value>
        </managed-property>
    </managed-bean>

And I receive the following error

javax.servlet.ServletException: Cannot get value for expression 
'#{searchBean.startIndexDisplay}'
        javax.faces.webapp.FacesServlet.service
(FacesServlet.java:152)

*root cause*

javax.faces.FacesException: Cannot get value for expression 
'#{searchBean.startIndexDisplay}'
        org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch
(ServletExternalContextImpl.java:422)
        
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
        
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
        javax.faces.webapp.FacesServlet.service
(FacesServlet.java:138)


If I use this code in my "setter" to check if the param is available, I'm able to get the value from the form below. Any ideas?
.
Object terms = FacesContext.getCurrentInstance ().getExternalContext().getRequestParameterMap().get("searchTerms"); if(terms != null){ this.searchTerms = terms.toString(); } performSearch();
<form name="frmSearch" action=
"searchResults.jsf" method="get"
        enctype="application/x-www-form-urlencoded"

<input id="searchTerms" name=
"searchTerms" type="text" value="Search"
        
onclick="clearForm(this);" class="searchInput"
        
onfocus="clearForm(this);" />
<input
id="performSearch" name="performSearch" type="image"
        src="images/btn_go.jpg" style=
"align:right;" class="go_btn" />
</
form>



On 5/14/07, *Cagatay Civici* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi,

    <managed-bean>
            <managed-bean-name>barcaBean</managed-bean-name>
<managed-bean-class>com.fc.barcelona.BarcaBean</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
            <managed-property>
                <property-name>playerId</property-name>
                <value>#{param.playerId}</value>
            </managed-property>
    </managed-bean>

    Example:
    playerDetail.jsf?playerId=10

    So when there is request param called playerId in the request
    parameter map, it'll be used automatically to set the playerId
    property of barcaBean assuming there are references to barcaBean in
    the playerDetail.jsf page.

    Cagatay


    On 5/14/07, *Todd Nine* < [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>> wrote:

        Perhaps I should be more clear, my last post didn't make much
        sense.  I've been using EL (obviously since I have JSF pages),
        but I'm not sure how to bind to bean values using simple HTTP
        named params.




Reply via email to