I have a
JSF application in which I want to use h:commandLink and f:param tags. The commandLink on it's own works but as soon as I add the f:param tag, the link no longer works.
I found an example that seems to work correctly:
http://www.javabeat.net/tips/44-hcommandlink-how-to-pass-parameter-to-next.html. When I create a new project in NetBeans, and use the files from the example, it works.
However when I create these same files within my own application in NetBeans 6.5 (via "File->New File->Web->JSP" and "File->New->Java->
Java Class"), then copying the example code into the new pages, and the relevant faces-config.xml section to my own faces-config.xml file, the commandLink no longer works. The obvious conclusion is that there's something different in my own application that's affecting the way the code is supposed to work.
In looking at the HTML source code generated, and comparing the working example with my non-working implementation of the same code, I found that the working version contains generated javascript, and the non-working version contains no generated javascript.
Seemingly, the reason my implementation does not work is that the javascript is missing.
My question is this:
Is this a NetBeans thing issue do you think? If so, how do I tell NetBeans to generate the javascript for the commandLink tag?
Thanks
-bob
The
JSP source code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<html>
<body>
<f:view>
<h:form id="commandLink">
<h:commandLink value="Test Link" action="#{commandLinkBean.linkIt}">
<f:param name="param1" value="ParamValue1" />
<f:param name="param2" value="ParamValue2" />
</h:commandLink>
</h:form>
</f:view>
</body>
</html>
******** Example faces.config.xml ***************************************************
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>
commandLinkBean
</managed-bean-name>
<managed-bean-class>
com.webfront.CommandLinkBean
</managed-bean-class>
<managed-bean-scope>
request
</managed-bean-scope>
<managed-property>
<property-name>param1</property-name>
<value>#{param.param1}</value>
</managed-property>
<managed-property>
<property-name>param2</property-name>
<value>#{param.param2}</value>
</managed-property>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>
commandLink
</from-outcome>
<to-view-id>
/CommandLinkResults.jsp
</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
********** My Application's faces.config.xml *******************************************
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!--
Test stuff -->
<managed-bean>
<managed-bean-name>
commandLinkBean
</managed-bean-name>
<managed-bean-class>
com.webfront.CommandLinkBean
</managed-bean-class>
<managed-bean-scope>
request
</managed-bean-scope>
<managed-property>
<property-name>param1</property-name>
<value>#{param.param1}</value>
</managed-property>
<managed-property>
<property-name>param2</property-name>
<value>#{param.param2}</value>
</managed-property>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>
commandLink
</from-outcome>
<to-view-id>
/CommandLinkResults.jsp
</to-view-id>
</navigation-case>
</navigation-rule>
<!-- end of Test stuff -->
<managed-bean>
<managed-bean-name>app</managed-bean-name>
<managed-bean-class>com.webfront.ApplicationBean</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>ses</managed-bean-name>
<managed-bean-class>com.webfront.SessionBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>req</managed-bean-name>
<managed-bean-class>com.webfront.RequestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>totes</managed-bean-name>
<managed-bean-class>com.webfront.controllers.ToteController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>connection</property-name>
<value>#{app.connection}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>inventory</managed-bean-name>
<managed-bean-class>com.webfront.controllers.InventoryController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>connection</property-name>
<value>#{app.connection}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>categories</managed-bean-name>
<managed-bean-class>com.webfront.controllers.CategoryController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>connection</property-name>
<value>#{app.connection}</value>
</managed-property>
<managed-property>
<property-name>selectedCat</property-name>
<value>#{param.selectedCat}</value>
</managed-property>
</managed-bean>
<!-- Menu navigation rules -->
<navigation-rule>
<navigation-case>
<from-outcome>totesList</from-outcome>
<to-view-id>/ToteListing.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>toteContents</from-outcome>
<to-view-id>/ToteContents.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>itemSearch</from-outcome>
<to-view-id>/InventoryItem.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>catEntry</from-outcome>
<to-view-id>/Categories.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- Totes pages navigation rules -->
<navigation-rule>
<from-view-id>/ToteListing.jsp</from-view-id>
<navigation-case>
<from-action>#{totes.newTote}</from-action>
<from-outcome>ok</from-outcome>
<to-view-id>/ToteForm.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/ToteForm.jsp</from-view-id>
<navigation-case>
<from-action>#{totes.cancel}</from-action>
<from-outcome>cancel</from-outcome>
<to-view-id>/ToteListing.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/ToteContents.jsp</from-view-id>
<navigation-case>
<from-action>#{inventory.edit}</from-action>
<from-outcome>edit</from-outcome>
<to-view-id>/InventoryItemEdit.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<!-- Inventory pages navigation rules -->
<navigation-rule>
<from-view-id>/InventoryItem.jsp</from-view-id>
<navigation-case>
<from-action>#{inventory.search}</from-action>
<from-outcome>ok</from-outcome>
<to-view-id>/InventorySearch.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/InventorySearch.jsp</from-view-id>
<navigation-case>
<from-action>#{inventory.reset}</from-action>
<from-outcome>reset</from-outcome>
<to-view-id>/InventoryItem.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/InventoryItemEdit.jsp</from-view-id>
<navigation-case>
<from-action>#{inventory.update}</from-action>
<from-outcome>update</from-outcome>
<to-view-id>/ToteContents.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-action>#{inventory.cancel}</from-action>
<from-outcome>cancel</from-outcome>
<to-view-id>/ToteContents.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<!-- Categories navigation -->
<navigation-rule>
<from-view-id>/Categories.jsp</from-view-id>
<navigation-case>
<from-action>#{categories.addCategory}</from-action>
<from-outcome>added</from-outcome>
<to-view-id>/CategoryForm.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/CategoryForm.jsp</from-view-id>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/Categories.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/Categories.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>