8 Replies Latest reply on Apr 10, 2006 1:06 AM by kittyk

    Refreshing window using seam

    kittyk

      Hi there,
      I'm using Seam for the first time and am wondering if there's a function available to automatically refresh a xhtml coded window when an action is performed.
      For example, in the application I'm developing, you can add a record. But then you have to manually refresh the window to see that it was in fact added. Note there is a table which contains all the records currently in the database, and when a new record is added, it is visible in this table after a refresh is performed.
      Can anyone please help me? If you need more info please ask :)
      Thanks~ Kitty

        • 1. Re: Refreshing window using seam
          gavin.king

          I don't understand.

          The page is re-rendered on the server *every* time an action is invoked....?

          • 2. Re: Refreshing window using seam
            kittyk

            Hi,

            I'm not sure what the problem is, as when the delete action is performed the page automatically refreshes.

            Basically, I have two data table's. For the list table, each column is an outputText value, and basically lists each record in the database. Each row is a record, each column is a field, for example, licence plate number.

            For the "add" table, each column is an inputText value, and the final column is the add button.

            Please see code below for an example...

            Data Table One - List of records
            <h:dataTable var="record" value="#{listOfRecords}" rendered="#{listOfRecords.rowCount>0}">
            <h:column>
            <f:facet name="header">
            <h:outputText value="Record" />
            </f:facet>
            <h:commandLink value="#{record.lpn}" action="#{lpnWatchlistOperations.list}" />
            </h:column>
            <h:column>
            <f:facet name="header">
            <h:outputText value="Lpn" />
            </f:facet>
            <h:outputText value="#{record.lpn}" />
            </h:column>
            </h:dataTable>

            Data Table Two - adding a record
            <h:dataTable value="Add records">
            <h:column>
            <f:facet name="header">
            <h:outputText value="Lpn" />
            </f:facet>
            <h:inputText value="#{lpnwatchlist.lpn}" />
            </h:column>
            <h:column>
            <f:facet name="header">
            <h:outputText value="Add Record?" />
            </f:facet>
            <h:commandButton value="add" action="#{add.add}" />
            </h:column>
            </h:dataTable>

            So when the add button is pressed, it calls the add method which adds the record to the database. I'd then like to see it update my data table containing the list of records. However, this is not the case until i manually hit the refresh button on the page. Is there something I'm missing?

            • 3. Re: Refreshing window using seam
              gavin.king

              What scope is the DataModel?

              • 4. Re: Refreshing window using seam
                kittyk

                It's an EVENT

                • 5. Re: Refreshing window using seam
                  gavin.king

                  If that is really the case, then it will be rebuilt on every request to the server. Are you *sure* about that?

                  • 6. Re: Refreshing window using seam
                    kittyk

                    Hi Gavin,

                    Yeah I'm pretty sure.. Here's what I've got. I have 2 classes. 1 for add, the other for delete. Can you please check it out and let me know if you see anything wrong in relation to how I'm using Seam? Thanks heaps I really appreciate your help!

                    Class One - Delete

                    @Stateful
                    @Scope(EVENT)
                    @Name("lpnWatchlistOperations")
                    @Interceptors(SeamInterceptor.class)
                    public class FunctionsOfLpnWatchlistAction implements FunctionsOfLpnWatchlist {

                    @In
                    private Context sessionContext;

                    @DataModel
                    private List listOfRecords;

                    @DataModelSelection
                    @Out (required = false)
                    private LPNWatchlistItem lpnwatchlist;

                    private LPNWatchList list = PluginFactory.getPlugin(LPNWatchList.class);

                    /*
                    * (non-Javadoc)
                    *
                    * @see com.transtoll.ui.actions.FunctionsOfLpnWatchlist#list()
                    */
                    @Factory ("listOfRecords")
                    public void list() {
                    listOfRecords = new ArrayList();

                    List recordList = list.getAllLpnWatchList();
                    for (LpnWatchListDto dto : recordList) {
                    LPNWatchlistItem item = new LPNWatchlistItem();
                    item.id = dto.id;
                    item.lpn = dto.lpn;
                    item.issuingRegion = dto.issuingRegion;
                    item.type = dto.type;
                    listOfRecords.add(item);
                    }
                    }


                    /* (non-Javadoc)
                    * @see com.transtoll.ui.actions.FunctionsOfLpnWatchlist#delete()
                    */
                    public String delete() {
                    sessionContext.set("currentLpnWatchlistItem", lpnwatchlist);
                    listOfRecords.remove(lpnwatchlist);
                    LpnWatchListDto dto = createDto(lpnwatchlist);
                    list.deleteRecord(dto);
                    return "deleted";
                    }
                    }

                    Class Two - Add

                    @Stateless
                    @Name("add")
                    @Interceptors(SeamInterceptor.class)
                    public class AddAction implements Add {

                    @In (required = false)
                    private LPNWatchlistItem lpnwatchlist;

                    @In
                    private Context sessionContext;

                    @In
                    private FacesContext facesContext; //used for outputting error messages.

                    private LPNWatchList list = PluginFactory.getPlugin(LPNWatchList.class);

                    /* (non-Javadoc)
                    * @see com.transtoll.ui.actions.Add#add()
                    */
                    @IfInvalid(outcome=Outcome.REDISPLAY)
                    public String add() {
                    LpnWatchListDto dto = createDto(new LPNWatchlistItem(lpnwatchlist.getId(), lpnwatchlist.getLpn(), lpnwatchlist.getIssuingRegion(), lpnwatchlist.getType()));
                    list.add(dto);
                    return "added";

                    }

                    /* (non-Javadoc)
                    * @see com.transtoll.ui.actions.Add#update()
                    */
                    @IfInvalid(outcome=Outcome.REDISPLAY)
                    public String update() {
                    sessionContext.set("currentLpnWatchlistItem", lpnwatchlist);
                    LpnWatchListDto dto = createDto(lpnwatchlist);
                    list.update(dto);
                    return "updated";
                    }

                    • 7. Re: Refreshing window using seam
                      gavin.king

                      Yep, that looks OK.

                      Try using the debugger and the Seam debug page to find out what is going on.

                      • 8. Re: Refreshing window using seam
                        kittyk

                        Okay will do, thanks! :)