Using the camera with the XPages Mobile Controls - xpages

In my XPages Mobile Controls singlePageApp I want to provide an interface for the user to upload a new photo or choose an existing photo from their photo library on their phone. I am using the following code:
<xp:fileUpload id="fileUpload1" value="#{document1.CapturedImage}" useUploadname="false"
filename="camerasnap.png" accept="image/*">
</xp:fileUpload>
The above works fine WHEN the user chooses to launch my mobile app from an icon that they added to their home screen (i.e. in standalone mode).
However, if they launch from their mobile web browser (i.e. web application mode) when they tap the fileUpload to "Choose File" they can attempt to take a picture or select an existing photo but they are always returned to the page with "no file selected" next to the [Choose File] button.
What can I do to enable the camera/photo selection for my web application mode users ... ie most users?

This is a modified version from XControls 1.5 Sampler:
<xp:fileUpload id="fileUpload1" styleClass="fileInput"
style="position:absolute;
width:100%;
min-height: 182px;
opacity:0;"
value="#{document1.CapturedImage}"
useUploadname="false"
filename="camerasnap.png"
accept="image/*">
<xp:this.attrs>
<xp:attr name="accept"
value="image/*">
</xp:attr>
<xp:attr name="type"
value="file">
</xp:attr>
<xp:attr name="capture"
value="camera">
</xp:attr>
<xp:attr name="onchange">
<xp:this.value><![CDATA[
var file = event.target.files[0];
unp.photoUploader.loadImage(file);
]]></xp:this.value>
</xp:attr>
</xp:this.attrs>
</xp:fileUpload>
Try adding browser object element attributes using <xp:attr>. Cheers.

The solution is to put the fileUpload on a separate XPage and then source it in an iframe on the appPage.
Very eloquently presented by dominoguru Chris Toohey in blog post with accompanying video here:
http://www.dominoguru.com/page.xsp?id=xpage_fileupload_extlib_dialog_tutorial.html

Related

Xpages Link Open New Browser Tab

I have found a few similar questions to this in stackoverflow but nothing exactly matches. I am attempting to amend an Xpages project where the search results are shown in a Dynamic View Panel. The first column of the search results is a link that opens the record in the same page. What I want to do is have this link open the record in a seperate page. It is the "Dynamic" part of the view that is confusing I think as there is no "Column Name" or "Column View" to add in a window.open or a target="_blank" that I can see. How would I go about this please?
The relevant section of the XPage only has the following;
<xp:panel id="maincontentpanel">
<xe:dynamicViewPanel rows="30" id="dynamicViewPanel1" width="100%">
<xe:this.data>
<xp:dominoView viewName="(keywordsUser)" var="view">
</xp:dominoView>
</xe:this.data>
</xe:dynamicViewPanel>
</xp:panel>
When viewing the source in HTML the clickable column shows the following;
<tr>
<td class="xspColumnViewStart">
<a id="view:_id1:cc4cconeuilayout:OneUIMainAreaCallback:dynamicViewPanel1:0:_id6:_internalColumnLink"
href="*routetoourrecord*";action=editDocument"
class="xspLinkViewColumn">2014</a>
</td>
Dynamic View Panel has a property "target" in All Properties where you can select "_blank". This should add the attribute target="_blank" to the links in first column. But, unfortunately, this works in Notes client only.
So, there is no property we just can set. Luckily, rendered links have an own class "xspLinkViewColumn" (see your source HTML example). With dojo.query we can get all elements with this class and add the target attribute on client side.
Just add following event code to your XPage:
<xp:eventHandler
event="onClientLoad"
submit="false">
<xp:this.script><![CDATA[
dojo.query(".xspLinkViewColumn").attr("target", "_blank");
]]></xp:this.script>
</xp:eventHandler>
All links will get the attribute target="_blank" this way and documents will be opened in a new browser tab.
Just to let know the code does not to work with the Bootstrap theme.
Instead you can use
dojo.query('[id$="_internalColumnLink"]').attr("target", "_blank");

Links within XPage Mobile Controls opening in same tab on iPad

