Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Trying to create a REALLY simple portlet
I'm trying to create a REALLY simple portlet to duplicate an existing form our security team uses.
I want to input several fields and then email the results to an internal email address which is a mailing list.
I've mocked up the form in the the view.jsp
<aui:form name="myForm" action="" method="post"> <aui:input label="Full Name" name="theName" required="true" value="" placeholder="Enter your first and last names" class="textbox1"/> <aui:input label="User ID (SUI)" name="theSUI" required="true" value="" placeholder="Enter your SUI" class="textbox1"/> <aui:input label="Manager's User ID (SUI)" name="theManager" required="true" value="" placeholder="Enter Manager's SUI" /> <aui:input label="Cost Center" name="theCostCenter" required="true" value="" placeholder="Enter Cost Center" /> <aui:input label="Department Name" name="theDepartment" required="true" value="" placeholder="Enter Department Name" /> <aui:input label="Workstation Number" name="theWorkstation" required="true" value="" placeholder="Enter Workstation Number (W#### or WS#####)" class="textbox1"/> <aui:input label="Web Address" name="theURL" value="" placeholder="Type Website Address Here (eg http://www.google.com)" class="textbox1"> <aui:validator name="required"/> <aui:validator name="url"/> </aui:input> <aui:input label="Business Need" name="theBusinessNeed" required="true" value="" placeholder="Type up to 300 characters describing your business need" class="textbox1" maxlength="300"/> <aui:button type="submit" name="submit" value="submit" /> </aui:form>
But that's where my expertise ends in Liferay. I want to take the values of those fields, create an email and add the values to it with some labels, etc. and send it to the mailing list.
This would be super simple in C#, but sadly my java is lacking and java inside liferay even more so.
Can anyone offer any help or point me to a tutorial, etc. that covers this sort of thing. I haven't found such an example even though this is the most basic type of functionality.
Thank you.
John Cressman:I'm trying to create a REALLY simple portlet to duplicate an existing form our security team uses.
I want to input several fields and then email the results to an internal email address which is a mailing list.
As you're talking about view.jsp, it seems that you started by creating a portlet from a template, e.g. in Liferay Developer Studio. This portlet is backed by a java class. One way to quickly implement some behavior is to override processAction. In there you'll get a request and response object. You'll be able to read the parameters from the request object and then use classic Java to create and send a mail.
If you want to see code: Which version are you looking for? A classic
JSR-286 portlet (e.g. up to Liferay 6.2) or an OSGi component?
Olaf Kock:John Cressman:I'm trying to create a REALLY simple portlet to duplicate an existing form our security team uses.
I want to input several fields and then email the results to an internal email address which is a mailing list.
As you're talking about view.jsp, it seems that you started by creating a portlet from a template, e.g. in Liferay Developer Studio. This portlet is backed by a java class. One way to quickly implement some behavior is to override processAction. In there you'll get a request and response object. You'll be able to read the parameters from the request object and then use classic Java to create and send a mail.
If you want to see code: Which version are you looking for? A classic JSR-286 portlet (e.g. up to Liferay 6.2) or an OSGi component?
So, I'm using DXP - 7.0 still - thus an OSGi would be better.
Currently, I came up with:
String from = "noreply@lvh.com"; String sendTo = "john.cressman@lvhn.org"; InternetAddress myFrom = new InternetAddress(from, from); InternetAddress myTo = new InternetAddress(sendTo, sendTo); String subject = "New URL Request"; String innerName = ParamUtil.getString(request, "theName"); String innerSUI = ParamUtil.getString(request, "theSUI"); String innerMgr = ParamUtil.getString(request, "theManager"); String innerCC = ParamUtil.getString(request, "theCostCenter"); String innerDept = ParamUtil.getString(request, "theDepartment"); String innerWS = ParamUtil.getString(request, "theWorkstation"); String innerURL = ParamUtil.getString(request, "theURL"); String innerNeed = ParamUtil.getString(request, "theBusinessNeed"); String mailBody = "Security Team, \n\nThe following request has been received the following request:\n\n"; mailBody += "Name: " + innerName + "\n"; mailBody += "SUI: " + innerSUI + "\n"; mailBody += "Manager: " + innerMgr + "\n"; mailBody += "Cost Center: " + innerCC + "\n"; mailBody += "Department: " + innerDept + "\n"; mailBody += "Workstation: " + innerWS + "\n"; mailBody += "URL: " + innerURL + "\n"; mailBody += "Business Need:\n " + innerNeed + "\n"; MailMessage mailMessage = new MailMessage(); mailMessage.setFrom(myFrom); mailMessage.setTo(myTo); mailMessage.setSubject(subject); mailMessage.setBody(mailBody); MailServiceUtil.sendEmail(mailMessage);
It ALMOST works... I think... but the compiler gets hung up on:
import javax.mail.internet.InternetAddress;
error: package javax.mail.internet does not exist
Not sure why this is happening.
John Cressman:It ALMOST works... I think... but the compiler gets hung up on:
import javax.mail.internet.InternetAddress;
error: package javax.mail.internet does not exist
You'll need to make javamail available to the compiler. Depending on the build tool you use - e.g. gradle, maven, gradle in Liferay workspace, you'll need to declare the dependency on javamail there. Then your compiler will find it, bnd (the OSGi dependency builder) will also find it and declare your runtime dependency on that library to make it available at runtime.
Sorry, I can't give you the exact lines right now - recently tore my
dev-environment down and have time restrictions for setting it
up
So I DID declare it, and it looks like the compiler TRIES to go out to find it.... but no luck...
My delcaration:
dependencies { compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.46.0" compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.8.0" compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0" compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1" compileOnly group: "javax.mail", name: "javax.mail", version: "1.4" compileOnly group: "jstl", name: "jstl", version: "1.2" compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0" compileOnly project(":modules:lehigh-portal-api") }
But, when I try to compile, I get:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for
configuration
':modules:lehigh-app-approval-portlet:compileClasspath'.
>
Could not resolve javax.mail:javax.mail:1.4.
Required
by:
Coverage:lehigh-app-approval-portlet:1.0.0
> Could not resolve javax.mail:javax.mail:1.4.
>
Could not get resource
'https://jcenter.bintray.com/javax/mail/javax.mail/1.4/javax.mail-1.4.pom'.
> Could not GET
'https://jcenter.bintray.com/javax/mail/javax.mail/1.4/javax.mail-1.4.pom'.
> sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
* Try:
Run with --stacktrace option to get the stack trace. Run
with --info or --debug option to get more log output.
:modules:lehigh-app-approval-portlet:compileJava
I try going out, but I get nothing...
It seems to redirect from jcenter.bintray.com to repo.jfrog.org but the directory path is wrong so it never finds it.
Any ideas?
Can you try replace with this > compileOnly group: 'javax.mail', name: 'mail', version: '1.4.1'compileOnly group: "javax.mail", name: "javax.mail", version: "1.4"
Arun Das<blockquote>
<div class="quote-title"> </div>
<div class="quote">
<div class="quote-content">
<pre
style="color: rgb(169,183,198);font-family: "Courier New";font-size: 9.0pt;background-color: rgb(43,43,43);">
compileOnly <span
style="color: rgb(106,135,89);">group</span>: <span
style="color: rgb(106,135,89);">"javax.mail"</span>, <span
style="color: rgb(106,135,89);">name</span>: <span
style="color: rgb(106,135,89);">"javax.mail"</span>, <span
style="color: rgb(106,135,89);">version</span>: <span style="color: rgb(106,135,89);">"1.4"
</span>
</pre></div></div></blockquote>
Can you try replace with this > compileOnly group: 'javax.mail',
name: 'mail', version: '1.4.1'<br />
<br />
I actually figured that out myself, but that was in fact the answer. Good catch!
Powered by Liferay™