0

エクスポートできるようにするために、いくつかの「基準」に準拠する必要があるいくつかのアイテムからエクスポート ファイルを生成しようとしています。問題は、ユーザーは (チェックボックスを使用して) いくつかの項目を選択し、ICEFaces のOutputResourceをクリックして、選択した項目を (できればすべて) エクスポートする必要があるということです。

このプロセスに関係する部分は次のとおりです。

XHTML の OutputResource:

<ice:outputResource rendered="#{not myBackingBean.emptySelection}" resource="#{myBackingBean.excelResource}" label="export to Excel" shared="false" target="_self" />

リソースを保持するバッキング Bean:

@ManagedBean(name = "myBackingBean")
@ViewScoped
@WindowDisposed
public class MyBackingBean implements Serializable
{
 ...
 private ExcelResource resource;
 ...
}

そして最後に、実際のリソース:

...
import com.icesoft.faces.context.Resource;
...

public class ExcelResource implements Resource
{
  ...

  @Override
  public InputStream open() throws IOException
  {
    //do some selection here. If there is no valid ticket to export then
    //this method will return null, otherwise it will return an InputStream
    //and everything will work properly

    if (everythingOk)
    {
        return new ByteArrayInputStream(...);
    }

    //hopefully, it won't get to this point
    return null;
  }

ご覧のとおり、インターフェイスを実装し、「その場で」Excel エクスポートを作成するメソッドをcom.icesoft.faces.context.Resourceオーバーライドしています。open()

ここでもう一度言いたいのは、最初に選択したアイテムの一部をフィルタリングし、アイテムが残っていない場合はエラー ページに移動することです。これがh:commandButtonまたは の場合は、アクションice:commandLinkプロパティを使用して実行しますが、これは であるため、ここでは実行できません。これに対する回避策はありますか? ユーザーは何かを選択することができますが (すぐに がレンダリングされます)、エクスポートする前に選択をフィルタリングする必要があるため、これを行うには render プロパティを使用するだけでは不十分であることに注意してください。ice:outputResourceice:outputResource

最後になりましたが、これを行うために Websphere 8 と ICEFaces 3 を使用しています。

前もって感謝します!

4

1 に答える 1

0

今回は実際のアクションを備えたいくつかのボタンを使用してページにリダイレクトしました。

私がしたことは次のとおりです。

  • MyBackingBean選択範囲が空かどうかを判断するメソッドが追加されました。
  • また、選択が有効かどうかを判断するメソッドもあります(つまり、ではなく、無効なアイテムが含まれていません)。
  • <ice:commandLink>選択が無効な場合にレンダリングされます。このcommandLinkには、エラー ページへの実際のリダイレクトがあります。
  • <ice:outputResource>がレンダリングされない場合(つまり<ice:commandLink>、選択が完全に有効な場合) がレンダリングされます。

そして今、コード:

まず、commandLink :

<ice:commandLink rendered="#{not myBackingBean.validSelection}" 
     disabled="#{myBackingBean.emptySelection}" 
     label="download excel report}"
     action="redirect_to_error_page" />

覚えて:

  • MyBackingBean.isEmptySelection()項目が選択されていない場合はtrueを返します。
  • MyBackingBean.isValidSelection()少なくとも 1 つの項目が選択されていて、選択されたすべての項目が有効な項目である場合 (つまり、エクスポートに有効な項目) 、 trueを返します。

さて、outputResource :

<ice:outputResource 
    rendered="#{myBackingBean.validSelection}" 
    resource="#{myBackingBean.excelResource}" 
    label="download excel report}" shared="false" target="_self" />

最後になりましたが、 が有効な<ice:outputResource>選択のみを処理するようになったことに気付いたかもしれません(エラー ページへの実際のリダイレクトは によって行われます)。これは、実際のエクスポートのためにアイテムをリソースに渡す前に、アイテムをフィルタリングする方法が必要であることを意味します。私の場合、バッキング Bean にメソッドを作成することにしました。<ice:commandLink>filter(...)

@ManagedBean(name = "myBackingBean")
@ViewScoped
@WindowDisposed
public class MyBackingBean implements Serializable
{
 ...
 private ExcelResource resource;
 ...

 public List<MyItems> getFilteredList(List<MyItems> allSelectedItems)
 {
  ...
  //do some selection here and return a list containing only valid items
  return validItemsList;
 }

 public ExcelResource getExcelResource()
 {
   return new ExcelResource(getFilteredList(allSelectedItems));
 }

 public boolean isEmptySelection()
 {
   //return true if the selection is EMPTY, false otherwise.
 }

 public boolean isValidSelection()
 {
   //return true if the selection is NOT EMPTY and it has
   //only VALID items in it, false otherwise.
 }
}

このようにExcelResourceして、有効なアイテムのみを含む「オンザフライ」を生成できます。が XHTML でレンダリングされるまで<ice:outputResource>には、有効でエクスポート可能なアイテムのみが含まれます!

誰かがこれが役立つことを願っています:)

于 2013-10-15T06:31:56.447 に答える