I have to create a simple XPages application for iOS devices so want to use the XPages Mobile Controls which come with the Extension Library in 8.5.3 UP1.
On one of the pages, I need the users to be able to open links in new tabs, but I've found that even with the link target set to _blank, the links are opening in the same tab when opened on the iPad. It works fine using Chrome on my laptop - opening in a new tab. If I just create a simple XPage (not using the Single Page App control) with the same link control on it, the link opens ok in a separate tab on the iPad.
Is there any way to try and force the link into a new tab if I use the Mobile controls?
This is code from a simple test xpage - which results in the link opening in the same tab when I test it on an iPad:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex" defaultLinkTarget="_blank">
<xe:singlePageApp id="singlePageApp1" selectedPageName="homePage">
<xe:appPage id="appPage1" pageName="homePage">
<xe:djxmRoundRectList id="djxmRoundRectList1">
<xp:label value="File Link:" id="FileLinkLabel"></xp:label>
<xp:br></xp:br>
<xp:link escape="true" text="Link" id="link1"
value="http://www.stackoverflow.com/" target="_blank">
</xp:link>
</xe:djxmRoundRectList>
<xe:djxmHeading id="djxmHeading1" label="Home">
</xe:djxmHeading>
</xe:appPage>
</xe:singlePageApp>
</xp:view>
I tried this out on an iPad with Domino v9.0.1 and on v8.5.3 (with ExtLib v853.20130315-0724 installed). In both cases the link opened in a new tab as expectedusing the code you posted.
Would you be able to upgrade to a newer version of the Extension Library, and try that?
http://extlib.openntf.org/?r=project/XPages%20Extension%20Library/releases/56832E9BD6A0615186257B4300349C59
The v853.20130315-0724 release was the final one released for 8.5.3, so I would try that.

JQuery Script works with new document, but not with saved ones

Here is what I have :
Lotus database (8.5.3) with jQuery and jQueryUI included
form1 is a form with just one field.
It is set to
"On open - Automatically enable Edit mode"
"On Open - Display XPage instead : xpage1"
"On Web Access - Display XPage instead : xpage1"
xpage1 is an xpage. It contains :
An inputBox linked to the field in form1
A button that calls a small script, just alert("some text")
A jQuery script is included on the page. It's a draggable Panel. It's all there is to it. Just a panel that you can drag on the page.
view1 is a view displaying documents based on form1
Now my problem :
If launch the Xpage in my browser (Chrome or IE), it behaves normaly : I can see my alert when I click on the button, I can drag my panel on the page, I can fill my field, I can save the document.
When I open it later, however, the Xpage opens and display the field data, but my scripts don't work : impossible to save the document, move the panel, display the alert.
If I launch the Xpage in my Lotus client, it works !
If I remove my jQuery reference and my movable panel, the other scripts work.
Did I forget something ? Is it some kind of known problem?
Here is my Xpage source, for reference :
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<!-- THIS WHERE I MAKE JQUERY AVAILABLE -->
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.10.3.custom.js"></script>
<!-- THIS IS MY DATA BINDING -->
<xp:this.data>
<xp:dominoDocument var="ds1" formName="form1"></xp:dominoDocument>
</xp:this.data>
<!-- THIS IS MY FIELD -->
<xp:br></xp:br>
Field1 : <xp:inputText id="field1" value="#{ds1.field1}"></xp:inputText>
<xp:br></xp:br><xp:br></xp:br>
<!-- THIS IS MY PROMPT BUTTON -->
<xp:button value="Alert" id="button2">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[alert("Waring!")]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br><xp:br></xp:br>
<!-- THIS IS MY MOVABLE PANEL -->
<xp:panel id="myPan01"
style="height:120px;width:120px;background-color:rgb(0,64,128)">
<xp:this.attrs>
<xp:attr name="class" value="dragItem"></xp:attr>
</xp:this.attrs>
<xp:div style="text-align:center">
<xp:span style="font-weight:bold;color:rgb(255,255,255)">
</xp:span>
</xp:div>
<xp:div style="text-align:center">
<xp:span style="font-weight:bold;color:rgb(255,255,255)">
Move Me!
</xp:span>
</xp:div>
</xp:panel>
<script>
XSP.addOnLoad(function(){ $(".dragItem").draggable({ grid: [
40,40 ]}); })
</script>
<xp:br></xp:br>
<!-- THIS IS MY SAVE BUTTON -->
<xp:button value="Save" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true">
</xp:eventHandler>
<!-- THIS IS THE END... -->
</xp:button>
</xp:view>
You're including jquery via a standard HTML <script> tag, this may lead to problems since this will be placed in the HTML body instead of the header.
Use the XPage's resource's property. Add some client side JavaScript library with in the XPage ressources properties, then go to the source of the XPage, locate the xp tag that includes the JavaScript library and change it's URL so that your jquery resource is included.
I'm not 100% sure that this solves your problem, but since your code looks good otherwise it's worth a try.

