Lunski's Clutter

This is a place to put my clutters, no matter you like it or not, welcome here.

0%

JavaServer Faces

用Java 寫網頁的東東

注意事項

  • “#{}”或””中不可有空格, 雙引號只需打”, 剩下自動補全
  • tag要習慣寫結尾</>
  • 引入包

實作

1
2
3
4
5
6
7
8
9
10
11
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@Entity: 資料表
@Stateless: Facade存取資料表

Controller控制邏輯
@ManagedBean(name="")
@SessionScoped

#{}: EL lambda mendel

初始化

1
2
3
import javax.annotation.PostConstruct;
@PostConstruct
public void init(){}

結構

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
template="/templates/generalPageTemplate.xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:define name="title">
<h:outputText value="#{su.funcTitle}" />
</ui:define>
<ui:define name="head">
<style type="text/css">
</style>
<script type="text/javascript">
//<![CDATA[
//]]>
</script>
</ui:define>
<ui:define name="content">

render不是只可以用True/ False, 還可以帶id

1
2
3
4
5
6
7
8
9
10
<h:head>
<script>
function ajaxOnevent(data){}
</script>
</h:head>

<h:commandButton>
<f:ajax onevent="ajaxOnevent" render="output">
</h:commandButton>
<h:outputText id="output" value="#{UserCtrl.outputText}"/>

Ajax

  • f:ajax render="@form"
  • f:ajax: 局部渲染,只更新頁面中的特定部分
  • render="@form": 指定Ajax請求完成後,哪些元件需要在客戶端重新渲染
  • @form: 指的包含f:ajax標籤的表單元件, 告訴JSF在Ajax請求處理完畢後,重新渲染整個表單

ResetDataTable

 /**
 * 移除 datatable 目前排序、filter 效果
 */
public void resetDataTable() {
    JsfUtils.resetDataTable(DATATABLE_RESULT);
}

SuccessCallback

JsfUtils.buildSuccessCallback();

卡住畫面

onclick=”setUpBlockUI()”

改名的2種可能

參數改名:example指ExampleClass

1
2
3
<ui:include src="/member/inc_example.xhtml">
<ui:param name="example" value="#{ExampleClass}"/>
</ui:include>

物件改名:example指ExampleClass

1
2
3
@ManagedBean(name = "example")
@ViewScoped
public class ExampleClass extends ... implements Serializable, AddSignerHandler {

如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)

Welcome to my other publishing channels