We want to write a simple JSF application that gets an input text from a user an
ID: 3575568 • Letter: W
Question
We want to write a simple JSF application that gets an input text from a user and echoes the input text. inputText.xhtml gets input text from a user. echoText.xhtml echoes the input text value entered from the user. Refer to the following two figures. please fill the gaps inputText.xhtml code snippet <h:form> <h:inputText value="#{textBean.inputText}" /> <h:commandButton value="Echo the Input Text" action="#{textBean.doEcho}" /> </h:form> (1) Write a JSF managed Bean based on the following code template import java.io.Serializable; import javax.enterprise.context.SessionScoped; import javax.inject.Named; @Named(value = "__________") @SessionScoped public class _____________________________ { //Write code declaring instance variable //methods including action controller method } (2) Complete echoText.xhtml code snippet shown below <h:body> <h1>Echo the input text value</h1> Echo the input text value : <h:outputText value=__________________________ /> </h:body>
Explanation / Answer
textBean.java--------------
package com.mkyong.form;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
@ManagedBean
@SessionScoped
public class textBean implements Serializable {
private String inputText;
public String getInputText() {
return inputText;
}
public void setInputText(String inputText) {
this.inputText = inputText;
}
}
echoText.xhtml-------------------------
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h1>Echoed Value:</h1>
Entered value is: <h:outputText value="#{textBean.inputText}" />
</h:body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.