h:commandLink JSF file download - file

I am trying to create a download link in a JSF page. The page has many richfaces fields that have validation enabled. Some have validator methods attached to them, some just have the required attribute set to true. The download link is an h:commandlink element. This link is supposed to download a file from the server. When I click on the link, validation on a few fields is triggered. How can I avoid this?
Thanks.

Either put it in a separate form,
<h:form>
... other input fields ...
</h:form>
<h:form>
<h:commandLink value="Download" action="#{bean.download}" />
</h:form>
or use immediate="true" so that all input fields which do not have this attribute set will be skipped in the process
<h:commandLink value="Download" action="#{bean.download}" immediate="true" />

The issue was with the file on the server side. Issue resolved.

Related

Redirect from any component to another page in adf

Hello im new on af and I´m trying to redirect by clicking on any adf component to another page. But i dont want to use javascript only with adf and beans.
I have been looking for something similar to the onclick of javascript that you can use it on any html element and with a click you can invoke a function.
On my test i had tried to redirect to another page by clicking on a af:inputText like when i click on an af:link and execute the action with the name of the control flow case for navigate from one activity to another, looking on the documentation, the af:inputText doesn´t have any onclick/action event or something similar.
primera.jsff
<?xml version='1.0' encoding='UTF-8'?>
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<!--af:link When i click on it i get redirected to another jsff page on my project -->
<af:link text="link 1" id="link1" action="gonext"></af:link>
<!--I want a similar behavior here -->
<af:inputText label="Label 1" id="it1"/>
</ui:composition>
My task-flow has defined a control flow case from primera.jsff to a empty segunda.jsff named gonext
I just want the similar behavior on the af:inputText than on the af:link, but only using adf not javascript code. Thanks and sorry for the redaction.

Is there any way I can direct focus to a specific input field on a form?

