-2

私は石鹸でアクセスできるgrails(TEST)プロジェクトを持っています.本などを追加できます.私が知りたいのは、本を追加するときに発生するすべてのエラーのリストをスローすることです.

以下のコードは現在これが機能しているものですが、すべてのエラーを保存することはできません。私はすでに @webFault で bookExceptions のリストを作成しようとしていますが、これは機能しません。または、@webresult ですべてのエラーを返す必要がありますか。

@XmlRootElement(name="Book")
@XmlAccessorType(XmlAccessType.NONE)
class Book {

  @XmlElement
  String name;

  @XmlElement
  String author;

  @XmlElement
  String publisher;

  @XmlElement
  String isbn;

  @XmlElement
  Date release;

  static constraints = {
    name(nullable: false, blank: true, maxSize: 30);
    author(nullable: false, blank: true, maxSize: 3);
    publisher(nullable: true);
    isbn(nullable: true);
    release(nullable: true);
  }
}

@WebService(serviceName="Service", endpointInterface="webservices.SimpleWebService", targetNamespace="http://pc158:7070/grailsSoap")
class SimpleWebServiceImpl implements SimpleWebService {

  public List<Book> getBooks() {
    return Book.list();
  }

  public void addBook(Book book) throws BookException {
    if (book == null)
      throw new BookException("Book is required.", new BookExceptionBean());

    // TODO : 
    /*
     * if (! book.save(flush: true))
     *   // get errors and throw the bookException that contains all errors.
     */
  }
}

@XmlRootElement(name="BookException")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="BookError")
public class BookExceptionBean extends Error {

  public BookExceptionBean() {
    super();
  }

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="Error", propOrder= {
    "field",
    "value",
    "i18Code",
    "i18Message"
  })
public class Error {

  protected String field;
  protected String value;
  protected String i18Code;
  protected String i18Message;

  public Error() {
  }

  public void setField(String field) {
    this.field = field;
  }

  public String getField() {
    return this.field;
  }

  public void setValue(String value) {
    this.value = value;
  }

  public String getValue() {
    return this.value;
  }

  public void setI18Code(String code) {
    this.i18Code = code;
  }

  public String getI18Code() {
    return this.i18Code;
  }

  public void setI18Message(String message) {
    this.i18Message = message;
  }

  public String getI18Message() {
    return this.i18Message;
  }

}

こんにちはケン、

4

1 に答える 1

0

問題が解決しました:

@XmlRootElement(name="BookException")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="BookError")
public class BookExceptionBean {

  @XmlElementWrapper(name="errors")
  @XmlElement(name="error")
  private List<Error> errors = new ArrayList<Error>();

  public void setError(Error error) {
    this.errors.add(error);
  }

  public List<Error> getErrors() {
    return this.errors;
  }

}
于 2012-12-03T08:18:13.360 に答える