我是靠谱客的博主 虚拟缘分,这篇文章主要介绍primeface eg,现在分享给大家,希望可以做个参考。

枚举的处理:

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

复制代码
1
2
3
4
5
6
7
8
<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框赋值:

复制代码
1
document.getElementById("orgChartForm:orgChartNodeIndex").value = index;

多选框赋值:

复制代码
1
2
3
4
5
6
7
8
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:

复制代码
1
2
3
4
5
6
7
8
9
10
11
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());

操作提示

复制代码
1
@MessageRequired(type = MessageType.SAVE)

数据库查询数目操作

复制代码
1
2
@Query("select count(state) from DeceasedState state where state.serviceTransaction.serviceCode =:serviceCode") public Long findCountQueryCode(@Param("serviceCode") ServiceCode serviceCode);

JS方法传参到primeface后台

复制代码
1
import javax.faces.context.FacesContext;

这里写图片描述
这里写图片描述
这里写图片描述

双击事件后传递对象

复制代码
1
2
3
4
5
6
public void onRowSelect(SelectEvent event) { Semester semester = (Semester) event.getObject(); semester.setIndex(semester.getIndex() + 1); putViewScope("semesterObject", semester); initSemester(); }

这里写图片描述

遍歷節點

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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取值设值的解决方法

这里写图片描述

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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()); }

添加消息提示

这里写图片描述

复制代码
1
2
3
MessageUtils.showFailedMessage("student.codeIsExist", FacesMessage.SEVERITY_ERROR); RequestContextUtils.execute("_tutorialStudentInfoDlgForm_tutorialStudentInfoDlg_dialog.show();"); RequestContextUtils.execute("tutorialStudentInfoDlgCode.jq.addClass('ui-state-error')");

primeface判断

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

primeface显示list集合

复制代码
1
2
3
4
5
6
7
8
9
<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>

复制代码
1
2
3
4
5
6
7
8
<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>

条件判断

这里写图片描述

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

後臺調用前臺JS

这里写图片描述

复制代码
1
RequestContextUtils.execute("showOrgChart();");

label加星号
这里写图片描述

后台操作更新前台

复制代码
1
RequestContextUtils.update("pageTemplateListForm");

datatable保存的優化處理

复制代码
1
2
HolidayTable[] selectHolidayTables = new HolidayTable[1]; selectHolidayTables[0] = holidayTable;

primeface p:selectBooleanCheckbox js選中效果

复制代码
1
2
substitutionTableChkIsSelect.check() substitutionTableChkIsSelect.uncheck();

primeface 表格是否有選中的數據

复制代码
1
substitutionVar.checkSelection();

primeface 表格選中數據

复制代码
1
2
putViewScope("selectTutorialStudents", new TutorialStudent[] { tutorialStudent });

primeface事件

复制代码
1
2
3
4
5
6
7
8
9
10
11
<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替换’”’

复制代码
1
2
3
<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

复制代码
1
xmlns:fn="http://java.sun.com/jsp/jstl/functions"

tomcat 增加內存配置

复制代码
1
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/

复制代码
1
2
3
4
5
6
7
8
9
10
11
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>

常用方法

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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; }
复制代码
1
2
3
4
5
6
7
8
9
<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的值

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//<![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" />

最后

以上就是虚拟缘分最近收集整理的关于primeface eg的全部内容,更多相关primeface内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部