Struts 2 Option transferiert ein Beispiel

Struts 2 OptionTransferBeispiel auswählen

Laden Sie es herunter -Struts2-OptionTransferSelect-Example.zip

In Struts 2 besteht die Auswahlkomponente für die Optionsübertragung aus zwei „updownselect“ -Auswahlkomponenten, die links und rechts in der Mitte ausgerichtet sind und Schaltflächen zum Verschieben der Auswahloptionen zwischen sich enthalten. Dies kann über das Tag<s:optiontransferselect>erstellt werden.

Die "name" und "list" beziehen sich auf die linke Auswahlkomponente; während sich "doubleName" und "doubleList" auf die richtige Auswahlkomponente beziehen.

Das Ergebnis ist der folgende HTML-Code, zwei "updownselect" -Komponenten, Schaltflächen und JavaScript, um die Auswahloptionen untereinander zu verschieben (Standard-XML-Design).







Beispiel für Struts 2

Ein vollständiges Beispiel für das<s:optiontransferselect>-Tag zeigt die Verwendung von OGNL- und Java-Listen, um die Daten in die Komponenten "Option Transfer Select" zu füllen.

1. Aktionsklasse

Aktionsklasse zum Generieren und Speichern der linken und rechten Auswahloptionen.

OptionTransferSelectAction.java

package com.example.common.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class OptionTransferSelectAction extends ActionSupport{

    private List leftAntivirusList = new ArrayList();
    private List rightAntivirusList = new ArrayList();

    private String leftAntivirus;
    private String rightAntivirus;

    private String leftNumber;
    private String rightNumber;

    public OptionTransferSelectAction(){

        leftAntivirusList.add("Norton 360 Version 4.0");
        leftAntivirusList.add("McAfee Total Protection 2010");
        leftAntivirusList.add("Trend Micro IS Pro 2010");
        leftAntivirusList.add("BitDefender Total Security 2010");

        rightAntivirusList.add("Norton Internet Security 2010");
        rightAntivirusList.add("Kaspersky Internet Security 2010");
        rightAntivirusList.add("McAfee Internet Security 2010");
        rightAntivirusList.add("AVG Internet Security 2010");
        rightAntivirusList.add("Trend Micro Internet Security 2010");
        rightAntivirusList.add("F-Secure Internet Security 2010");

    }

    public String getLeftNumber() {
        return leftNumber;
    }

    public void setLeftNumber(String leftNumber) {
        this.leftNumber = leftNumber;
    }

    public String getRightNumber() {
        return rightNumber;
    }

    public void setRightNumber(String rightNumber) {
        this.rightNumber = rightNumber;
    }

    public List getLeftAntivirusList() {
        return leftAntivirusList;
    }

    public void setLeftAntivirusList(List leftAntivirusList) {
        this.leftAntivirusList = leftAntivirusList;
    }

    public List getRightAntivirusList() {
        return rightAntivirusList;
    }

    public void setRightAntivirusList(List rightAntivirusList) {
        this.rightAntivirusList = rightAntivirusList;
    }

    public String getLeftAntivirus() {
        return leftAntivirus;
    }

    public void setLeftAntivirus(String leftAntivirus) {
        this.leftAntivirus = leftAntivirus;
    }

    public String getRightAntivirus() {
        return rightAntivirus;
    }

    public void setRightAntivirus(String rightAntivirus) {
        this.rightAntivirus = rightAntivirus;
    }

    public String execute() throws Exception{

        return SUCCESS;
    }

    public String display() {
        return NONE;
    }

}

2. Ergebnisseite

Rendern Sie die Optionsübertragungsauswahlkomponente über das Tag "<s:optiontransferselect>" und generieren Sie die linken und rechten Auswahloptionen über die Java- und OGNL-Liste.

optiontransferselect.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>






Struts 2 optiontransferselect example

result.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>



Struts 2 optiontransferselect example

Left AntiVirus :

Right AntiVirus :

Left Numbers :

Right Numbers :

3. struts.xml

Verknüpfe alles ~






 



  
    pages/optiontransferselect.jsp
  

  
    pages/result.jsp