Posts Tagged ‘JEE’

Processing GET request parameters in JSF 2.0

Friday, April 23rd, 2010

In JSF 2.0 <h:link> tags were introduced that allow users to navigate to a JSF page without using a postback request.

For example:


<h:link value="3 Month Subscription" outcome="subscribe" />

would create an HTML link similar to:


<a href="/MyApp/faces/subscribe.xhtml">3 Month Subscription</a>

The value of the “outcome” parameter utilizes JSF 2.0 implicit navigation rules that save you the trouble of defining navigation cases in the faces-config.xml file.

Furthermore query parameters may be added to the links:


<h:link value="3 Month Subscription" outcome="subscribe">
    <f:param name="subscriptionType" value="threeMonth" />
</h:link>

<h:link value="6 Month Subscription" outcome="subscribe">
    <f:param name="subscriptionType" value="sixMonth" />
</h:link>

The links would look like this:


<a href="/MyApp/faces/subscribe.xhtml?subscriptionType=threeMonth">3 Month Subscription</a>
<a href="/MyApp/faces/subscribe.xhtml?subscriptionType=sixMonth">6 Month Subscription</a>

This way we are able to preset the subscription type field on the subscribe.xhtml page. In subscribe.xhtml there might be the following Radio Buttons:


<h:selectOneRadio label="Subscription Type" value="#{BackingBean.subscriptionType}" id="subscriptionType">
    <f:selectItem itemLabel="3 Month Subscription" itemValue="threeMonth" />
    <f:selectItem itemLabel="6 Month Subscription" itemValue="sixMonth" />
</h:selectOneRadio>

Instead of representing the subscription type value as radio buttons you could use any other input component including for example a hidden field.

In order for the radio button to be selected upon loading the subscribe.xhtml page you must add the following annotation to the subscriptionType field in the corresponding JSF managed bean:


[...]
@ManagedProperty(value="#{param.subscriptionType}")
private String subscriptionType;
[...]

Differences between TopLink and EclipseLink

Monday, March 22nd, 2010

The default persistence manager in Netbeans Release 6.8 has changed from TopLink to EclipseLink and I will list error messages and differences that I find as I go along.

1.
ErrorMessage

Exception [EclipseLink-8034] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [findUserByEmail: SELECT u FROM theuser u WHERE u.email = :email]. Unknown entity type [theuser].
at org.eclipse.persistence.exceptions.JPQLException.entityTypeNotFound(JPQLException.java:483)

Solution
EclipseLink is case sensitive. If your entity is named “TheUser” (yes, it is a dumm name for an entity) your named query should be:
@NamedQueries({
@NamedQuery(
name="findUserByEmail",
query="SELECT u FROM TheUser u WHERE u.email = :email"
)
})

and not ...SELECT u FROM theuser....