我有2页,inputForm.xhtml
和outputPage.xhtml
。
在inputForm.xhtml
中,有1个文本字段和1个复选框。当用户单击“提交”按钮时,值将传递到URL中的outputPage.xhtml
。
可以正确传递textfield的值。但是,无论是否选中复选框,URL中的参数始终为false。
e.g。 http://localhost:8080/jsf-web/outputPage.xhtml?c=false&n=franz
我正在使用myFaces 2.1.13。我真的不知道如何解决这个问题。感谢。
inputForm.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewParam name="n" value="#{inputFormBean.name}" />
<f:viewParam name="c" value="#{inputFormBean.nameUppercase}" />
</f:metadata>
<h:head>
</h:head>
<h:body>
<h:form>
<p>Name: <h:inputText value="#{inputFormBean.name}" /></p>
<p>Name uppercase: <h:selectBooleanCheckbox value="#{inputFormBean.nameUppercase}"/></p>
<p><h:commandButton action="output_page" value="Submit" /></p>
</h:form>
</h:body>
</html>
outputPage.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewParam name="n" value="#{outputPageBean.name}" />
<f:viewParam name="c" value="#{outputPageBean.nameUppercase}" />
</f:metadata>
<h:head>
</h:head>
<h:body>
<h3>Welcome #{outputPageBean.nameUppercase ? outputPageBean.name.toUpperCase() : outputPageBean.name}!!</h3>
</h:body>
</html>
faces-config.xml
<?xml version="1.0"?>
<faces-config 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_2_0.xsd"
version="2.0">
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>output_page</from-outcome>
<to-view-id>/outputPage.xhtml</to-view-id>
<redirect include-view-params="true"/>
</navigation-case>
</navigation-rule>
</faces-config>
InputFormBean.java
package com.franzwong.jsfweb;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class InputFormBean {
private String name;
private boolean nameUppercase;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isNameUppercase() {
return nameUppercase;
}
public void setNameUppercase(boolean nameUppercase) {
this.nameUppercase = nameUppercase;
}
}
OutputPageBean.java
package com.franzwong.jsfweb;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class OutputPageBean {
private String name;
private boolean nameUppercase;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isNameUppercase() {
return nameUppercase;
}
public void setNameUppercase(boolean nameUppercase) {
this.nameUppercase = nameUppercase;
}
}
答案 0 :(得分:0)
最后我尝试了原始的int,无论我输入什么值,都会传递给0。
因此,我尝试使用Boolean,Integer并发现我输入的值可以在URL中正确传递。