JavaServer Faces で値を使用することとバインディングを使用することの違いは何ですか? 私の質問が何であるかを明確にするために、いくつかの簡単な例をここに示します。
通常、XHTML コードの JSF では、次のように「値」を使用します。
<h:form>
<h:inputText value="#{hello.inputText}"/>
<h:commandButton value="Click Me!" action="#{hello.action}"/>
<h:outputText value="#{hello.outputText}"/>
</h:form>
次に、Bean は次のとおりです。
// Imports
@ManagedBean(name="hello")
@RequestScoped
public class Hello implements Serializable {
private String inputText;
private String outputText;
public void setInputText(String inputText) {
this.inputText = inputText;
}
public String getInputText() {
return inputText;
}
// Other getters and setters etc.
// Other methods etc.
public String action() {
// Do other things
return "success";
}
}
ただし、「バインディング」を使用する場合、XHTML コードは次のようになります。
<h:form>
<h:inputText binding="#{backing_hello.inputText}"/>
<h:commandButton value="Click Me!" action="#{backing_hello.action}"/>
<h:outputText value="Hello!" binding="#{backing_hello.outputText}"/>
</h:form>
対応する Bean はバッキング Bean と呼ばれ、ここにあります。
// Imports
@ManagedBean(name="backing_hello")
@RequestScoped
public class Hello implements Serializable {
private HtmlInputText inputText;
private HtmlOutputText outputText;
public void setInputText(HtmlInputText inputText) {
this.inputText = inputText;
}
public HtmlInputText getInputText() {
return inputText;
}
// Other getters and setters etc.
// Other methods etc.
public String action() {
// Do other things
return "success";
}
}
2 つのシステムには実際にはどのような違いがありますか? また、通常の Bean ではなくバッキング Bean を使用するのはどのような場合ですか? 両方を使用することは可能ですか?
私はこれについてしばらく混乱しており、これを解決していただければ幸いです。