0
所以,我有一個支持bean,Foo和一個帶有客戶端,請求和響應的模板。客戶是多餘的,我只想要一個客戶。hello world facelets 2.0 navigation
客戶:
[email protected]:~$
[email protected]:~$ cat NetBeansProjects/NNTPjsf/web/foo/request.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<ui:define name="left">
<h:form>
<h:inputText size="2" maxlength="50" value="#{foo.bar}" />
<h:commandButton id="submit" value="submit" action="response" />
</h:form>
</ui:define>
<ui:define name="content">
<h:outputText value="#{foo.bar}"></h:outputText>
</ui:define>
</ui:composition>
[email protected]:~$
[email protected]:~$ cat NetBeansProjects/NNTPjsf/web/foo/response.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<ui:define name="left">
<h:form>
<h:inputText size="2" maxlength="50" value="#{foo.bar}" />
<h:commandButton id="submit" value="submit" action="response" />
</h:form>
</ui:define>
<ui:define name="content">
<h:outputText value="#{foo.bar}"></h:outputText>
</ui:define>
</ui:composition>
[email protected]:~$
我認爲這是好的,在其本身。
支持bean:
package guessNumber;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpSession;
@Named
@SessionScoped
public class Foo implements Serializable {
private String bar = "bar";
private String response = "response";
public Foo() {
}
/**
* @return the bar
*/
public String getBar() {
return bar;
}
/**
* @param bar the bar to set
*/
public void setBar(String bar) {
this.bar = bar;
}
/**
* @return the response
*/
public String getResponse() {
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
session.invalidate();
response = "hmm";
return response;
}
/**
* @param response the response to set
*/
public void setResponse(String response) {
this.response = response;
}
}
我想只是一個單一的客戶端,request_response什麼的。這樣文本輸入表單停留在左側,結果在右側。這是用組合標籤完成的?或者,第三個「普通客戶」有兩個子客戶?
只有兩個提示:
那麼對於酒吧和響應變化值可以在右側圖所示:如果你想留在同一頁面上,你可以將你的action方法定義爲void doAction(){}。另外,在這種情況下,可能不需要';您可以將EL直接放在Facelet上。希望這會有所幫助;) –
2012-04-01 19:13:50
答案和表揚看起來很棒,我會在幾個小時內嘗試,然後回到這裏。謝謝! – Thufir 2012-04-01 19:59:48
謝謝,你們倆。 – Thufir 2012-04-01 20:10:34