" OnClick = "SubmitForm (Document. fm);">>>>>>>>>>>>>>>>>>
td>
TR>
TABLE>
td>
TR>
form>
TABLE>
Third, related java files
1. Helloutil.java
Package com.kevingq.portlet.hello.util;
Import com.kevingq.portlet.Hello.model.Hello;
Import com.liferay.portal.util.webcacheexception;
Import com.liferay.portal.util.Webcachepool;
Import com.liferay.portal.util.webcacheable;
Import com.liferay.cache.model.cache;
Public class helloutil {
Public Static Hello GetHello (String Name)
Throws Webcachexception {
Webcacheable WC = New Helloconverter (Name);
Cache cache = WebcachePool.g (
Helloutil.class.getname () Name, WC);
Return (hello) cache.getObject ();
}
}
2. HelloConverter.java implements the main class of SOAP calls, bold code is particularly important, and the Axis Server end will throw errors.
Package com.kevingq.portlet.hello.util;
Import org.apache.axis.client.call;
Import org.apache.axis.client.service;
Import javax.xml.rpc.parametermode;
Import org.apache.axis.encoding.xmltype;
Import com.kevingq.portlet.Hello.model.Hello;
Import com.liferay.portal.util.webcacheable;
Import com.liferay.util.convertEREXCEPTION;
Import com.liferay.util.time;
Public class helloconverter imports Webcacheable {
Helloconverter (String name) {
_name = name;
}
Public Object Convert (String Arg0) throws converterexception {
Hello Hello = New Hello ();
Try {
String endpoint = "http:// localhost: 80 / axis / service / helloservice";
Service service = new service ();
Call call = (call) service.createcall ();
Call.SetsoApactionuri ("http: // localhost: 80 / axis / service / helloService # Sayhello");
Call.SettargetendPointdaddress (New Java.net.URL (Endpoint));
Call.SetoperationName ("Sayhello");
Call.addparameter ("param1", xmltype.xsd_string, parametermode.in);
Call.setRType (XMLTYPE.XSD_STRING);
String Ret = (String) Call.invoke (new object [] {_ name});
Hello.setHello (RET);
} catch (exception e) {
Throw new converterexception (_Name " E.toString ());
}
Return hello;
}
Public long getRefreshtime () {
Return_Refreshtime;
}
Private long _refreshtime = time.day;
Private string _name;
}
3. Hello.java
Package com.kevingq.portlet.hello.model;
Import java.io.serializable;
Public class hello imports serializable {
Public hello () {
// EMPTY
}
Public Hello (String Hello) {
_hello = hello;
}
Public string getHello () {
Return_Hello;
}
Public void sethello (string hello) {
_hello = hello;
}
PRIVATE STRING_HELLO;
}
4. EDITPREFERENCESACTION.JAVA Treatment for the PREFERENCES for the portlet
Package com.kevingq.portlet.hello.action;
Import javax.portlet.actionRequest;
Import javax.portlet.ActionResponse;
Import javax.portlet.portletconfig;
Import Javax.Portlet.RenderRequest;
Import javax.portlet.renderResponse;
Import javax.portlet.portletpreference;
Import javax.portlet.validatorException;
Import org.apache.struts.Action.actionform;
Import org.apache.struts.Action.actionForward;
Import org.apache.struts.action.actionmapping;
Import com.liferay.portal.struts.portletAction;
Import com.liferay.portal.util.constants;
Import com.liferay.util.Paramutil;
Import com.liferay.util.stringutil;
Import com.liferay.util.servlet.sessionerro;
Import com.liferay.util.servlet.SessionMESSAGES;
Public class editpreferencesaction extends portletAction {
Public Void Processction
ActionMapping Mapping, Actionform Form, PortletConfig Config,
ActionRequest Req, ActionResponse Res?
Throws exception {
String cmd = paramutil.getstring (Req, constants.cmd);
IF (! cmd.equals (constants.Update) {
Return;
}
PortletPreferences prefs = req.getpreference ();
String [] names = Stringutil.split (
PARAMUTIL.GETSTRING (Req, "Names"), "/ N");
Prefs.SetValues ("Names", Names);
Try {
Prefs.store ();
}
Catch (ValidatorException Ve) {
SessionerRors.Add (Req, ValidatorException.class.getName (), VE);
Return;
}
SessionMessages.Add (Req, Config.getPortletName () ".doEdit");
Public ActionForward Render
ActionMapping Mapping, Actionform Form, PortletConfig Config,
RenderRequest Req, RenderResponse Res?
Throws exception {
Return mapping.findforward (GetForward (Req, "Portlet.hello.edit"));
}
}
The above four classes are compiled, put it until the% Tomcat_Home% / LifeRay / Web-INF / CLASSES / if there is no Classes folder, you can create yourself.
four. Related deployment description file modification
1, modify portlet.xml
Add the following piece
70 portlet-name>
Hello to display-name>
com.liferay.portlet.strutsportlet portlet-class>
edit-action name>
/ hello / edit value>
init-param>
view-action name>
/ hello / view value>
init-param>
300 expedition-cache>
text / html mime-type>
Edit portlet-mode>
supports>
com.liferay.portlet.strutsResourceBundle resource-bundle>
Names name>
Kevin value>
john value>
preference>
portlet-preferences>
Power User role-name>
security-role-ref>
User role-name>
security-role-ref>
portlet>
2, modify struts-config.xml
Add it under the tag
action>
3, modify Liferay-Portal.xml
Add it under tab
4, modify Liferay-Display.xml
Add it under the label
category>
5, modify Tiles-Defs.xml
Add it under the tab
definition>
definition>
6, modify the language.properties file
Due to LifeRay-Tomcat-
3.1.0
The file is packaged in the portal-ejb.jar file, so you need to create a Content folder in% Tomcat_Home% / LifeRay / Web-INF / Create a Properties.languange file in it.
Javax.Portlet.title.70 = HelloTo
category.myportlet = myportlet
To achieve the internationalization of portlet, you need to create a series of Properties files, for example, the Chinese Porperties_ZH_CN.Properties is not written in Chinese with Unicode, will not explain here.
The above is my practice, all the code is verified by experiments, this example is simple and representative, and I have written it yourself.
转载请注明原文地址:https://www.9cbs.com/read-61003.html