public void addBook()

in tapestry-examples/Vlib/src/org/apache/tapestry/vlib/pages/NewBook.java [49:117]


    public void addBook(IRequestCycle cycle)
    {
        Map attributes = getAttributes();

        Integer publisherId = (Integer) attributes.get("publisherId");
        String publisherName = getPublisherName();

        if (publisherId == null && Tapestry.isBlank(publisherName))
        {
            setErrorField("inputPublisherName", getMessage("need-publisher-name"));
            return;
        }

        if (publisherId != null && Tapestry.isNonBlank(publisherName))
        {
            setErrorField("inputPublisherName", getMessage("leave-publisher-name-empty"));
            return;
        }

        if (isInError())
            return;

        Visit visit = (Visit) getVisit();
        Integer userId = visit.getUserId();
        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();

        attributes.put("ownerId", userId);
        attributes.put("holderId", userId);

        int i = 0;
        while (true)
        {
            try
            {

                IOperations operations = vengine.getOperations();

                if (publisherId != null)
                    operations.addBook(attributes);
                else
                {
                    operations.addBook(attributes, publisherName);

                    // Clear the app's cache of info; in this case, known publishers.

                    vengine.clearCache();
                }

                break;
            }
            catch (CreateException ex)
            {
                setError("Error adding book: " + ex.getMessage());
                return;
            }
            catch (RemoteException ex)
            {
                vengine.rmiFailure("Remote exception adding new book.", ex, i++);
            }
        }

        // Success.  First, update the message property of the return page.

        MyLibrary myLibrary = (MyLibrary) cycle.getPage("MyLibrary");

        myLibrary.setMessage(format("added-book", attributes.get("title")));

        myLibrary.activate(cycle);
    }