と の戻り値の型は何であるべきで、getResponse
どちらsubmit
も必要ですか?
firstForm
またはに推測が入力された場合、SecondForm
その推測を同じ Web ページにエコーするにはどうすればよいですか?
ajaxを使用しているため、同じページをリロードしません
また
たとえば、新しいページをロードするとguessResults.xhtml
、これが推測されます。
バッキングビーンNextClient
:
package dur.beans;
import dur.jpa.Client;
import dur.jpa.ClientFacadeLocal;
import java.util.concurrent.atomic.AtomicInteger;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
@Named("nextClient")
@ApplicationScoped
public class NextClient implements NextClientLocal {
@EJB
private ClientFacadeLocal clientFacade;
private AtomicInteger next = new AtomicInteger(1009);
private AtomicInteger guess = new AtomicInteger(0);
private final boolean correct = true;
@Override
public String getNext() {
next.addAndGet(1);
Client client = clientFacade.find(next.intValue());
return client.toString();
}
@Override
public void setGuess(int guessInt) {
guess = new AtomicInteger(guessInt);
}
@Override
public int getGuess() {
return guess.intValue();
}
//not sure what do with these methods
@Override
public String getResponse() {
return "the guess of " + guess.intValue() + " is " + correct;
}
@Override
public String submit() {
return "the guess of " + guess.intValue() + " is " + correct;
}
}
facelets テンプレート クライアントnext.xhtml
:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head></h:head>
<h:body>
This and everything before will be ignored
<ui:composition template="template.xhtml">
<ui:define name="navigation">
<ui:include src="menu.xhtml"/>
</ui:define>
<ui:define name="main">
<h1>next bird</h1>
<p>
#{nextClient.next}
</p>
<p>
<h:panelGroup id="firstPanel">
<h:form id="firstForm">
<h:outputLabel for="input" value="First form input" />
<h:inputText id="input" value="#{nextClient.guess}" required="true" />
<h:commandButton value="Submit form" action="#{nextClient.submit}">
<f:ajax execute="@form" render="@form :secondPanel :secondForm :messages" />
</h:commandButton>
<h:message for="input" />
</h:form>
</h:panelGroup>
<h:panelGroup id="secondPanel">
<h:form id="secondForm">
<h:outputLabel for="input" value="Second form input" />
<h:inputText id="input" value="#{nextClient.guess}" required="true" />
<h:commandButton value="Submit other form" action="#{nextClient.submit}">
<f:ajax execute="@form" render="@form :firstPanel :firstForm :messages" />
</h:commandButton>
<h:message for="input" />
</h:form>
</h:panelGroup>
<h:messages id="messages" globalOnly="true" layout="table" />
</p>
</ui:define>
</ui:composition>
This and everything after will be ignored
</h:body>
</html>
以下も参照してください。
https://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/h/commandButton.html
http://docs.oracle.com/javaee/7/tutorial/doc/jsf-facelets003.htm
@Named
私はCDIを使用してGlassfishでFaceletsを実行しているので、使用していませ ん.@ManagedBean
@ManagedBean
目標は「hello world」よりも一歩進んだ、「hello world, yourguess is」が良い結果になるでしょう。特定のマニュアルがある場合、その特定のドキュメントへの RTFM は気にしません。Oracle ドキュメントはおそらく facelets に最適ですか?
コード: