I am trying to upload an image in jsf am using primefaces. However am facing challenges or even stack on how to show Image Preview after a user browse the image on a click of a preview button.
Here is my design
And here is my code snippet
public StreamedContent getImage()throws Exception {
//no idea how to get the uploaded file before submit
}
<div class="row" style="margin-top: 4px">
<div class="col-md-2">
<p:outputLabel for="fleet_insure" value="Fleet Insurance" />
</div>
<div class="col-md-3">
<p:fileUpload id="fleet_insure"
mode="simple"
accept=".png,.PNG,.JPEG,.jpeg,.JPG,.jpg"
validatorMessage="Only images accepted"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
value="#{rider.insurance}"
oncomplete="#{rider.onChange(this)}"
auto="false" />
</div>
<div class="col-md-2">
<p:commandButton update="prev" oncomplete="PF('prev').show()" style="background: #6e256a;color:white;" value="Preview Insurance" icon="fa fa-eye">
</p:commandButton>
</div>
</div>
<p:dialog widgetVar="prev" id="prev" header="Document Preview" width="500" height="400" resizable="false">
<p:graphicImage value="#{rider.image}" height="380" width="480" />
</p:dialog>
Related
I have h:form in PrimeFaces p:dialog. All other components works fine, even the p:selectOneMenu, but value of p:inputText is not bound to bean and gives null.
<p:dialog header="Delivery Schedule" id="deleditdlg" widgetVar="deleddlg1" showEffect="clip"
hideEffect="clip" styleClass="dialogwidth"
modal="true" appendTo="#(body)" closable="true" width="500">
<h:form id="saveform">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<h:outputLabel style="font-weight: bold;"
value="Timing: "></h:outputLabel>
<br/>
<p:inputText value="#{deliveryScheduleBean.deliverySchedule.vehTiming}"></p:inputText>
</div>
<div class="col-md-3">
<h:outputLabel style="font-weight: bold;"
value="Status: "></h:outputLabel>
<br/>
<p:selectOneMenu value="#{deliveryScheduleBean.deliverySchedule.vehStatus}">
<f:selectItem itemLabel="Active" itemValue="0"></f:selectItem>
<f:selectItem itemLabel="Inactive" itemValue="1"></f:selectItem>
</p:selectOneMenu>
</div>
</div>
<br />
<div class="row">
<div class="col-md-4 ml-auto">
<p:commandButton class="btn btn-success" process="saveform"
action="#{deliveryScheduleBean.updateSchedule}" value="Save"></p:commandButton>
</div>
</div>
</div>
</h:form>
</p:dialog>
I have a weird problem with jsf components (h:inputFile & h:selectBooleanCheckbox).
Both components receive focus, even when my mouse is somewhere else on the page. Here is the code:
<h:form id="logoUpload" enctype="multipart/form-data">
<div>
<h:outputLabel rendered="true">
<h:inputFile id="companyLogo" label="file" value="#{fileHandlerBean.part}" >
<f:validator validatorId="FileUploadValidator" />
</h:inputFile>
</h:outputLabel>
</div>
<div class="clear" />
<h:outputLabel rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" value="#{companyEditController.confirmToU}">
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"
action="#{companyEditController.companyLogoUpload()}"
actionListener="#{fileHandlerBean.uploadCompanyLogo()}"
disabled="#{!companyEditController.confirmToU}"/>
</div>
</h:outputLabel>
</h:form>
If I move the mouse over the h:outputText the checkbox receives focus.
I had the same problem with the h:inputFile tag. I solved it by surrounding it with a h:outputLabel tag, but unfortunately it doesn´t workd with the selectBooleanCheckbox.
Did somebody have the same problem in the past and knows a solution?
This is because everything is wrapped in the h:outputLabel tag. This outputLable is rendered as a plain label html element.
You can see form the W3C specification that anything inside the label will toggle the control
The element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control
To fix this, you need to replace the h:output label tag using a h:panelGroup layout="block" which renders a <div>:
<h:panelGroup layout="block" rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" >
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"/>
</div>
</h:panelGroup>
I have a page 'report1.xhtml'and 'report2.xhtml'both of which is using the same template 'template.xhtml'.
Here's 'template.xhtml':
<pe:layout fullPage="true" id="collapsibleLayoutPanel" stateCookie="false" widgetVar="templateLayoutWidget" style="100%;">
<pe:layoutPane id="topPanel" styleClassContent="topPanel unhideMenus" position="north" resizable="false"
closable="false" spacingClosed="0" spacingOpen="0">
<p:outputPanel id="dg">
<p:outputPanel id="dMHeader" styleClass="A_class Amarks_top">
#{tController.classificationMarking}
</p:outputPanel>
</p:outputPanel>
<div id="Ar" class="Aer" role="banner">
<div id="my_apps" style="display:none;">
<h:outputLink rendered="#{primaryMenuController.renderReturnToMyApps}"
value="#{primaryMenuController.myAppsUrl}">
<img id="my_apps_img" src="#{request.contextPath}/resources/img/my_apps.png" alt="My Apps"
title="My Apps"/>
</h:outputLink>
</div>
<b:navBar brandImg="#{request.contextPath}/resources/img/X_logo.png"
brandHref="#{request.contextPath}/view/landingPage.jsf">
<b:navbarLinks>
<div class="ui-grid-col-6">
<ui:include src="prnu.xhtml"/>
</div>
<div class="ui-grid-col-6">
<div id="A_logout">
<h:form id="helpLogoutForm">
<p:menubar styleClass="Aout_menu" autoDisplay="false">
<p:submenu
label="#{pController.name} (#{pController.accountType})"
icon="primnav-user-acct">
<p:menuitem id="myDashboardLink" value="My Dashboard"
action="landingPage" a:allowRead="true"
icon="primnav-dashboard"/>
<p:menuitem id="myMessagesLink" value="My Messages"
action="userMessageList" a:allowRead="true"
icon="primnav-inbox"/>
<p:menuitem id="myPrefLink" value="My Preferences"
oncomplete="PF('upDialog_widget').show();"
a:allowRead="true" icon="primnav-preferences"/>
<p:separator/>
<p:menuitem id="logoutLink" value="Logout"
action="#{primaryMenuController.logout}"
a:allowRead="true" onclick="X.logoutHandler();"
icon="primnav-logout" ajax="false"/>
</p:submenu>
<p:submenu icon="primnav-help">
<p:menuitem value="Help"
onclick="window.open('#{request.contextPath}/help/default.htm', 'Help', 'height=600,width=850,resizable=yes'); return false;"
icon="primnav-help_menu_child" a:allowReadHelp="true"/>
<p:menuitem value="About"
action="#{aController.updateMemoryValues()}"
oncomplete="PF('aboutDialog_widget').show();"
a:allowRead="true" icon="primnav-help_menu_child"
update=":aboutDialog"/>
</p:submenu>
</p:menubar>
</h:form>
</div>
</div>
</b:navbarLinks>
</b:navBar>
</div>
<ui:insert name="tertiaryNavMenu"/>
</pe:layoutPane>
<!-- Main content -->
<pe:layoutPane id="centerPanel" styleClassContent="centerPanel" position="center" spacingClosed="0"
spacingOpen="0">
<pe:layoutPane position="north" id="nestedTopPanel" size="45" resizable="false" closable="false"
styleClassContent="unhideMenus"
spacingClosed="0" spacingOpen="0" rendered="#{not hideTitleActionBar}">
<div id="A_content" class="AE_content" role="main">
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row template-header">
<div class="ui-grid-col-3 template-title">
<div id="A_content_pagetitle" class="AE_content_pagetitle">
<h1 class="pagetitle_h1"><ui:insert name="contentHeader"></ui:insert></h1>
</div>
</div>
<div class="ui-grid-col-9 template-actions">
<div class="action_buttons">
<ui:insert name="actionMenu"></ui:insert>
</div>
</div>
</div>
</div>
</div>
</pe:layoutPane>
<pe:layoutPane position="center" id="nestedCenterPanel" spacingClosed="0" spacingOpen="0">
<div id="A_content_body" class="A_content_body" style="padding:0 12px;">
<p:growl id="siteMessages" globalOnly="true" showDetail="true" life="4000" autoUpdate="false"
widgetVar="siteMessages_widget"
sticky="#{not empty facesContext.maximumSeverity and facesContext.maximumSeverity.ordinal gt 1}"/>
<ui:insert name="content"></ui:insert>
</div>
</pe:layoutPane>
</pe:layoutPane>
<!-- Bottom markings -->
<pe:layoutPane id="bottomPanel" styleClassContent="bottomPanel" position="south" resizable="false"
closable="false" spacingClosed="0" spacingOpen="0">
<!-- TODO: Determine classification marks to display -->
<!-- BEGIN FOOTER -->
<p:outputPanel styleClass="A_classmarking AE_body_classmarks_bottom" id="documentMarkingFooter">
#{tController.classificationMarking}
</p:outputPanel>
<!-- END FOOTER -->
</pe:layoutPane>
</pe:layout>
When I load report1.xhtml and resize window to iPhone size(640x960) everything works as expected and the burger menu onclick is showing the previously hidden menu options. However after the onchange event that causes page forward to report2.xhtml, the burger menu onclick is no longer working.. It's still clickable but nothing happens after clicking it.. If I make the navigation redirect instead of page forward, everything works just fine, so my conclusion is this has something to do with page forward...
After debugging on the devtools console I've got this error showing up after page load(for page forward only):
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
The source js is http://localhost:8080/javax.faces.resource/jquery/jquery.js.jsf?ln=primefaces&v=5.2.7
Then on resize I've got this error from source https://raw.githubusercontent.com/primefaces-extensions/core/master/src/sourcemap/3.2.0/layout.source.js:
Uncaught TypeError: Cannot read property 'state' of undefined
Again, note that those errors only occur when navigation is page forward and goes away when doing a redirect. I don't want to do a redirect because I want the URL to stay the same..
i use primefaces 5.2 and i want to add a commandbutton to a tab inside a tabview.
Code to test:
<p:tabView>
<p:tab>
<f:facet name="title">
<h:outputText value="Error Log"/>
<p:commandButton icon="fa fa-refresh" id="fetcherror" update="form:msg errorlogpane" style="margin-left: 12px;"/>
</f:facet>
<p:scrollPanel id="errorlogpane" style="height: 300px">
</p:scrollPanel>
</p:tab>
</p:tabView>
I want a label and at the right a button inside the tab to reload the tab content. The Button does not need any text, just an icon to show the functionality.
But if i deploy the above code the icon is not correct in place as you can see in the following picture
The Resulting html code is:
<li class="ui-state-default ui-tabs-selected ui-state-active ui-corner-top" role="tab" aria-expanded="true" aria-selected="true">
<a href="#form:j_idt29:j_idt30" tabindex="-1">Error Log<button id="form:j_idt29:fetcherror" name="form:j_idt29:fetcherror" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" style="margin-left: 12px;" type="submit">
<span class="ui-button-icon-left ui-icon ui-c fa fa-refresh"></span>
<span class="ui-button-text ui-c">ui-button</span>
</button>
</a>
</li>
What is the problem with this tab design? How can i fix it? Any suggestion helps :)
I am using to enter address field .by default am setting active-index="-1" so the panel will be closed when the page gets loaded.After the details has been entered by user i want the panel area which means i want the accordion panel to be closed on button(save) click.but i tried a lot using java script but am not able to achieve ,and here is page
<h:body>
<ui:composition template="/WEB-INF/templates/layout.xhtml">
<ui:define name="content">
<h:form id="quotesForm">
<div class="headerbg">
<div id="innerheaderbg">
<div id="iconarea">
<img src="#{request.contextPath}/images/headerimages/productlist.png" />
</div>
<div id="headertextarea">
<p class="headingtext">New Quote</p>
<p id="breadCrumbtext">Order <img src="#{request.contextPath}/images/error-bullet.gif" />
Quote List <img src="#{request.contextPath}/images/error-bullet.gif" />
New Quote
</p>
</div>
</div>
</div>
<p:growl id="msgs" />
<div class="widget widget-table action-table">
<div class="widget-header" style="text-align:center;padding-top: 52px">
<h3>Create New Quote</h3>
</div>
<div class="widget-content" style="background-color: #DAEDF4;height: 600px;" >
<div id="calender" style="margin-left: 52px;margin-top: -26px">
<table>
<tr>
<td>
<p:outputLabel id="qDate" value="#{quotesBean.qtCreationDate}"></p:outputLabel>
</td>
<td>
<p:calendar id="popup" showOn="button" display="inline" >
<p:ajax event="dateSelect" listener="#{quotesBean.onDateSelect}" update="qDate" />
</p:calendar>
</td>
</tr>
</table>
<p:outputLabel value="Invoice # #{quotesBean.qCount}" style="margin-top:-15px;margin-left:10px;"/>
</div>
<div id="company">
<table align="right" style="margin-right: 52px">
<thead>
<tr>
<th style="text-align: center;padding: 0;"><img src="#{request.contextPath}/images/favicon.ico"/><p:spacer width="5px"/>SolvEdge</th>
</tr>
</thead>
<tr><td style="text-align: center;padding: 0;">Zameen Pallavaram,</td></tr>
<tr><td style="text-align: center;padding: 0;">Chennai,</td></tr>
<tr><td style="text-align: center;padding: 0;">INDIA</td></tr>
</table>
</div>
<h:form id="addForm">
<p:accordionPanel id="accordion" cache="false" activeIndex="-1" style="margin-bottom:20px;width:330px;" widgetVar="acc" >
<p:tab title="Bill To Address:" titleStyle="width:330px;background-color:#DAEDF4" >
<h:panelGrid columns="2">
<h:outputLabel value="Name" />
<h:inputText value="#{quotesBean.name}"/>
<h:outputLabel value="Street" />
<h:inputText value="#{quotesBean.street}"/>
<h:outputLabel value="City" />
<h:inputText value="#{quotesBean.city}"/>
<h:outputLabel value="ZIP" />
<h:inputText value="#{quotesBean.zip}"/>
</h:panelGrid>
<p:commandButton icon="ui-icon-save" value="Save" action="#{quotesBean.saveAddress}" update=":quotesForm:addForm:accordion" ajax="false" onclick="PF('quotesForm:addForm:accordion').hide();"/>
</p:tab>
</p:accordionPanel>
</h:form>
</div>
</div>
<script type="text/javascript">
var link = document.getElementById('quotesForm:popup_input');
link.style.display = 'none';
function closeAccordianPanel()
{
var panel = document.getElementById('quotesForm:addForm:accordion');
link.style.activeIndex = '-1';
/* PF('widget_accordion').unselect(0); */
}
</script>
</h:form>
<br></br>
</ui:define>
</ui:composition>
</h:body>
</html>
Note:Java Script i tried here is nothing worked for me,i would like to close the accordion panel on button click.
I bet you have javascript errors in the console...(PF('quotesForm:addForm:accordion').hide(); is wrong, it should be PF('acc').hide(); IF it works at all (nothing about that in the PrimeFaces docs). And why close a ui component via javascript if you do an 'ajax="false"'. And sending a click event to the tab you want to toggle works, but even better is to use the official client-side api: PF('acc').unselect(...);
Ahhhh... you have additional code below the commandbutton... but there is a wrong widgetVar value... and it is commented out... and the other part does nothing...
Unselect(index of tab) method only hide the p:tab.
If you want to hide your accordionPanel, you can use rendered attribute.
Here is the panel:
<p:panel id="toggleable" header="Toggleable" toggleable="true"
toggleOrientation="horizontal" toggleSpeed="500" closeSpeed="500"
widgetVar="panel" class="left-menu-panel" >
</p:panel>enter code here`
and button or commandLink which collapse panel
<p:commandLink styleClass="open-left-menu-button"
onclick="PF('panel').toggle()">
</p:commandLink>
You can set it with toggleOrientation="horizontal/vertical".
normal panel - not collapsed
collapsed