2016-11-14 7 views
0

У меня есть проблемы с доступом к Model свойства (ProcessSolution) в моем JSP, я не получаю то, что случилось с моими следующими кодами:Struts 2: Не удается получить доступ к свойствам Модель в JSP

Это моя модель класса ProcessSolution. Java

package POJO; 

import java.util.Arrays; 

public class ProcessSolution { 
    private long processId; 
    private String processName; 
    private String processSolutionSteps []; 
    private String processRemark; 
    private String processNote; 

    public ProcessSolution() { 
     // TODO Auto-generated constructor stub 
    } 

    public ProcessSolution(long processId, String processName, 
      String[] processSolutionSteps, String processRemark, String processNote) { 
     this.processId = processId; 
     this.processName = processName; 
     this.processSolutionSteps = processSolutionSteps; 
     this.processRemark = processRemark; 
     this.processNote = processNote; 
    } 
    public long getProcessId() { 
     return processId; 
    } 
    public void setProcessId(long processId) { 
     this.processId = processId; 
    } 
    public String getProcessName() { 
     return processName; 
    } 
    public void setProcessName(String processName) { 
     this.processName = processName; 
    } 
    public String[] getProcessSolution() { 
     return processSolutionSteps; 
    } 
    public void setProcessSolution(String[] processSolutionSteps) { 
     this.processSolutionSteps = processSolutionSteps; 
    } 
    public String getProcessRemark() { 
     return processRemark; 
    } 
    public void setProcessRemark(String processRemark) { 
     this.processRemark = processRemark; 
    } 
    public String getProcessNote() { 
     return processNote; 
    } 
    public void setProcessNote(String processNote) { 
     this.processNote = processNote; 
    } 

    @Override 
    public String toString() { 
     return "ProcessSolution [processId=" + processId + ", processName=" 
       + processName + ", processSolutionSteps=" 
       + Arrays.toString(processSolutionSteps) + ", processRemark=" 
       + processRemark+ ", processNote=" + processNote + "]"; 
    } 
} 

Это мое действие Класс ProcessSolutionAction

public class ProcessSolutionAction extends ActionSupport implements Preparable, ModelDriven<ProcessSolution>, 
            SessionAware, ServletRequestAware, ServletContextAware{ 

    private static final long serialVersionUID = 1L; 

    private ProcessSolution processSolution; 
    private ProcessService processService; 
    private short opType; 
    private String nsec; 
    private UserClass user; 
    private Jmain jmain; 
    private ProcessSolution processSolutions[]; 

    private HttpServletRequest request; 
    private Map<String, Object> sesstion; 
    private ServletContext servletContext; 

    /* (non-Javadoc) 
    * @see com.opensymphony.xwork2.Preparable#prepare() 
    */ 
    @Override 
    public void prepare() throws Exception { 
     this.processSolution = new ProcessSolution(); 
     this.jmain = new Jmain(); 
    } 
    /*public void prepareAddProcessSolution() throws Exception { 
     this.processService = new ProcessService(); 
    } 
    public void prepareListProcessSolutions() throws Exception { 
     System.out.println("prepareListProcessSolution()"); 
     this.jmain = new Jmain(); 
    } 
    public void prepareEditProcessSolution() throws Exception { 
     System.out.println("prepareEditProcessSolution()"); 
     this.jmain = new Jmain(); 
    }*/ 

    @Override 
    public ProcessSolution getModel() { 
     return this.processSolution; 
    } 

    /* (non-Javadoc) 
    * @see com.opensymphony.xwork2.ActionSupport#execute() 
    */ 
    @Override 
    public String execute() throws Exception { 
     System.out.println("ProcessSolution#execute()"); 

     /*System.out.println("Process ID :- "+this.request.getParameter("processId")); 
     System.out.println("this.processSolution Before :- "+this.processSolution); 
     if(Long.parseLong(this.request.getParameter("processId")) != 0) 
      this.processSolution = this.jmain.getProcessSolution(Long.parseLong(this.request.getParameter("processId"))); 
     System.out.println("this.processSolution After :- "+this.processSolution);*/ 
     return SUCCESS; 
    } 

    public String editProcessSolution() throws Exception { 
     System.out.println("ProcessSolution#editProcessSolution()"); 

     System.out.println("Process ID :- "+this.request.getParameter("processId")); 
     System.out.println("this.processSolution Before :- "+this.processSolution); 
     if(Long.parseLong(this.request.getParameter("processId")) != 0) 
      setProcessSolution((ProcessSolution) this.jmain.getProcessSolution(Long.parseLong(this.request.getParameter("processId")))); 
     System.out.println("this.processSolution After :- "+this.processSolution); 
     return SUCCESS; 
    } 

    public ProcessSolution getProcessSolution() { 
     return processSolution; 
    } 
    public void setProcessSolution(ProcessSolution processSolution) { 
     this.processSolution = processSolution; 
    } 
    public short getOpType() { 
     return opType; 
    } 
    public void setOpType(short opType) { 
     this.opType = opType; 
    } 
    public String getNsec() { 
     return nsec; 
    } 
    public void setNsec(String nsec) { 
     this.nsec = nsec; 
    } 
    public UserClass getUser() { 
     return user; 
    } 
    public void setUser(UserClass user) { 
     this.user = user; 
    } 
    public ProcessSolution[] getProcessSolutions() { 
     return processSolutions; 
    } 
    public void setProcessSolutions(ProcessSolution[] processSolutions) { 
     this.processSolutions = processSolutions; 
    } 

    @Override 
    public void setServletRequest(HttpServletRequest request) { 
     this.request = request; 
    } 

    @Override 
    public void setSession(Map<String, Object> sesstion) { 
     this.sesstion = sesstion; 
    } 
    @Override 
    public void setServletContext(ServletContext servletContext) { 
     this.servletContext = servletContext; 
    } 
} 

