Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Struts2 jQuery插件为第二个下拉列表选择初始值_Javascript_Jquery_Struts2 Jquery Plugin - Fatal编程技术网

Javascript Struts2 jQuery插件为第二个下拉列表选择初始值

Javascript Struts2 jQuery插件为第二个下拉列表选择初始值,javascript,jquery,struts2-jquery-plugin,Javascript,Jquery,Struts2 Jquery Plugin,我在尝试使用Struts2 jQuery插件中的Doubleselect元素时遇到了一个小问题(我希望如此)。我没有遇到任何问题,在添加新记录(将新记录添加到数据库)时,行为与预期一样,但当我尝试编辑现有记录时,第二次选择不会加载正在编辑的记录的存储值 有什么帮助吗 代码和配置如下: JSP代码 <s:form id="ingresoForm" action="saveIngreso" method="post" validate="true" cssClass="well form-ho

我在尝试使用Struts2 jQuery插件中的Doubleselect元素时遇到了一个小问题(我希望如此)。我没有遇到任何问题,在添加新记录(将新记录添加到数据库)时,行为与预期一样,但当我尝试编辑现有记录时,第二次选择不会加载正在编辑的记录的存储值

有什么帮助吗

代码和配置如下:

JSP代码

<s:form id="ingresoForm" action="saveIngreso" method="post" validate="true" cssClass="well form-horizontal">
    <s:hidden key="ingreso.id"/>
    <s:hidden key="cliente" id="cliente"/>

    <div class="type-text">
            <label for="cliente">Cliente: </label>
            <s:url var="remoteurl" action="ajax/clienteProyectoSelectSource"/>
            <sj:select
                href="%{remoteurl}"
                id="clienteSelect"
                onChangeTopics="reloadsecondlist"
                name="ingreso.cliente.id"
                list="clientes"
                listKey="id"
                listValue="nombre"
                emptyOption="false"
                headerKey="-10"
                headerValue="Por favor seleccione un cliente"/>
        </div>
        <div class="type-text">
            <label for="Proyecto">Proyecto: </label>
            <sj:select
                href="%{remoteurl}"
                id="proyectoSelect"
                formIds="ingresoForm"
                reloadTopics="reloadsecondlist"
                name="ingreso.proyecto.id" 
                list="proyectos"
                listKey="id"
                listValue="nombre"
                emptyOption="false"
            />
        </div>
public class ClienteProyectoSelectSourceAjaxAction extends BaseAction {

private List<Cliente> clientes;
private List<Proyecto> proyectos;
private String cliente;
private GenericManager<Cliente, Long> clienteManager;


@Override
public String execute() {

    clientes = clienteManager.getAll();

    if (cliente != null && cliente.length() > 0 && !cliente.equals("-10")) {
        proyectos = clienteManager.get(new Long(cliente)).getProyectos();
    }
    return Action.SUCCESS;
}
}


Thx提前解决问题。看来jquery插件工作得很好,像往常一样,错误出现在键盘和椅子之间

我忘记为第二次选择加载数据列表,因此jquery无法选择相应的值

因此,解决方案是确保在用户编辑元素时加载第二个列表(proyectos)

我在JSP上添加了一个标志(cliente)作为隐藏元素,并从主操作中预加载它,因此如果有必要填充第二个列表,我可以从Ajax操作中进行检查

入口操作(视图的主操作)