How to style <xe:tabBar> and <xe:tabBarButton> as a footer navigation bar in mobile?

How can I style the xe:tabBar and xe:tabBarButton control so it looks as a "native" footer with buttons (including icons, text)?
To have your tabbar stay at the bottom of the page, use a Dojo ScrollablePane (dojox.mobile.ScrollablePane). If you're using Domino 9, this widget is already available and can be implemented like:
<xe:appPage
id="appPage1"
pageName="firstpage">
<xe:djxmHeading
id="heading1"
label="Scrollable Pane Demo">
</xe:djxmHeading>
<xp:div
id="scrollableContent"
dojoType="dojox.mobile.ScrollablePane">
<xp:this.dojoAttributes>
<xp:dojoAttribute name="fixedFooter">
<xp:this.value><![CDATA[#{javascript:var mobFooter = getComponent("tabBar1");
return mobFooter.getClientId(facesContext);}]]></xp:this.value>
</xp:dojoAttribute>
<xp:dojoAttribute name="fixedHeader">
<xp:this.value><![CDATA[#{javascript:var mobHeader = getComponent("heading1");
return mobHeader.getClientId(facesContext);}]]></xp:this.value>
</xp:dojoAttribute>
<xp:dojoAttribute
name="scrollDir"
value="v">
</xp:dojoAttribute>
<xp:dojoAttribute
name="fixedHeaderHeight"
value="54">
</xp:dojoAttribute>
<xp:dojoAttribute
name="fixedFooterHeight"
value="54">
</xp:dojoAttribute>
</xp:this.dojoAttributes>
YOUR CONTENT GOES HERE
</xp:div>
<xe:tabBar
id="tabBar1"
barType="segmentedControl">
</xe:tabBar>
</xe:appPage>
The Header and footer must stay outside the ScrollablePane and the following dojo attributes are required for functionality:
fixedHeader
fixedFooter
scrollDir
fixedHeaderHeight
fixedFooterHeight
If you're using Domino 8.5.3 then you will have to add the ScrollablePane and all of it's dependencies to your NSF which I cover in a blog post here. You can find additional documentation here.
You will need to implement a version of the dojo scrollableView or scrollablePane in order to get the navigation bar to reliably position itself at the bottom of the mobile device. Watch out for a video from Keith Strickland on NotesIn9 that explains how to do this if you have any troubles.
Using Domino 9.0 we at Red Pill Development have found that styling the NavBar with CSS alone does not guarantee the navigation bar will always drop to the bottom of the screen on each application page transition and/or screen orientation and/or partial refresh.
This is currently not possible with the current set of XPages mobile controls. We have logged PHAN962BJ8 to address this in the future.

How to get Image uploading for Rich Text control within a repeat control to work

Using 8.5.3 UP1 with the Hotfix for the multi-rich text control issue.
I am dynamically binding rich text controls that are within a custom control wrapped in a repeat control. The rich text controls render just fine, except that the image upload functionality does not work. If I click on the image upload, choose a file, and then click send to server, the image apparently never makes it there.
Here is my code:
The Repeat Control:
<xp:repeat id="rptSections" rows="99" repeatControls="false"
var="sections" indexVar="rptIndex" value="#{javascript:2}">
<xc:ccDynamicSections_2 rptIndex="#{javascript:rptIndex}">
<xc:this.fieldName><![CDATA[#{javascript:"contentRT"+rptIndex}]]></xc:this.fieldName>
</xc:ccDynamicSections_2>
</xp:repeat>
The custom control:
<xp:inputRichText id="inputRichText1" value="#{document1[compositeData.fieldName]}" >
</xp:inputRichText>
I'm pretty sure if I can find a way to bind the rich text controls at run time I can make this work. I tried to do this and it appears to work on the page but when I go to save the document I get a error such like "Could not save the document NEW_79 NotesException: Object has been removed or recycled"
Bind after page load attempt:
<xp:repeat id="rptSections" rows="99" repeatControls="false"
var="sections" indexVar="rptIndex" value="#{javascript:2}">
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:var application = facesContext.getApplication();var scopedField = 'content'+rptIndex;var valueBinding = application.createValueBinding( '#{document1.' + scopedField + '}');getComponent("inputRichText1").setValueBinding('value', valueBinding );"test"+rptIndex}]]></xp:this.value>
</xp:text>
<xp:inputRichText id="inputRichText1"></xp:inputRichText>
</xp:repeat>
Any help is appreciated.
I think you should set repeatControls to true. Or else it will fail to correctly bind to your datasource. See this page too.

Resources