В editProcessSolution класса действия (в) я могу получить мою модель, и получения отпечатан правильно после вызова метода но не в состоянии получить доступ к свойствам моего класса модели в JSP

Вот как я доступ к свойствам в JSP

<s:property value="%{[0].processName}" /> 
    <s:property value="%{[1].processName}" /> 
    <s:property value="processId" /> 
    <s:property value="nsec" /> 
    <s:property value="#processSolution.processName" /> 
    <s:property value="%{processSolution.processName}" /> 
    <s:property value="processSolution.processName" /> 
    <s:property value="%{processName}" /> 
    <s:property value="processRemark" /> 
    <s:property value="processNote" /> 
    <s:property value="processSolution.getProcessName()" /> 
    <s:property value="processSolution.getProcessId()" /> 
    <s:if test="%{processName == null}"> 
     NULL 
    </s:if> 
    <s:else> 
     NOT NULL 
    </s:else> 

Что не так с моим кодом?

, чем вы

Обновленный код

Если я получить доступ к моей модели с помощью поглотитель я могу получить доступ к свойствам модели

 <s:property value="getProcessSolution().getProcessName()" /> 

но непосредственно я не могу получить доступ Моя модель

это мой xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
    <constant name="struts.multipart.maxSixe" value="1000000"/> 

    <package name="shantaram" extends="struts-default"> 
     <!-- Process Solution Actions --> 
     <action name="load-process-solution" class="actions.ProcessSolutionAction"> 
      <result name="success">process_solution_entry.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
     <action name="list-process-solution" class="actions.ProcessSolutionAction" method="listProcessSolutions"> 
      <result name="success">process_solution_list.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
     <action name="add-process-solution" class="actions.ProcessSolutionAction" method="addProcessSolution"> 
      <result name="success">process_solution_entry.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
     <action name="edit-process-solution" class="actions.ProcessSolutionAction" method="editProcessSolution"> 
      <result name="success">process_solution_entry.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
     <action name="update-process-solution" class="actions.ProcessSolutionAction" method="addProcessSolution"> 
      <result name="success">process_solution_entry.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
     <action name="delete-process-solution" class="actions.ProcessSolutionAction" method="deleteProcessSolution"> 
      <result name="success">process_solution_list.jsp</result> 
      <result name="error">Error.jsp</result> 
      <result name="login">Login.jsp</result> 
     </action> 
    </package> 
</struts> 
+0

Можете ли вы разместить свои struts.xml. Мне нужно проверить действие и перехватчик –

+0

удалить 'ModelDriven' из реализованных интерфейсов –

+0

извините, это была моя ошибка, в Model у меня есть более ** getter **' getProcessSolution() ', который должен был быть' getProcessSolutionSteps() ', который я забыл переименовать ... –

ответ

0

Вы должны изменить свой результат тип своего действия, чтобы dispatch в вашем ProcessSolutionAction в struts.xml.

Пример:

<result name="success" type="dispatcher">sample.jsp</result> 

или удалить type на свой результат, поскольку значение по умолчанию типа dispatcher

<result name="success">sample.jsp</result> 

Может быть, ваш тип результата является перенаправление, поэтому вы не можете взять значение для вашего класса действий для вашего jsp.

+0

Вы уверены, что ваш синтаксис? –

+0

этот синтаксис дает мне ошибку .... –

+0

Потому что это неправильно;) –

 Смежные вопросы

  • Нет связанных вопросов^_^