If you are working with primefaces you will figure out that this framework implemented with JQuery library, this a good behaviour for jsf pages, if you try to do something with javascript, you have to keep in mind reading primefaces css to understand how get that component you need.
1. First Step should be declare the libraries in head part of JSF:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h:outputScript library="primefaces" name="jquery/jquery.js"/> | |
<script language="javascript" type="text/javascript" src="#{request.contextPath}/js/jquery-1.7.1.min.js"/> | |
<script language="javascript" type="text/javascript" src="#{request.contextPath}/js/position.js"/> |
2. Second step is to declare a position.js in your WEB-INF folder and write a function like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showMessageDialog(sourceElement, jqr) { | |
var x = getOffset(document.getElementById(sourceElement)).left; | |
var y= getOffset(document.getElementById(sourceElement)).top; | |
var parentSource = jqr.parent(); | |
var parent = jqr.parent(); | |
parent.find('.ui-dialog').each(function() { | |
jQuery(this).css('position', 'absolute'); | |
jQuery(this).css('width', '780px'); | |
}); | |
parent.addClass("autoWidthDialog"); | |
parent.offset({ | |
top: y-85 //change Y position in pixels | |
,left: x-3 //change X position in pixels | |
}); | |
MessageDialog.show(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<p:commandLink onmouseover="showMessageDialog('form50:selectLocationButton', PoliticaDialog.jq);"> | |
<h:outputText id="selectLocationButton" value="Show MessageDialog"/> | |
</p:commandLink> | |
<p:dialog modal="true" widgetVar="statusDialog" header="Process..." draggable="false" | |
closable="false"> | |
<img src="#{request.contextPath}/images/ajaxloadingbar.gif"/> | |
</p:dialog> | |
... | |
<p:panel id="popup" style="border:0px"> | |
<p:dialog position="left top" id="MessageDialog" widgetVar="MessageDialog" | |
header="Something to describe the conten"> | |
<h:outputText value="Content of the Message...."/> | |
</p:dialog> | |
</p:panel> |
And that is it, you can take the control of any primefaces component rendered in the JSF page, using JQuery.
Best Regards,
No comments:
Post a Comment