I have a large form and I would like when the user clicks a "new" button for the focus to be placed in a specific input field. There's a grid on the form and every field has a known id. Note it might not be the first field so not easy to use the tab.
Would appreciate some advice if this is possible. Would save having to manually have the user move the cursor over and click in the input field.
Update: Changed "move cursor" to "change focus"
Here is one solution -
Angular js gives you an advantage of using some of the extra features so that you dont have to use the jquery.
Here is one way to implement the autofocus feature.
<div class="button" input-focus>{{element.idORname}}</div>
and the directive to be defined here.
.directive("inputfocus",function($timeout){
return {
link : function(element,attributes){
element.bind('click',function($timeout){
$timeout(function(){
element/*.parent() or.child()*/.find('type of the field you want to select')[0].focus();
);
);
);
Here you can use the javascript or jquery methods for the dom traversal if there are nested fields in your code.
$timeout is necessary to call for the focus after the browser renders when user has finished clicking the event
As you can see the find('')[0] is a replacement for find('').focus as the latter requires jquery to be used.
Place "autofocus" attribute on the element that you want to focus.
Example:
Name: <input type="text" name="name" autofocus />
If all the input ids are known, just use that.
$("#NewButton").on('click', function(){
//Other code.
$("#IdOfInputToBeFocused").focus();
});
Custom data attribute can be used with jQuery like this
<input data-field="special" />
And then that specific field can be called like this
jQuery('input').find("[data-field='special']").focus();

jsf upload file upload immediately

I have a little problem and I wonder is it possible to resolve it in JSF 2.2.3
I use relatively new inputFile tag and it works ok:
<h:form enctype="multipart/form-data">
<h:inputFile id="auctionImage" value="#{auctionBean.image}"/>
<h:commandButton value="Add">
<f:ajax execute="auctionImage" render="images"/>
</h:commandButton>
<h:panelGroup id="images">
<ui:repeat value="#{auctionBean.productImages}" var="oneImage">
<h:graphicImage value="/image/#{oneImage.url}" width="200" height="171" />
</ui:repeat>
</h:panelGroup>
</h:form>
I want to show every submitted img on the website and have one main sumbit button to submit them all at once. It works ok.
The problem is I have three buttons to browse for image, to submit image and to submit all images. Is it possible to submit it after clicking OK in explorator window?
Ok after day of trying with javascript i realized that it's very simple to achieve by just an ajax tag.
<h:form class="imageForm" enctype="multipart/form-data">
<div class="browseButton"><span class="browseString">BROWSE...</span>
<h:inputFile id="auctionImage" value="#{auctionBean.image}">
<f:ajax execute="auctionImage" render=":mainForm:repeatImages"/>
</h:inputFile>
</div>
</h:form>
Yes, that's it.
PS I used wrapper div and opacity trick for button to change standard html 5 appearance.

Liferay: Showing Related Assets for Calendar Event in the list page

I'm working to customize liferay's Calendar portlet and have created a hook for this.
I want to show all the "Related Assets" associated with a Calendar Event directly in the list page itself where all the Events are displayed instead of the Event's detail view page.
Currently liferay shows the "Related Assets" only when we click on the Event to view the details of that Event.
Can anyone help me?
Environment: Liferay 6.1
Thanks a lot
Sabrina
I assume you already have liferay's source code and you know how to create a hook.
The JSPs you would be modifying would be in this path:
portal-web/docroot/html/portlet/calendar
So here are some steps to help you solve your query:
You need to modify the event_iterator.jspf: row.addText(event.getTitle(), rowURL);
You have to adjust the following code taken from view_event.jsp in event_iterator.jspf.
<%
AssetEntry layoutAssetEntry = AssetEntryLocalServiceUtil.getEntry(CalEvent.class.getName(), event.getEventId());
%>
<%-- <liferay-util:buffer> is a tag which stores all that is written inside
its body in a single variable string, in this case "relatedAssetsLinksBuffer"
--%>
<liferay-util:buffer var="relatedAssetsLinksBuffer">
<c:if test="<%= enableRelatedAssets %>">
<%=event.getTitle() %>
<div class="entry-links">
<liferay-ui:asset-links
assetEntryId="<%= layoutAssetEntry.getEntryId() %>"
/>
</div>
</c:if>
</liferay-util:buffer>
Now the line in step-1 becomes: row.addText(relatedAssetsLinksBuffer, rowURL);
I have not tried this but I think it would work or will atleast give you some help in solving your query.
Tip for Hooks (might be useful in future):
Liferay follows a convention in storing its JSPs, so for custom-jsps Hook (i.e. a hook created for modifying liferay's JSP) you just need to search for that particular JSP & modify it.
For Eg: You wanted to modify the first page of calendar portlet. So liferay portlet's first page is always view.jsp located in the folder with the same name as the portlet-name in this case "Calendar" and view.jsp will contain some tags like <%# include /> or <liferay-util:include /> which would include other files to show the content. So you can always start with a view.jsp and navigate ahead. By the way the names of the JSPs are also most of the time self-explanatory.
Hope this helps.

Add a custom link/button to a visualforce page?

I have a custom link on the opportunity object which points to an external site. Is it possible to add this custom link to a visualforce page?
The solution I came up with was to copy the url salesforce creates for this custom link, and paste it in the page. It looks something like this:
my custom link
This works fine, however, it won't work once it's in a managed package installed on other servers because the lid param will be different (the custom link id). Is there a solution for this?
Have you thought about putting the URL of the link in a field on the opportunity object and then creating an output link on your VF page?
Paul
Look under $Action. Buttons and links are available via that global variable. For example $Action.Opportunity.CustomLink
To build off the answer from danieljimenez, the $Action global variable provides access to the button/link objects. From there you need to use the URLFOR function to get it into a usable form. Then you can either put it into the action param of a command button, or use it as you'd like anywhere else in your markup.
<apex:commandButton action="{!URLFOR($Action.My_Obj__c.My_custom_link)}" value="My custom button"/>
or
My link
create New Contact (Salesforce button target _blank)
<apex:commandLink target="_blank"
styleClass="btn"
style="text-decoration:none;padding:4px;"
action="{!URLFOR($Action.Contact.NewContact)}"
value="Create New Contact" />

Resources