ユーザーがカンマ区切りの数値フィールドに入力した値に応じて、フォーム提出後に別のページに移動する必要があります。続いナビゲーションルールが適用されていません
はcomsepの値を取得するためのコードであり、ボタンを提出:
<h:inputText id="comsep" value="#{bean.comsep}" ></h:inputText>
<h:commandButton value="Submit" action ="bean.func"></h:commandButton>
これは豆である:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
@ManagedBean
public class Bean
{
public String comsep;
public Bean()
{
}
public String func()
{
double avg = calculate();
if (avg == 10)
{ return "casea"; }
else
{ return "caseb"; }
}
public double calculate()
{
String[] pos = comsep.split(",");
double avg = 0;
for (int i = 0; i < pos.length; i++)
avg = avg + Integer.parseInt(pos[i]);
avg = avg/pos.length;
return avg;
}
public String getComsep() {
return comsep;
}
public void setComsep(String comsep) {
this.comsep = comsep;
}
}
、これは顔-config.xmlにある:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee h http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<navigation-rule>
<from-view-id>/Home.xhtml</from-view-id>
<navigation-case>
<from-action>#{bean.func}</from-action>
<from-outcome>casea</from-outcome>
<to-view-id>/Page1.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{bean.func}</from-action>
<from-outcome>caseb</from-outcome>
<to-view-id>/Page2.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
avg == 10 else page2の場合、期待される結果はpage1ですが、これは起こっていません。私がsubmitを押すと、何も起こらないが、home.xhtmlがリフレッシュされる。
JSFの新機能ですので、新人ミスがあれば申し訳ありません。
これは 'h:inputtext'で動作しますか?タイトルに「タグ」を追加する必要はありません。また**タイトルの**問題**を要約する。そして、いくつかの良いnon-jsf 1.2チュートリアルから始めてください。 – Kukeltje
@Kukeltjeいいえ、h:inputtextのどちらでも動作しません。 – NJWeb