jboss-seam-pdf inside rich:modalPanel cannot work - java

I have a modalPanel declared as
<rich:modalPanel id="printEmailExcel" minWidth="800" minHeight="600" resizable="true">
<div style="width: 1055px; height: 700px; overflow: auto">
<s:decorate template="/view/popup/printEmailExcelPopup.xhtml"styleClass="popupCDiv">
<ui:param name="panelid" value="printEmailExcel" />value="/view/printForm/order.xhtml" />
</s:decorate>
</div>
</rich:modalPanel>
There is also a commandbutton to show the modalPanel in the same page
<s:button oncomplete="#{rich:component('printEmailExcel')}.show()" image="/images/icons/btn_print.gif" ></s:button>
inside the printEmailExelPopup.xhtml, there is a
<h:form><s:button view="/view/print/order.xthml" /></h:form>
order.xhtml :
<p:document xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://jboss.com/products/seam/pdf">
The document goes here.
< /p:document>
The problem is that when i click the s:button in the modalPanel, it only refresh the whole page and the pdf file IS NOT downloaded. However, if i place the s:button outside the modalPanel(same level of the rich:modalPanel, it works normally). Any Help?

try surrounding your commandButton with form tags.

Related

Jsoup parsing for nested html

I have an HTML to parse with Jsoup and I lose track after the HTML's weird structure. I can summarize HTML like this(Every line is one level inside of the above):
<html>
<body class="page3078">
<div id="mainCapsule">
<div id="contentCapsule" class="capsule">
<div id="content">
<div id="subCapsule" class="clearFix" xmlns="">
<div id="contentLeft">
<iframe width="635" height="1000" frameborder="0" src="apps/Results.aspx">
#document
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background:none;">
<form id="form1" action="Results.aspx" method="post" name="form1">
<div class="pressContent">
<div class="tableCapsule details">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="even">
Basically I want to get text inside of the tag with class "even". I tried directly calling class even like this:
doc.getElementsByClass("even")
It didn't work. I tried parent > child relationship with selector method. It didn't work either. I tried this inside of second html tag:
doc.select("body.page3078 > html > body > #form1 > th");
Didn't work either. Where am I wrong?
One comment summarizes the start of a solution here:
As mentioned here you need to get the page from the iframe in a separate jsoup parser. This page isn't weird at all - it's just a separate page is shown in the iframe. – Boris the Spider

How to get content of iframe using GWT Query?

