0
我嘗試使用Struts2製作一個基本的應用程序。Struts2:xwork不轉換髮送的參數
我的問題是我的參數沒有被Xworks轉換。我的動作屬性(idParticipant)是一個字符串,但參數是一個數組2。如果我沒有弄錯,XWork應該在動作執行之前轉換基本參數,對吧?
我的jsp:
<s:form action="afficher_participant">
<s:hidden name="idParticipant" value="4"></s:hidden>
<s:submit>bob</s:submit>
</s:form>
我的行動:
package action;
import java.util.List;
import model.Participant;
import service.ParticipantService;
import service.ParticipantServiceImpl;
public class ParticipantAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private String idParticiPant;
private List<Participant> listeParticipant;
private Participant participant;
private ParticipantService participantService = new ParticipantServiceImpl();
public String getIdParticiPant() {
return idParticiPant;
}
public void setIdParticiPant(String idParticiPant) {
this.idParticiPant = idParticiPant;
}
public List<Participant> getListeParticipant() {
return listeParticipant;
}
public void setListeParticipant(List<Participant> listeParticipant) {
this.listeParticipant = listeParticipant;
}
public Participant getParticipant() {
return participant;
}
public void setParticipant(Participant participant) {
this.participant = participant;
}
/* Actions */
public String lister() {
participantService = new ParticipantServiceImpl();
this.listeParticipant = participantService.lister();
return "listerParticipant";
}
public String afficher() {
if (idParticiPant == null) {
return ERROR;
}
participantService = new ParticipantServiceImpl();
participant = participantService.get(Integer.valueOf(idParticiPant));
return "afficherParticipant";
}
}
我的struts.xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="package" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<package name="frontoffice" namespace="/" extends="struts-default">
<default-interceptor-ref name="defaultStack"></default-interceptor-ref>
<!-- Action de l'action de réference -->
<default-action-ref name="index" />
<!-- Navigation rules -->
<action name="*_participant" class="action.ParticipantAction" method="{1}">
<result name="success">jsp/listerParticipant.jsp</result>
<result name="listerParticipant">jsp/listerParticipant.jsp</result>
<result name="afficherParticipant">jsp/afficherParticipant.jsp</result>
<result name="error">/index.jsp</result>
</action>
</package>
</struts>
和finaly,我得到的異常時,我提出:
Unexpected Exception caught setting 'idParticipant' on 'class action.ParticipantAction: Error setting
expression 'idParticipant' with value ['4', ]
我知道這可能只是一個配置問題,但我找不到我的錯誤。
感謝
好吧,我是官方的白癡,或者只是盲目。無論哪種方式,2.解決了我的問題。 非常感謝。 – Cybercachalot
歡迎來到SO ...如果有幫助,請記住接受Jaiwo的回答 –