公共类IngreeAction扩展了BaseAction实现了Preparable{
私人客户;
公共字符串编辑(){
如果(id!=null){
ingreso=ingresoManager.get(id);
cliente=Long.toString(ingreso.getCliente().getId());
}否则{
Ingreo=新的Ingreo();
}
回归成功;
}
公共字符串getCliente(){
回头客;
}
public void setCliente(字符串cliente){
this.cliente=客户;
}
<package name="example" extends="json-default"  namespace="/ajax">
    <action name="clienteProyectoSelectSource" class="com.queres.smtm.webapp.action.ajax.ClienteProyectoSelectSourceAjaxAction">
        <result type="json"/>
    </action>
</package>
@Entity
@Table(name = "ingreso")
public class Ingreso extends BaseObject {

// Campos comunes
private Long id;
private TipoIngreso tipo;
private String observaciones;
private BigDecimal importe;
private BigDecimal tipoIVA;
private Date fechaPrevistaCobro;
private Date fechaEfectivaCobro;

// Campos para facturas
private String numeroFactura;
private Cliente cliente;
private Proyecto proyecto;
private TipoServicio servicio;
private Date fechaEmision;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}


@Enumerated(EnumType.STRING)
public TipoIngreso getTipo() {
    return tipo;
}

public void setTipo(TipoIngreso tipo) {
    this.tipo = tipo;
}

public String getObservaciones() {
    return observaciones;
}

public void setObservaciones(String observaciones) {
    this.observaciones = observaciones;
}

public BigDecimal getImporte() {
    return importe;
}

public void setImporte(BigDecimal importe) {
    this.importe = importe;
}

public BigDecimal getTipoIVA() {
    return tipoIVA;
}

public void setTipoIVA(BigDecimal tipoIVA) {
    this.tipoIVA = tipoIVA;
}

@Temporal(javax.persistence.TemporalType.DATE)
@Field
public Date getFechaPrevistaCobro() {
    return fechaPrevistaCobro;
}

public void setFechaPrevistaCobro(Date fechaPrevistaCobro) {
    this.fechaPrevistaCobro = fechaPrevistaCobro;
}

@Temporal(javax.persistence.TemporalType.DATE)
@Field
public Date getFechaEfectivaCobro() {
    return fechaEfectivaCobro;
}

public void setFechaEfectivaCobro(Date fechaEfectivaCobro) {
    this.fechaEfectivaCobro = fechaEfectivaCobro;
}

public String getNumeroFactura() {
    return numeroFactura;
}

public void setNumeroFactura(String numeroFactura) {
    this.numeroFactura = numeroFactura;
}

@ManyToOne
public Cliente getCliente() {
    return cliente;
}

public void setCliente(Cliente cliente) {
    this.cliente = cliente;
}

@ManyToOne
public Proyecto getProyecto() {
    return proyecto;
}

public void setProyecto(Proyecto proyecto) {
    this.proyecto = proyecto;
}

@Enumerated(EnumType.STRING)
public TipoServicio getServicio() {
    return servicio;
}

public void setServicio(TipoServicio servicio) {
    this.servicio = servicio;
}

@Temporal(javax.persistence.TemporalType.DATE)
@Field
public Date getFechaEmision() {
    return fechaEmision;
}

public void setFechaEmision(Date fechaEmision) {
    this.fechaEmision = fechaEmision;
}

@Override
public int hashCode() {
    int hash = 3;
    hash = 43 * hash + (this.numeroFactura != null ? this.numeroFactura.hashCode() : 0);
    hash = 43 * hash + (this.fechaEmision != null ? this.fechaEmision.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final Ingreso other = (Ingreso) obj;
    if ((this.numeroFactura == null) ? (other.numeroFactura != null) : !this.numeroFactura.equals(other.numeroFactura)) {
        return false;
    }
    if (this.fechaEmision != other.fechaEmision && (this.fechaEmision == null || !this.fechaEmision.equals(other.fechaEmision))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "Ingreso{" + "id=" + id + ", tipo=" + tipo + ", observaciones=" + observaciones + ", importe=" + importe + ", tipoIVA=" + tipoIVA + ", fechaPrevistaCobro=" + fechaPrevistaCobro + ", fechaEfectivaCobro=" + fechaEfectivaCobro + ", numeroFactura=" + numeroFactura + ", cliente=" + cliente + ", proyecto=" + proyecto + ", servicio=" + servicio + ", fechaEmision=" + fechaEmision + '}';
}
public class IngresoAction extends BaseAction implements Preparable {

private String cliente;

public String edit() {
    if (id != null) {
        ingreso = ingresoManager.get(id);
        cliente = Long.toString(ingreso.getCliente().getId());

    } else {
        ingreso = new Ingreso();
    }

    return SUCCESS;
}

public String getCliente() {
    return cliente;
}

public void setCliente(String cliente) {
    this.cliente = cliente;
}

<...>