I trying to do like this:
$("iframe.cke_dialog_ui_input_file").contents()
but it returns:
< #document(gquery, error getting the element string representation: (TypeError) #com.google.gwt.dom.client.DOMImplMozilla::toString(Lcom/google/gwt/dom/client/Element;)([JavaScript object(8570)]): doc is null)/>
But document is not null!
Help me please to solve this problem :(
UPD. HTML CODE:
<iframe id="cke_107_fileInput" class="cke_dialog_ui_input_file" frameborder="0" src="javascript:void(0)" title="Upload Image" role="presentation" allowtransparency="0">
<html lang="en" dir="ltr">
<head>
<body style="margin: 0; overflow: hidden; background: transparent;">
<form lang="en" action="gui/ckeditor/FileUploadServlet?CKEditor=gwt-uid-7&CKEditorFuncNum=0&langCode=en" dir="ltr" method="POST" enctype="multipart/form-data">
<label id="cke_106_label" style="display:none" for="cke_107_fileInput_input">Upload Image</label>
<input id="cke_107_fileInput_input" type="file" size="38" name="upload" aria-labelledby="cke_106_label">
</form>
<script>
window.parent.CKEDITOR.tools.callFunction(90);window.onbeforeunload = function() {window.parent.CKEDITOR.tools.callFunction(91)}
</script>
</body>
</html>
</iframe>
First get the iframe element using javascript like your existing cod and store it into Iframe of GWT
IFrameElement iframe = (IFrameElement) element;
Now use iframe to get content
iframe.getContentDocument().getBody().getInnerText();
Hope it help you to get values.
The contents() method returns the HTMLDocument, so normally you have to find the <body> to manipulate it.
$("iframe.cke_dialog_ui_input_file").contents().find("body");
A common mistake is to query the iframe before it has been fully loaded, so code a delay using a Timer, Scheduler or GQuery.delay(). For instance:
$("iframe.cke_dialog_ui_input_file")
.delay(100,
lazy()
.contents().find("body")
.css("font-name", "verdana")
.css("font-size", "x-small")
.done());

Javascript function not working inside composite control JSF [duplicate]

This question already has answers here:
Adding <h:form> causes java.lang.IllegalStateException: Cannot create a session after the response has been committed
(5 answers)
Closed 7 years ago.
I have a composite control as below;
&LT;html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<composite:interface>
<composite:attribute name="validatorId"/>
<composite:attribute name="message"/>
</composite:interface>
<composite:implementation>
<div>
<script type="text/javascript">
function #{cc.attrs.validatorId}(){alert('why is it not working :(');};
</script>
<div style="background-color: #F2DEDE;color: #b94a48;border-style: solid;border-color: #FAC3CB;border-width: 1.8px;font-family: Arial;
font-size: 12px;height:17px;vertical-align: middle;padding-left: 8px;padding-right: 8px;padding-top: 2px;display: none;"
id="#{cc.attrs.validatorId}">
#{cc.attrs.message}
<img src="images/close-mini.png" style="cursor: pointer;padding-left: 5px;"/>
</div>
</div>
</composite:implementation> </html>
This control is placed in a xhtml file.The javascript and composite controls are rendering as the expected way. But when a request is made to xhtml following exception occurs at Glassfish Server :
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed.
What can be the reason? When I remove the javascript function exception doesn't occurs.
The following prerender listener is added at composite control,
<f:event type="preRenderView" listener="#{fieldValidatorBean.PreRenderValidator}"/>
and inside the listener function,
public void PreRenderValidator(){
FacesContext.getCurrentInstance().getExternalContext().getSession(true);
System.out.println("prerender being called");
}
to reenable session. Thanks #BalusC.

JSF Component IDs ignored when dynamically generating Views

I ran into a bit of a problem.
I generate Views dynamically by iterating a list of strings via the c:forEach tag
and then including them via the facelets include tag.
This works fine for building the layout but shows some strange behaviour.
I have a primefaces tabview containing 2 tabs.
For the first Tab (the one that gets initially displayed) the component id is set (eg. tabview:categoryTab) but that's not the case for e.g. the second tab, here I only get tabview: for the component id (but it actually should be tabview:usrTab)
Why does JSF override the id I set for the second Tab? Am I missing some crucial information from the spec?
I use JSF 2 with Primefaces 3.6 (snapshot build)
(And yes, I use the snapshot build on purpose and have tested this with stable PF releases as well but the same behaviour occurs)
edit
Code:
admin.xhtml
<ui:composition template="/templates/commonLayout.xhtml">
<ui:define name="content">
<p:panel id="parentPanel">
<h:outputText value="Verwaltung" />
<br />
<p:tabView id="tabview">
<!-- insert marker -->
<c:forEach items="#{adminTabs}" var="tab">
<ui:include src="#{tab}" />
</c:forEach>
</p:tabView>
</p:panel>
</ui:define>
</ui:composition>
catTab.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:tab title="Categories Tab" id="catTab">
....
</p:tab>
</ui:composition>
usrTab.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:tab title="Users Tab" id="usrTab">
....
</p:tab>
</ui:composition>
testTab.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:tab title="TestTab" id="testTab">
....
</p:tab>
</ui:composition>
ContentProvider.java
public class ContentProvider {
....
#Produces
#Named("adminTabs")
public List<String> getTabs(){
List<String> components = new ArrayList<String>();
components.add("/templates/tabs/catTab.xhtml");
components.add("/templates/tabs/usrTab.xhtml");
components.add("/templates/tabs/testTab.xhtml");
return components;
}
....
}
This gets generated:
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist">
<li class="ui-state-default ui-tabs-selected ui-state-active ui-corner-top" aria-expanded="true" role="tab">
Categories
</li>
<li class="ui-state-default ui-corner-top" aria-expanded="false" role="tab">
TestTab
</li>
<li class="ui-state-default ui-corner-top" aria-expanded="false" role="tab">
Benutzer und Rollen
</li>
</ul>
So, to reiterate: Only the id for the first tab is retained, the ids for the other tabs are generated despite being set in the xhtml code...
I ran into something very similar with Richfaces 4 and JSF 2. I managed to hack around it by including an EL expression in the id attribute. For me
<h:form id="staticName">
was being rendered into
<form id="j_idblah>
but once I did
<h:form id="#{_objectInContext}">
it began rendering properly. Pretty hacky, but for now it'll work. Good luck!!
I ran into the same problem when including facelets with a c:forEach loop.
What worked for me was specifying the Ids as EL-Constants: id="#{'address_street'}"

Partial rendering JSF components

dwelling over how to partial render (divs), by including different source files (with panels and components). Depending on menu actions. If understood the JSF phases correctly, the View is rebuilt during the Render Response, the last phase. And if I have events and actions, they will be invoked during the Invoke Application phase, the phase before.
All I want to do is to set the including xhtml page for a specific menu command via ajax, before the View is re-rendered. But the ui:include always get invoked before the menu action. I've tried with richfaces 4 (a4j:param, rich:panel, etc) and standard JSF 2.0 (f:param, h:panelGroup) components, but the the ui:include always get invoked before the action.
What should I do to process the menu action (to set the including page), before the ui:include gets invoked?
PS. This must be the standard patter, instead of including static content. But I find very few examples on this on the net ?!
Menu.xhtml
<rich:toolbar itemSeparator="line">
...
<rich:dropDownMenu mode="ajax">
<f:facet name="label">
<h:panelGroup>
<h:outputText value="Menu 1" />
</h:panelGroup>
</f:facet>
<rich:menuItem id="newActivityMenu" action="#{navigationBean.menuAction}" render="content" label="New">
<a4j:param id="newActivityParam" name="includeContentPage" value="/user/Create.xhtml" />
</rich:menuItem>
...
NavigationBean.Java
#ManagedBean
#RequestScoped
public class NavigationBean {
public String menuAction() {
String param = JsfUtil.getRequestParameter("includeContentPage");
this.includedContentPage = param;
JsfUtil.log(this, "Including Content Page : " +param);
FacesContext.getCurrentInstance().renderResponse();
return "";
}
public String getIncludedContentPage() {
if(includedContentPage == null)
return "";
else if(!includedContentPage.endsWith(".xhtml"))
includedContentPage += ".xhtml";
JsfUtil.log(this, "Get Content Page : " +includedContentPage);
return includedContentPage;
}
layoutClient.xhtml
...
<ui:define name="top">
<ui:include src="/resources/viewComponents/menuTop.xhtml"/>
</ui:define>
<ui:define name="content">
<ui:include src="#{navigationBean.includedContentPage}"/>
</ui:define>
...
masterLayout.xhtml (added)
...
<h:body>
<div id="top" >
<ui:insert name="top">Top Default</ui:insert>
</div>
<div id="left">
<ui:insert name="left">Left Default</ui:insert>
</div>
<ui:insert name="content">Content Default</ui:insert>
</h:body>
..
You must have a template page as well since you are defining top and content in layoutClient.xhtml so I think you are trying to be too general with the layoutClient.xhtml page as it appears to be functioning as a template as well. Lets assume your template page is called template.xhtml. The standard pattern you eluded to is to make your template page something like this:
template.xhtml
...
<ui:insert name="top">
<ui:include src="/resources/viewComponents/menuTop.xhtml"/>
</ui:insert>
...
<ui:insert name="content" />
...
This means that all your pages contain the menu at the 'top' (by default, they can override this) and that they must specify their own content, which makes sense.
Now, instead of trying to make a page like layoutClient.xhtml that does tricky stuff to determine which content is inserted, create each page seperately like this:
page1.xhtml
<ui:composition template="template.xhtml">
...
<ui:define name="content">
<p>This is a page that defines some content and also includes my menu that it inherits from template.xhtml</p>
</ui:define>
...
</ui:composition>
page2.xhtml
<ui:composition template="template.xhtml">
...
<ui:define name="content">
<p>This is another page that defines some content and also includes my menu that it inherits from template.xhtml</p>
</ui:define>
...
</ui:composition>
Both of these pages inherit your menu and put the content in the appropriate place.
With that kind of configuration, all your menuAction() method needs to do is return a link to page1.xhtml or page2.xhtml. Also, you don't need any complex use of parameters or manual calls to renderResponse() or a4j:param tags!

Categories