Dmitry
Dmitry

Reputation: 2993

How to access html components in JSF EL?

I want some code in facelet (jsf 2.0) to work:

  <h:inputText id="q" />
  <h:button outcome="/search.xhtml?q=#{q.value}" />

but when I press the button, search page opens without any parameters.

I think, my EL expression is wrong. Is it possible to access inputText value from EL expression? If not, how can I achieve the same functionality?

Upvotes: 1

Views: 641

Answers (2)

Stan
Stan

Reputation: 862

this is a late answer but I guess many people finding this post will have the same doubt whether EL can access html component and how it can: Yes, EL can access JSF component which are implicit JSF object. However, up to now I have only seen and used the example of component.valid:

<h:inputText id="streetNumber" value="#{property.streetNumber}" title="streetNumber" required="true" requiredMessage="Please enter the street number!" validatorMessage="Please enter a street number between 1 and 1000" converterMessage="Please enter a number" pt:placeholder="900">
<f:convertNumber integerOnly="true"/>
<f:validateLongRange minimum="1" maximum="1000" />
</h:inputText>
<h:message for="streetNumber" class="#{!streetNumber.valid ? 'label label-warning' : 'none'}" /> 

So, I suggest you(Dmitry) change the code to

<h:button outcome="#{"/search.xhtml?q=" + q.value}" />

Please let me know whether it works because I am also curious and anyone who faces the similar problem can follow my example and please let me know the result.

Upvotes: 0

Dmitry
Dmitry

Reputation: 2993

I've finished with using plain html form:

<form action="faces/search.xhtml" method="get">
      <input type="text" name="query" />
      <input type="submit" value="Find" />
</form>

In search.xhtml I have view param to get a value of query string:

    <f:metadata>
        <f:viewParam name="query" />
    </f:metadata>

This solution has the problem - "faces/search.xhtml" is hardcoded. Also, when I place this form in search.xhtml and perform several searches I have something like this in browser url:

"http://localhost:8080/Application/faces/faces/faces/search.xhtml"

I think this problem can be solved with PrettyFaces (TODO :)

Upvotes: 1

Related Questions