Development Portlet The second step: How to transform a crystal static portlet into a dynamic portlet based on test data?

Source: Internet
Author: User

When crystal-based static portlet development is complete, the portlet needs to be transformed into a dynamic portlet based on the test data before it is associated with the background service. The steps are as follows:

Step into the Guide
    1. Copy the Portlet project and modify the associated Pom.xml, Src/main/webapp/web-inf/liferay-plugin-package.xml, src/main/webapp/web-inf/ liferay-plugin-package.properties files in the Atifact-id, Module-id and other information, distinguish the original static Portlet project, to prevent the duplication of two items, resulting in the inability to run in an environment;
    2. Modify src/main/webapp/web-inf/portlet.xml, Src/main/webapp/web-inf/liferay-portlet.xml,/ static-development-portlet/src/main/webapp/web-inf/ Liferay-display.xml in the Portlet-name and other information, distinguish the original project portlet-name information, prevent and the original static portlet can not run in an environment;
    3. Modify the ****-portlet.xml file name under Src/main/webapp/web-inf/spring, keep the * * * part and corresponding portlet-name (remove the bar) consistent;
    4. See if the package path defined in the ****-portlet.xml file is required by the project, otherwise modify;
    5. See if the package path under Src/main/java is consistent with the package path defined in the ****-portlet.xml file, otherwise modified;

To create a test data project:

  1. Create a Java MAVEN project ****-service-stub with the following structure:
  2. To modify the Pom.xml file, add the Remote Service API package dependency:
  3. The implementation class of the related service is implemented according to the API, but only the test data of the design can be returned inside the method, as follows:

    @Service Public classApplicationmanager implements Applicationservice {/*(non-javadoc) * @see com.gsoft.portlet.uum.application.applicationservice#list ()*/@Override PublicList<application>list () {list<Application> list =NewArraylist<application>();  for(inti =0; I < -; i++) {Application app=Newapplication (); App.setid (NewLong (i)); App.setname ("Name"+i); App.setcode ("Code"+i); App.seturl ("http://localhsot/"+i); app.setdisabled (i%3==0?true:false);        List.add (APP); }        returnlist; }    /*(non-javadoc) * @see Com.gsoft.portlet.uum.application.applicationservice#getbyid (java.lang.Long)*/@Override PublicApplication getById (Long ID) {Application app=Newapplication (); App.setid (10L); App.setname ("Name Ten"); App.setcode ("Code Ten"); App.seturl ("HTTP://LOCALHSOT/10"); returnapp; }}

To modify a static Portlet project as a dynamic test portlet:

  1. Introduce test data project and remote service interface in Porltet project;
  2. Modify the corresponding Portlet class under Src/main/java, call the remote API and test data service, return the test data;

    @Controller Public classApplicationmanagementportlet extends Abstractcrystalportlet {@ResourcePrivateAuthsystemservice Authsystemservice; @RequestMapping PublicString View (model, renderrequest request) {List<AuthSystemDto> result =authsystemservice.finaallauthsystemlist (); Request.setattribute ("result", result); return "View"; } @RequestMapping (params="Action=add")     Publicstring View4add (model model, @Param string rediract) {Model.addattribute ("rediract", rediract); return "Add"; } @RequestMapping (params="Action=edit")     Publicstring View4edit (model model, @RequestParam string rediract, @RequestParam Long id) {Model.addattribute ("rediract", rediract); Authsystemdto Authsystemdto=Authsystemservice.findone (ID); Model.addattribute ("system", authsystemdto); return "Add"; } @RequestMapping (params="Action=del")     PublicString Delete (model model, renderrequest request, @RequestParam Long ID) {Authsystemservice.deleteauthsystem (        ID); return "pop_up_success"; } @RequestMapping (params="action=editstate")     Publicstring editstate (model, renderrequest request, @RequestParam Long ID, @RequestParam string state) {Auths Ystemdto Authsystemdto=Newauthsystemdto ();        Authsystemdto.setid (ID); if(Stringutils.equals (UserRepConstants.UserRepState.DISABLE, state)) {Authsystemdto.setstate (userrepconstant        s.userrepstate.enable); } Else{authsystemdto.setstate (UserRepConstants.UserRepState.DISABLE);        } authsystemservice.updateauthsystemstate (Authsystemdto); return "pop_up_success"; } @RequestMapping (params="Action=save")     PublicString Save (model, @ModelAttribute ("Authsystem") authsystemdto Authsystem, @RequestParam String rediract) {if(Stringutils.isempty (Authsystem.getstate ())) {Authsystem.setstate ("1"); }        if(Authsystem.getid () = =NULL) {Authsystemservice.saveauthsystem (Authsystem); }Else{Authsystemservice.updateauthsystem (Authsystem); } model.addattribute ("rediract", rediract); return "pop_up_success"; } @RequestMapping (params="Action=check")     PublicModelandview Checkdupcode (model, renderrequest request, @RequestParam Long ID, @RequestParam String code) thro WS jsonprocessingexception {authsystemdto system=Newauthsystemdto ();        System.setcode (code);        System.setid (ID); Boolean exists=Authsystemservice.existsauthsystemcode (System); Map<string, object> result =NewHashmap<string, object>(); Result.put ("Success", boolean.true); Result.put ("Data", exists); returnAjax (Result); }}
  3. Modify the relevant JSP file under SRC/MAIN/WEBAPP/WEB-INF/JSP, add tags, get the data returned by the backend Portlet class, and generate the corresponding code dynamically according to the original static HTML code format.

Publish the dynamic test Portlet and debug accordingly.

Development Portlet The second step: How to transform a crystal static portlet into a dynamic portlet based on test data?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.