primeface eg

枚舉的處理:

putViewScope(“types”, Type.values());

<h:outputText value="#{msg['dms']['type']}" />
<p:selectOneMenu id="type" style="width:140px;"
        value="#{viewScope.type}"  converter="#{enumConverter}">
    <f:selectItem itemLabel="" itemValue="" />
    <f:selectItems value="#{viewScope.types}" var="type"
        itemLabel="#{type.name}" itemValue="#{type}" />
</p:selectOneMenu>

input框賦值:

document.getElementById("orgChartForm:orgChartNodeIndex").value = index;

多選框賦值:

var departmentOptions = document.getElementById("orgChartForm:department_input").options;
for(var i = 0; i &lt; departmentOptions.length; i++){
    if(departmentId == departmentOptions[i].value){
        departmentOptions[i].selected = 'selected';
        document.getElementById('orgChartForm:department_label').innerText = departmentOptions[i].text;
        break;
    } 
}

枚舉轉換成JSON:

JSONArray types = new JSONArray();
for (Type type : Type.values()) {
    JSONObject typeElement = new JSONObject();
    try {
        typeElement.put(type.toString(), type.getName());
        types.put(typeElement);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
putViewScope("types", types.toString());

操作提示

@MessageRequired(type = MessageType.SAVE)

數據庫查詢數目操作

@Query("select count(state) from DeceasedState state where state.serviceTransaction.serviceCode =:serviceCode")
    public Long findCountQueryCode(@Param("serviceCode") ServiceCode serviceCode);

JS方法傳參到primeface後臺

import javax.faces.context.FacesContext;

這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

雙擊事件後傳遞對象

public void onRowSelect(SelectEvent event) {
   Semester semester = (Semester) event.getObject();
    semester.setIndex(semester.getIndex() + 1);
    putViewScope("semesterObject", semester);
    initSemester();
}

這裏寫圖片描述

遍歷節點

private OrgChartNode orgChartNodeStateToOrgChart(Long nodeId, List<OrgChartNodeState> orgChartNodeStates, OrgChart orgChart){
    List<OrgChartNodeState> newOrgChartNodeStates = new ArrayList<OrgChartNodeState>();
    OrgChartNode orgChartNode = orgChartNodeDao.findById(nodeId);
    List<OrgChartNode> childNodes = new ArrayList<OrgChartNode>();
    for(OrgChartNodeState nodeState : orgChartNodeStates){
        System.out.println("循環ing...");
        //OrgChartNodeState nodeState = orgChartNodeStates.get(0);
        if(nodeState.getParentId().equals(nodeId)){
            OrgChartNode node = new OrgChartNode();
            if(nodeState.getDbNodeId().equals(new Long(-1))){
                node = getNewNode(nodeState.getName());

                Long curNodeId = nodeState.getId();
                Long newNodeId = node.getId();
                nodeState.setId(newNodeId);
                nodeState.setDbNodeId(newNodeId);
                orgChartNodeStates = updateOrgChartNodeStateParentId(
                        orgChartNodeStates, curNodeId, newNodeId);
            }else{
                node = orgChartNodeDao.findById(nodeState.getDbNodeId());
            }
            node.setOrgChart(orgChart);
            node.setParent(orgChartNode);
            node.setName(nodeState.getName());
            node.setDepartment(departmentDao.findById(nodeState.getDepartmentId()));
            node.setRole(orgChartRoleDao.findById(nodeState.getRoleId()));
            node.setType(Type.valueOf(nodeState.getType()));

            //orgChartNodeStates.remove(0);
            //node = orgChartNodeStateToOrgChart(node.getId(), orgChartNodeStates);             
            childNodes.add(node);
        }else{
            newOrgChartNodeStates.add(nodeState);
        }
    }
    orgChartNode.setChildren(childNodes.size()>0 ? childNodes: null);

    for(OrgChartNode childNode : childNodes){
        orgChartNodeStateToOrgChart(childNode.getId(), newOrgChartNodeStates, orgChart);
    }

    return orgChartNode;
}

p:selectManyCheckbox JS取值設值的解決方法

這裏寫圖片描述

function getSelectManyCheckboxVal(name){
    var nameStr = "[name='" + name + "']:checked";
    var nameVal = [];
    $(nameStr).each(function(){
        nameVal.push($(this).val());   
    });
    return nameVal;
}

function setSelectManyCheckboxVal(name, values){
    var nameStr = "[name='" + name + "']";
    clearSelectManyCheckboxVal(name);
    //set
    $(nameStr).each(function(){
        for(var i = 0; i &lt; values.length; i++){
            var boxVal = values[i];
            if(boxVal == $(this).attr('value')){
                $(this).parent().parent().children().eq(1).click();
            }
        }  
    });
}

function clearSelectManyCheckboxVal(name){
    var nameStr = "[name='" + name + "']";
    $(nameStr).each(function(){
        if($(this).attr('checked') == "checked"){
            $(this).parent().parent().children().eq(1).click();
        }
    });
}

這裏寫圖片描述

p:selectManyCheckbox設置成一列的CSS

這裏寫圖片描述
http://stackoverflow.com/questions/20213248/render-pselectmanycheckbox-with-10-columns
這裏寫圖片描述

枚舉轉JSON

public void initType() {
    JSONArray types = new JSONArray();
    for (Type type : Type.values()) {
        JSONObject typeElement = new JSONObject();
        try {
            typeElement.put(type.toString(), type.getName());
            types.put(typeElement);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    putViewScope("types", types.toString());
}

添加消息提示

這裏寫圖片描述

MessageUtils.showFailedMessage("student.codeIsExist", FacesMessage.SEVERITY_ERROR);
RequestContextUtils.execute("_tutorialStudentInfoDlgForm_tutorialStudentInfoDlg_dialog.show();");
RequestContextUtils.execute("tutorialStudentInfoDlgCode.jq.addClass('ui-state-error')");

primeface判斷

value="#{element.skipped == true ? msg['dms']['yes']: msg['dms']['no']}" />

primeface顯示list集合

<p:column headerText="#{msg['dms']['substitutionUser']}">
    <ui:repeat var="user" varStatus="userStatus"
        value="#{element.users}">
        <p:outputPanel>
            <h:outputText value="#{user.username}" rendered="#{userStatus.index==0}" />
            <h:outputText value=" , #{user.username}" rendered="#{userStatus.index!=0}" />
        </p:outputPanel>
    </ui:repeat>
</p:column>

<p:column headerText="#{msg['dms']['substitutionUser']}">
    <c:forEach var="user" items="#{element.users}" varStatus="userStatus">
        <h:outputText rendered="#{userStatus.index==0}"
            value="#{user.username}" />
        <h:outputText rendered="#{userStatus.index!=0}"
            value=" , #{user.username}" />
    </c:forEach>
</p:column>

條件判斷

這裏寫圖片描述

style="display:#{(userStatus.index!=0) ? 'block' : 'none'};"

後臺調用前臺JS

這裏寫圖片描述

RequestContextUtils.execute("showOrgChart();");

label加星號
這裏寫圖片描述

後臺操作更新前臺

RequestContextUtils.update("pageTemplateListForm");

datatable保存的優化處理

HolidayTable[] selectHolidayTables = new HolidayTable[1];
        selectHolidayTables[0] = holidayTable;

primeface p:selectBooleanCheckbox js選中效果

substitutionTableChkIsSelect.check() 
substitutionTableChkIsSelect.uncheck(); 

primeface 表格是否有選中的數據

substitutionVar.checkSelection();

primeface 表格選中數據

putViewScope("selectTutorialStudents",
                new TutorialStudent[] { tutorialStudent });

primeface事件

<p:selectBooleanCheckbox
    value="#{viewScope.hasOtherRelationship}">
    <p:ajax event="change"
        update=":tutorialStudentInfoDlgForm:tutorialStudentInfoDlg:contentPanel"
        listener="#{controller.otherRelationshipChange}" />
</p:selectBooleanCheckbox>
接收方法:
public void otherRelationshipChange(AjaxBehaviorEvent event){
    Boolean value = ((SelectBooleanCheckbox)event.getSource()).isSelected();
    System.out.println("value:" + value);
}

JSTL替換’”’

<c:set var="search" value='"' />
<c:set var="replace" value='\\"' />
<c:out value="${fn:replace(userName, search, replace)}"/>

參考自:http://stackoverflow.com/questions/8898815/how-to-use-both-single-and-double-quotes-inside-jstl-el-expression

xmlns:fn

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

tomcat 增加內存配置

set JAVA_OPTS=-Xms512m -Xmx1256m -XX:PermSize=128m -XX:MaxPermSize=256m

這裏寫圖片描述

傳對象到後臺的方法

參考鏈接:https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/

public void courseClassDatesDlgShow(ActionEvent event) {
    Course course = (Course) event.getComponent().getAttributes()
                .get("course");
}

<p:commandButton value="#{msg['course']['showDate']}"
    actionListener="#{controller.courseClassDatesDlgShow}"
    update=":courseClassDatesForm"
    oncomplete="courseClassDatesDlg.show()"
    styleClass="table-toolbar-button" immediate="true">
    <f:attribute name="course" value="#{viewScope.course}" />
</p:commandButton>

常用方法

function datatableIsSelected(widgetVar) {
    getDatatableSelectRow(widgetVar);
    var status = widgetVar.checkSelection();
    if (!status) {
        alert("#{msg['framework']['selectRecordFirst']}!");
    }
    return status;
}

function datatableCheckDelete(widgetVar) {
    var selected = datatableIsSelected(widgetVar);
    if (selected){
        return confirm("#{msg['framework']['confirmDelete']}?");
    }
    return selected;
}

function datatableOnlySelectOne(widgetVar) {
    if(!datatableIsSelected(widgetVar)){
        return false;
    }
    if(getDatatableSelectRow(widgetVar) != 1){
        alert("#{msg['common']['canOnlySelectOneRecordOperation']}");
        return false;
    }
    return true;
}

function getDatatableSelectRow(widgetVar) {
    var chkboxSelectCount = 0;
    var $This = widgetVar.jq;
    $This.find(".ui-selection-column").each(function(){
        var $uiChkbox = $(this).find(".ui-chkbox");
        var isUiChkboxAll = $(this).find(".ui-chkbox").hasClass("ui-chkbox-all");
        if(!isUiChkboxAll) {
            if($uiChkbox.find(".ui-chkbox-box").hasClass("ui-state-active")){
                chkboxSelectCount++;
            }
        }
    });
    return chkboxSelectCount;
}
<p:column>
    <f:facet name="header">
        <h:outputText value="#{msg['student']['poorSubjectSort']}" />
    </f:facet>
    <c:set var="search" value='"' />
    <c:set var="replace" value='' />
    <h:outputText
        value="#{fn:replace(element.subject, search, replace)}" />
</p:column>

primeface修改dialog的值

//<![CDATA[ 
function showMessage(severity, content) {
    var html = '<div class="ui-messages-'+ severity +' ui-corner-all">'
             +      '<span class="ui-messages-'+ severity +'-icon"></span>'
             +      '<ul>';
    for(var i = 0; i < content.length; i++) {
        html += '<li><span class="ui-messages-'+ severity +'-detail">'+ content[i] +'</span></li>';
    }
    html += '</ul></div>';
    $("#tutorialStudentInfoDlgForm\\:tutorialStudentInfoDlg\\:tutorialMessages").html(html);
}
//]]>

<p:messages id="tutorialMessages" showDetail="true" showSummary="false" />
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章